-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpod-enforce-labels.rego
27 lines (25 loc) · 1.08 KB
/
pod-enforce-labels.rego
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package admission
import data.k8s.matches
###############################################################################
#
# Policy : Enforce labels on pod
# e.g. pod should have required labels
#
###############################################################################
deny[{
"id": "pod-enforce-labels", # identifies type of violation
"resource": {
"kind": "pods", # identifies kind of resource
"namespace": namespace, # identifies namespace of resource
"name": name # identifies name of resource
},
"resolution": {"message": msg}, # provides human-readable message to display
}] {
matches[["pods", namespace, name, matched_pod]]
requiredLabels := "test1|test2"
delimiter := "|"
split(requiredLabels, delimiter, labels)
label = labels[_]
not matched_pod.metadata.labels[label]
msg := sprintf("required label %v is missing for pod: %v", [label, matched_pod.metadata.name])
}