-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtemplate.yaml
33 lines (32 loc) · 1.06 KB
/
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
# https://raw.githubusercontent.com/Azure/azure-policy/master/built-in-references/Kubernetes/allowed-external-ips/template.yaml
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: externalips
spec:
crd:
spec:
names:
kind: ExternalIPs
validation:
# Schema for the `parameters` field
openAPIV3Schema:
type: object
properties:
allowedIPs:
type: array
items:
type: string
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package externalips
violation[{"msg": msg}] {
input.review.kind.kind == "Service"
input.review.kind.group == ""
allowedExternalIPs := {ip | ip := input.parameters.allowedExternalIPs[_]}
externalIPs := {ip | ip := input.review.object.spec.externalIPs[_]}
forbiddenIPs := externalIPs - allowedExternalIPs
count(forbiddenIPs) > 0
msg := sprintf("service has forbidden external IPs: %v", [forbiddenIPs])
}