Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #86 from Shopify/refactor-labels
Browse files Browse the repository at this point in the history
Make labels conform to standards
  • Loading branch information
Fedor Lisovskiy authored Jan 17, 2018
2 parents 14f5e3a + 2f6b230 commit 6a22472
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/allowPrivilegeEscalation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func checkAllowPrivilegeEscalation(container Container, result *Result) {
if reason := result.Labels["kubeaudit.allow.privilegeEscalation"]; reason == "" {
if reason := result.Labels["audit.kubernetes.io/allow-privilege-escalation"]; reason == "" {
if container.SecurityContext == nil || container.SecurityContext.AllowPrivilegeEscalation == nil {
occ := Occurrence{
id: ErrorAllowPrivilegeEscalationNIL,
Expand Down
2 changes: 1 addition & 1 deletion cmd/automountServiceAccountToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func checkAutomountServiceAccountToken(result *Result) {
return
}

if reason := result.Labels["kubeaudit.allow.automountServiceAccountToken"]; reason != "" {
if reason := result.Labels["audit.kubernetes.io/allow-automount-service-account-token"]; reason != "" {
if result.Token != nil && *result.Token {
occ := Occurrence{
id: ErrorAutomountServiceAccountTokenTrueAllowed,
Expand Down
2 changes: 1 addition & 1 deletion cmd/privileged.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func checkPrivileged(container Container, result *Result) {
message: "Privileged defaults to false, which results in non privileged, which is okay.",
}
result.Occurrences = append(result.Occurrences, occ)
} else if reason := result.Labels["kubeaudit.allow.privileged"]; reason != "" {
} else if reason := result.Labels["audit.kubernetes.io/allow-privileged"]; reason != "" {
if *container.SecurityContext.Privileged == true {
occ := Occurrence{
id: ErrorPrivilegedTrueAllowed,
Expand Down
2 changes: 1 addition & 1 deletion cmd/readOnlyRootFilesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func checkReadOnlyRootFS(container Container, result *Result) {
if reason := result.Labels["kubeaudit.allow.readOnlyRootFilesystemFalse"]; reason != "" {
if reason := result.Labels["audit.kubernetes.io/allow-read-only-root-filesystem-false"]; reason != "" {
if container.SecurityContext == nil || container.SecurityContext.ReadOnlyRootFilesystem == nil || *container.SecurityContext.ReadOnlyRootFilesystem == false {
occ := Occurrence{
id: ErrorReadOnlyRootFilesystemFalseAllowed,
Expand Down
5 changes: 3 additions & 2 deletions cmd/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ func shouldLog(err int) (members []string) {
func (r *Result) allowedCaps() (allowed map[Capability]string) {
allowed = make(map[Capability]string)
for k, v := range r.Labels {
if strings.Contains(k, "kubeaudit.allow.capability.") {
allowed[Capability(strings.ToUpper(strings.TrimPrefix(k, "kubeaudit.allow.capability.")))] = v
if strings.Contains(k, "audit.kubernetes.io/allow-capability-") {
capName := strings.Replace(strings.ToUpper(strings.TrimPrefix(k, "audit.kubernetes.io/allow-capability-")), "-", "_", -1)
allowed[Capability(capName)] = v
}
}
return
Expand Down
2 changes: 1 addition & 1 deletion cmd/runAsNonRoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func checkRunAsNonRoot(container Container, result *Result) {
if reason := result.Labels["kubeaudit.allow.runAsRoot"]; reason != "" {
if reason := result.Labels["audit.kubernetes.io/allow-run-as-root"]; reason != "" {
if container.SecurityContext == nil || container.SecurityContext.RunAsNonRoot == nil || *container.SecurityContext.RunAsNonRoot == false {
occ := Occurrence{
id: ErrorRunAsNonRootFalseAllowed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
metadata:
labels:
apps: fakeAllowPrivilegeEscalation
kubeaudit.allow.privilegeEscalation: "Superuser privileges needed"
audit.kubernetes.io/allow-privilege-escalation: "Superuser privileges needed"
spec:
containers:
- name: fakeContainerAPE
Expand Down
2 changes: 1 addition & 1 deletion fixtures/allow_privilege_escalation_true_allowed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
metadata:
labels:
apps: fakeAllowPrivilegeEscalation
kubeaudit.allow.privilegeEscalation: "Superuser privileges needed"
audit.kubernetes.io/allow-privilege-escalation: "Superuser privileges needed"
spec:
containers:
- name: fakeContainerAPE
Expand Down
2 changes: 1 addition & 1 deletion fixtures/capabilities_misconfigured_allow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
metadata:
labels:
apps: fakeSecurityContext
kubeaudit.allow.capability.sys_time: "Time is of the essence"
audit.kubernetes.io/allow-capability-sys-time: "Time is of the essence"
spec:
containers:
- name: fakeContainerSC
Expand Down
4 changes: 2 additions & 2 deletions fixtures/capabilities_some_allowed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ spec:
metadata:
labels:
apps: fakeSecurityContext
kubeaudit.allow.capability.chown: "True"
kubeaudit.allow.capability.sys_time: "Time is of the essence"
audit.kubernetes.io/allow-capability-chown: "True"
audit.kubernetes.io/allow-capability-sys-time: "Time is of the essence"
spec:
containers:
- name: fakeContainerSC
Expand Down
2 changes: 1 addition & 1 deletion fixtures/privileged_misconfigured_allow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
metadata:
labels:
apps: fakePrivileged
kubeaudit.allow.privileged: "Privileged execution required"
audit.kubernetes.io/allow-privileged: "Privileged execution required"
spec:
containers:
- name: fakeContainerPrivileged
Expand Down
2 changes: 1 addition & 1 deletion fixtures/privileged_true_allowed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
metadata:
labels:
apps: fakePrivileged
kubeaudit.allow.privileged: "Privileged execution required"
audit.kubernetes.io/allow-privileged: "Privileged execution required"
spec:
containers:
- name: fakeContainerPrivileged
Expand Down
2 changes: 1 addition & 1 deletion fixtures/read_only_root_filesystem_false_allowed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
metadata:
labels:
apps: fakeReadOnlyRootFilesystem
kubeaudit.allow.readOnlyRootFilesystemFalse: "Write permissions needed"
audit.kubernetes.io/allow-read-only-root-filesystem-false: "Write permissions needed"
spec:
containers:
- name: fakeContainerRORF
Expand Down
2 changes: 1 addition & 1 deletion fixtures/read_only_root_filesystem_misconfigured_allow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
metadata:
labels:
apps: fakeReadOnlyRootFilesystem
kubeaudit.allow.readOnlyRootFilesystemFalse: "Write permissions needed"
audit.kubernetes.io/allow-read-only-root-filesystem-false: "Write permissions needed"
spec:
containers:
- name: fakeContainerRORF
Expand Down
2 changes: 1 addition & 1 deletion fixtures/run_as_non_root_false_allowed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
metadata:
labels:
apps: fakeSecurityContext
kubeaudit.allow.runAsRoot: "Superuser privileges needed"
audit.kubernetes.io/allow-run-as-root: "Superuser privileges needed"
spec:
containers:
- name: fakeContainerRANR
Expand Down
2 changes: 1 addition & 1 deletion fixtures/run_as_non_root_misconfigured_allow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
creationTimestamp: null
labels:
apps: fakeSecurityContext
kubeaudit.allow.runAsRoot: "Superuser privileges needed"
audit.kubernetes.io/allow-run-as-root: "Superuser privileges needed"
spec:
containers:
- name: fakeContainerRANR
Expand Down
2 changes: 1 addition & 1 deletion fixtures/service_account_token_misconfigured_allow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
metadata:
labels:
apps: fakeAutomountServiceAccountToken
kubeaudit.allow.automountServiceAccountToken: "True"
audit.kubernetes.io/allow-automount-service-account-token: "True"
spec:
automountServiceAccountToken: false
containers:
Expand Down
2 changes: 1 addition & 1 deletion fixtures/service_account_token_true_allowed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
metadata:
labels:
apps: fakeAutomountServiceAccountToken
kubeaudit.allow.automountServiceAccountToken: "True"
audit.kubernetes.io/allow-automount-service-account-token: "True"
spec:
automountServiceAccountToken: true
containers:
Expand Down

0 comments on commit 6a22472

Please sign in to comment.