-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrbacconstraint.yaml
38 lines (36 loc) · 1.13 KB
/
rbacconstraint.yaml
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
28
29
30
31
32
33
34
35
36
37
38
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: k8swhitelistedimages
spec:
crd:
spec:
names:
kind: k8sWhitelistedImages
validation:
# Schema for the `parameters` field
openAPIV3Schema:
properties:
images:
type: array
items: string
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package k8swhitelistedimages
whitelisted_images = {images |
images = input.parameters.images[_]
}
images_whitelisted(str, patterns) {
image_matches(str, patterns[_])
}
image_matches(str, pattern) {
contains(str, pattern)
}
violation[{"msg": msg}] {
input.review.object
image := input.review.object.spec.containers[_].image
name := input.review.object.metadata.name
not images_whitelisted(image, whitelisted_images)
msg := sprintf("pod %q has invalid image %q. Please, contact your DevOps. Follow the whitelisted images %v", [name, image, whitelisted_images])
}