Configure OPA Gatekeeper mutation with Assign and AssignMetadata to automatically add default labels to pods

domain: security/compliance · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Enable the Gatekeeper mutation feature by setting --enable-mutation in the Gatekeeper controller manager arguments or via the Helm chart value; restart the controller after enabling.
  2. Write an AssignMetadata manifest to inject a specific label into every pod's metadata.labels using spec.match to scope it by namespace or resource kind.
  3. Write an Assign manifest to inject a value into a non-metadata field (e.g., spec.containers[].securityContext.readOnlyRootFilesystem) using a location path and spec.parameters.
  4. Apply both mutation CRDs and create a test pod to verify the label and field are injected; describe the pod and inspect its metadata.
  5. Check for mutation conflicts: if two Assign objects target the same path, Gatekeeper resolves them by applying all matching mutations and a conflict will cause neither to apply; audit the MutationStatus.

Known gotchas

Related routes

Configure OPA Gatekeeper with a ConstraintTemplate and Constraint to enforce that all Deployments have a specified owner label and block admission for non-compliant resources
open-policy-agent.github.io · 5 steps · unrated
Author an OPA Gatekeeper ConstraintTemplate and Constraint to enforce image signature requirements in Kubernetes
open-policy-agent.github.io/gatekeeper · 6 steps · unrated
Write an OPA Gatekeeper ConstraintTemplate and Constraint to require resource labels
open-policy-agent.github.io/gatekeeper · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans