Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
OPA Gatekeeper is a Kubernetes admission controller that enforces Open Policy Agent rules. Constraint templates hold the Rego; constraints apply it to selected resources with parameters.

What Is OPA Gatekeeper?
Gatekeeper puts Open Policy Agent in the path of every request to the Kubernetes API server. When a manifest is submitted, the admission webhook evaluates it against the policies installed in the cluster and either admits it, rejects it with a message, or records a violation, depending on how the policy is configured. It is a project of the Open Policy Agent community under the Cloud Native Computing Foundation.
The design separates the logic from its application, which is the part newcomers find unfamiliar.
A ConstraintTemplate contains a Rego policy and declares a schema for the parameters it accepts. Installing one creates a new custom resource type in the cluster. A Constraint is an instance of that type: it supplies parameter values, selects which resources the rule applies to, and sets the enforcement action.
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sAllowedRepos
metadata:
name: images-from-approved-registries
spec:
enforcementAction: dryrun
match:
kinds:
- apiGroups: [""]
kinds: ["Pod"]
excludedNamespaces: ["kube-system", "gatekeeper-system"]
parameters:
repos: ["ghcr.io/acme/", "registry.internal.acme/"]
The separation pays off at scale. One template for an approved registry list, written and tested once, can be instantiated differently for production, staging, and a sandbox cluster without anyone touching Rego again. Platform engineers write templates; application teams and cluster owners write constraints.
The community Gatekeeper Library provides tested templates for the usual requirements — required labels, container limits, host path restrictions, allowed registries, blocked node ports — which means most clusters never need to write Rego from scratch.
Enforcement is not binary. enforcementAction accepts deny, dryrun, and warn, and Gatekeeper additionally runs a periodic audit that evaluates resources already in the cluster against every constraint and writes the violations into the constraint’s status field.
That audit loop is the feature that makes a rollout survivable. An admission controller only sees new and updated objects, so a cluster can be full of resources that would never be admitted today. Audit finds them before you switch anything to deny, and it keeps finding them when a constraint is tightened later.
Some rules need context that is not in the incoming manifest: an ingress hostname must be unique across the cluster, a namespace must not exceed a count of services, an image must not already be deployed elsewhere. Gatekeeper handles this by replicating selected resource types into OPA’s cache, configured through a Config or SyncSet resource, so policies can query data.inventory.
Replication costs memory and introduces a window where the cache is stale, so sync only the kinds you genuinely need. Gatekeeper also supports mutation — Assign and AssignMetadata resources that set fields on admission — and external data providers that call out to another service during evaluation, which is how image signature checks are usually wired in.
Both replaced the use cases of PodSecurityPolicy, which was removed in Kubernetes 1.25. The honest comparison is this: Gatekeeper gives you Rego, which is more powerful, applies far beyond Kubernetes, and takes real effort to learn. Kyverno keeps everything in YAML and adds resource generation, which most teams find faster to adopt.
Choose Gatekeeper when your organisation already uses Open Policy Agent for service authorisation, Terraform gating, or data filtering, and wants one policy language across all of them. Choose Kyverno when Kubernetes is the only place policy is enforced and the people writing it are application teams.
Either way, neither replaces Pod Security Standards, which are built into the API server, cost nothing, and keep working when your webhook does not.
kube-system and the Gatekeeper namespace from the start, or a cluster upgrade will deadlock.gator, the project’s command-line verifier, in continuous integration. A Rego error that only appears at admission time is an outage.Done properly this is policy as code at the most useful point in the lifecycle: the moment before something exists.
The template holds the Rego policy and defines what parameters it accepts; installing it creates a new resource type in the cluster. The constraint is an instance of that type that supplies the parameters, selects which resources and namespaces it applies to, and sets the enforcement action. One template typically has several constraints behind it, tuned per environment.
Yes, through its audit controller. On a configurable interval it evaluates existing cluster resources against every constraint and records violations in the constraint’s status. This matters because admission control only sees new and changed objects, so a cluster adopting policy usually contains plenty of resources that would be rejected today. Run audit for a few weeks before enforcing anything.
Not necessarily. The Gatekeeper Library publishes tested constraint templates for most common requirements, and using them means writing only YAML constraints with parameters. Rego becomes necessary for organisation-specific logic. If your team already writes Open Policy Agent policies elsewhere, that is a strong argument for Gatekeeper; if not, a YAML-based engine may be a faster route to the same controls.
With the webhook failure policy set to Fail, which is what enforcement requires, the API server rejects requests it cannot validate, so an unhealthy Gatekeeper can block deployments across the cluster. Mitigate by running several replicas across nodes, excluding system namespaces so the cluster can heal itself, setting a sensible webhook timeout, and testing the failure mode before production depends on it.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.