This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0915a8
commit 44e7e36
Showing
6 changed files
with
190 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package sarif | ||
|
||
import ( | ||
"github.com/Shopify/kubeaudit/auditors/apparmor" | ||
"github.com/Shopify/kubeaudit/auditors/asat" | ||
"github.com/Shopify/kubeaudit/auditors/capabilities" | ||
"github.com/Shopify/kubeaudit/auditors/deprecatedapis" | ||
"github.com/Shopify/kubeaudit/auditors/hostns" | ||
"github.com/Shopify/kubeaudit/auditors/image" | ||
"github.com/Shopify/kubeaudit/auditors/limits" | ||
"github.com/Shopify/kubeaudit/auditors/mounts" | ||
"github.com/Shopify/kubeaudit/auditors/netpols" | ||
"github.com/Shopify/kubeaudit/auditors/nonroot" | ||
"github.com/Shopify/kubeaudit/auditors/privesc" | ||
"github.com/Shopify/kubeaudit/auditors/privileged" | ||
"github.com/Shopify/kubeaudit/auditors/rootfs" | ||
"github.com/Shopify/kubeaudit/auditors/seccomp" | ||
) | ||
|
||
var allAuditors = map[string]string{ | ||
apparmor.Name: "Finds containers that do not have AppArmor enabled", | ||
asat.Name: "Finds containers where the deprecated SA field is used or with a mounted default SA", | ||
capabilities.Name: "Finds containers that do not drop the recommended capabilities or add new ones", | ||
deprecatedapis.Name: "Finds any resource defined with a deprecated API version.", | ||
hostns.Name: "Finds containers that have HostPID, HostIPC or HostNetwork enabled", | ||
image.Name: "Finds containers which do not use the desired version of an image (via the tag) or use an image without a tag", | ||
limits.Name: "Finds containers which exceed the specified CPU and memory limits or do not specify any", | ||
mounts.Name: "Finds containers that have sensitive host paths mounted", | ||
netpols.Name: "Finds namespaces that do not have a default-deny network policy", | ||
nonroot.Name: "Finds containers allowed to run as root", | ||
privesc.Name: "Finds containers that allow privilege escalation", | ||
privileged.Name: "Finds containers running as privileged", | ||
rootfs.Name: "Finds containers which do not have a read-only filesystem", | ||
seccomp.Name: "Finds containers running without seccomp", | ||
} | ||
|
||
var violationsToRules = map[string]string{ | ||
apparmor.AppArmorAnnotationMissing: apparmor.Name, | ||
apparmor.AppArmorDisabled: apparmor.Name, | ||
apparmor.AppArmorInvalidAnnotation: apparmor.Name, | ||
asat.AutomountServiceAccountTokenDeprecated: asat.Name, | ||
asat.AutomountServiceAccountTokenTrueAndDefaultSA: asat.Name, | ||
capabilities.CapabilityAdded: capabilities.Name, | ||
capabilities.CapabilityOrSecurityContextMissing: capabilities.Name, | ||
capabilities.CapabilityShouldDropAll: capabilities.Name, | ||
deprecatedapis.DeprecatedAPIUsed: deprecatedapis.Name, | ||
hostns.NamespaceHostIPCTrue: hostns.Name, | ||
hostns.NamespaceHostNetworkTrue: hostns.Name, | ||
hostns.NamespaceHostPIDTrue: hostns.Name, | ||
image.ImageCorrect: image.Name, | ||
image.ImageTagIncorrect: image.Name, | ||
image.ImageTagMissing: image.Name, | ||
limits.LimitsCPUExceeded: limits.Name, | ||
limits.LimitsCPUNotSet: limits.Name, | ||
limits.LimitsMemoryExceeded: limits.Name, | ||
limits.LimitsMemoryNotSet: limits.Name, | ||
limits.LimitsNotSet: limits.Name, | ||
mounts.SensitivePathsMounted: mounts.Name, | ||
netpols.MissingDefaultDenyIngressAndEgressNetworkPolicy: netpols.Name, | ||
netpols.MissingDefaultDenyIngressNetworkPolicy: netpols.Name, | ||
netpols.MissingDefaultDenyEgressNetworkPolicy: netpols.Name, | ||
netpols.AllowAllIngressNetworkPolicyExists: netpols.Name, | ||
netpols.AllowAllEgressNetworkPolicyExists: netpols.Name, | ||
nonroot.RunAsUserCSCRoot: nonroot.Name, | ||
nonroot.RunAsUserPSCRoot: nonroot.Name, | ||
nonroot.RunAsNonRootCSCFalse: nonroot.Name, | ||
nonroot.RunAsNonRootPSCNilCSCNil: nonroot.Name, | ||
nonroot.RunAsNonRootPSCFalseCSCNil: nonroot.Name, | ||
privesc.AllowPrivilegeEscalationNil: privesc.Name, | ||
privesc.AllowPrivilegeEscalationTrue: privesc.Name, | ||
privileged.PrivilegedTrue: privileged.Name, | ||
privileged.PrivilegedNil: privileged.Name, | ||
rootfs.ReadOnlyRootFilesystemFalse: rootfs.Name, | ||
rootfs.ReadOnlyRootFilesystemNil: rootfs.Name, | ||
seccomp.SeccompAnnotationMissing: seccomp.Name, | ||
seccomp.SeccompDeprecatedPod: seccomp.Name, | ||
seccomp.SeccompDisabledPod: seccomp.Name, | ||
seccomp.SeccompDeprecatedContainer: seccomp.Name, | ||
seccomp.SeccompDisabledContainer: seccomp.Name, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package sarif | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Shopify/kubeaudit/auditors/all" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAuditorsLength(t *testing.T) { | ||
// if new auditors are created | ||
// make sure they're added with a matching description | ||
assert.Len(t, allAuditors, len(all.AuditorNames)) | ||
} | ||
|
||
func TestViolationToRules(t *testing.T) { | ||
cases := []struct { | ||
auditorName string | ||
expectedCount int | ||
}{ | ||
{ | ||
"apparmor", | ||
3, | ||
}, | ||
{ | ||
"asat", | ||
2, | ||
}, | ||
{ | ||
"capabilities", | ||
3, | ||
}, | ||
{ | ||
"deprecatedapis", | ||
1, | ||
}, | ||
{ | ||
"hostns", | ||
3, | ||
}, | ||
{ | ||
"image", | ||
3, | ||
}, | ||
{ | ||
"limits", | ||
5, | ||
}, | ||
{ | ||
"mounts", | ||
1, | ||
}, | ||
{ | ||
"netpols", | ||
5, | ||
}, | ||
{ | ||
"nonroot", | ||
5, | ||
}, | ||
{ | ||
"privesc", | ||
2, | ||
}, | ||
{ | ||
"privileged", | ||
2, | ||
}, | ||
{ | ||
"rootfs", | ||
2, | ||
}, | ||
{ | ||
"seccomp", | ||
5, | ||
}, | ||
} | ||
|
||
assert.Len(t, cases, len(all.AuditorNames)) | ||
|
||
for _, c := range cases { | ||
var totalCount int | ||
|
||
for _, v := range violationsToRules { | ||
if v == c.auditorName { | ||
totalCount += 1 | ||
} | ||
} | ||
|
||
assert.Equal(t, c.expectedCount, totalCount) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.