-
Notifications
You must be signed in to change notification settings - Fork 9
/
policy-strict-template.yaml
48 lines (39 loc) · 1.34 KB
/
policy-strict-template.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
39
40
41
42
43
44
45
46
47
48
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: policystrictonly
spec:
crd:
spec:
names:
kind: PolicyStrictOnly
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package istio.policystrictonly
# VIOLATION spec.peers does not exist
violation[{"msg": msg}] {
p := input.review.object
speckeys := { k | p.spec[k]}
not speckeys["peers"]
msg := sprintf("%v %v.%v spec.peers does not exist",
[p.kind, p.metadata.name, p.metadata.namespace])
}
# VIOLATION spec.peers is []
violation[{"msg": msg}] {
p := input.review.object
k := "peers"
p.spec[k] == []
msg := sprintf("%v %v.%v spec.peers cannot be empty",
[p.kind, p.metadata.name, p.metadata.namespace])
}
# VIOLATION peer authentication is set to permissive
violation[{"msg": msg}] {
p := input.review.object
kp := "peers"
km := "mode"
peermethod := p.spec[kp][_]
peermethod[km] != "STRICT"
msg := sprintf("%v %v.%v spec.peers must include [{mtls: {}, mode: STRICT}]",
[p.kind, p.metadata.name, p.metadata.namespace])
}