Skip to main content

OPA Gatekeeper as an alternative

Use OPA Gatekeeper when your organization already standardizes on OPA and writes policy in Rego. Like , it runs as an admission webhook, so it checks the platform's requests as well as yours. Read first for how to scope a webhook so it never blocks the platform; this page covers what is specific to Gatekeeper.

Which tool to use 

  • Gatekeeper if you have an existing Rego policy library or an OPA practice to reuse. Its model is ConstraintTemplate (the reusable rule, in Rego) plus Constraint (the rule applied with parameters).
  • Kyverno if you want YAML-native policies and easy mutate and generate, with no Rego. See .
  • A native ValidatingAdmissionPolicy for any rule that must always block, because a webhook engine cannot guarantee that here, as explained below.

Install and write a constraint 

Install Gatekeeper with its Helm chart, then define a ConstraintTemplate and a Constraint:

yaml
				apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
  name: k8srequiredlabels
spec:
  crd:
    spec:
      names: {kind: K8sRequiredLabels}
  targets:
    - target: admission.k8s.gatekeeper.sh
      rego: |
        package k8srequiredlabels
        violation[{"msg": msg}] {
          not input.review.object.metadata.labels["team"]
          msg := "every workload must carry a team label"
        }
---
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabels
metadata:
  name: require-team-label
spec:
  match:
    kinds:
      - {apiGroups: ["apps"], kinds: ["Deployment"]}
			

Scope Gatekeeper's webhook 

Syself Autopilot does not check Gatekeeper's webhook configuration, so keep it inside the rules in :

  • Prefer failurePolicy: Ignore on Gatekeeper's webhook. If Gatekeeper is down and its webhook is Fail, it blocks every matching request, including the platform's own work on the cluster. Ignore means an outage skips the check rather than freezing the API.
  • Keep kube-system, kube-node-lease and kube-public out of its namespaceSelector, for example with Gatekeeper's namespace exemption settings. shows what happens when it reaches them while Gatekeeper is down.
  • Do not start the name of your own policies with syself-. The platform uses that prefix.

Why some rules need a native VAP 

With failurePolicy: Ignore, Gatekeeper's validation is best-effort: during a Gatekeeper outage, a policy violation can slip through, because the API server was told to allow rather than wait. That is the right trade for cluster availability, and it is why a rule that must never be bypassed, "no privileged pods, ever", belongs in a , which runs inside the API server and cannot be taken offline. Use Gatekeeper for the broad policy set and a native VAP for the few rules that must always hold. Keep Gatekeeper highly available to shrink the best-effort window.