Skip to content

Instantly share code, notes, and snippets.

@developer-guy
Forked from velotiotech/deny-lb-type-svc.yaml
Created November 30, 2020 19:33
Show Gist options
  • Save developer-guy/9b5bf6b3b7e2ceca771c8a9d347a3b11 to your computer and use it in GitHub Desktop.
Save developer-guy/9b5bf6b3b7e2ceca771c8a9d347a3b11 to your computer and use it in GitHub Desktop.
Constraint Template to deny service of type LoadBalancer
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: lbtypesvcnotallowed
spec:
crd:
spec:
names:
kind: LBTypeSvcNotAllowed
listKind: LBTypeSvcNotAllowedList
plural: lbtypesvcnotallowed
singular: lbtypesvcnotallowed
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package kubernetes.admission
violation[{"msg": msg}] {
input.review.kind.kind = "Service"
input.review.operation = "CREATE"
input.review.object.spec.type = "LoadBalancer"
msg := "LoadBalancer Services are not permitted"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment