Skip to content

Instantly share code, notes, and snippets.

@cartyc
Created September 17, 2019 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cartyc/db0fe2cea80d0b5fa8075befb1e76375 to your computer and use it in GitHub Desktop.
Save cartyc/db0fe2cea80d0b5fa8075befb1e76375 to your computer and use it in GitHub Desktop.
OPA Gatekeeper Duplicate Ingress
apiVersion: templates.gatekeeper.sh/v1alpha1
kind: ConstraintTemplate
metadata:
name: ingressdupes
spec:
crd:
spec:
names:
kind: IngressDupe
listKind: IngressDupeList
plural: ingressdupes
singular: ingressdupes
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package kubernetes.admission
deny[{"msg":msg}] {
host := input.review.object.spec.rules[_].host
ingress := data.inventory.namespace[other_ns]["extensions"].Ingress[other_ingress]
other_ns != input.review.namespace
ingress.spec.rules[_].host == host
msg := sprintf("invalid ingress host <%q> (conflicts with <%v>/<%v>)", [host, other_ns, other_ingress])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment