cleaned policie tests

This commit is contained in:
Sebastian Wendel 2022-07-13 23:22:28 +02:00
parent d29d46fe8f
commit 29ea8a6f88
No known key found for this signature in database
GPG key ID: 1422B7DF78144640
5 changed files with 12 additions and 40 deletions

View file

@ -1,24 +0,0 @@
package main
import data.kubernetes
name = input.metadata.name
deny[msg] {
kubernetes.is_deployment
not input.spec.template.spec.securityContext.runAsNonRoot
msg = sprintf("Containers must not run as root in Deployment %s", [name])
}
required_deployment_selectors {
input.spec.selector.matchLabels.app
input.spec.selector.matchLabels.release
}
deny[msg] {
kubernetes.is_deployment
not required_deployment_selectors
msg = sprintf("Deployment %s must provide app/release labels for pod selectors", [name])
}

View file

@ -1,9 +0,0 @@
package kubernetes
is_service {
input.kind = "Service"
}
is_deployment {
input.kind = "Deployment"
}

View file

@ -18,9 +18,3 @@ deny[msg] {
not required_deployment_labels
msg = sprintf("%s must include Kubernetes recommended labels: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels", [name])
}
deny[msg] {
input.kind = "Deployment"
not input.spec.selector.matchLabels.app
msg = "Containers must provide app label for pod selectors"
}

View file

@ -3,5 +3,5 @@ package main
deny[msg] {
input.kind = "Deployment"
not input.spec.template.spec.securityContext.runAsNonRoot = true
msg = "Containers must not run as root"
msg = sprintf("%s Containers must not run as root", [name])
}

11
test/selector.rego Normal file
View file

@ -0,0 +1,11 @@
package main
import data.kubernetes
name = input.metadata.name
deny[msg] {
input.kind = "Deployment"
not input.spec.selector.matchLabels.app
msg = sprintf("%s must provide app label for pod selectors: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels", [name])
}