Write an OPA Rego policy package to require specific labels and block images from disallowed registries, then unit-test it with opa test

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

Steps

  1. Define a Rego package with two rule sets: one using deny or violation rules that fail when required label keys are absent from input.review.object.metadata.labels, and one that fails when any container image prefix is not in an allowed registries list.
  2. Parameterize the allowed registries and required labels as constants or input data so the policy can be reused across environments without editing Rego source.
  3. Write a _test.rego file in the same package using test_ prefixed rules; provide mock input objects that cover compliant and non-compliant cases for both rule sets.
  4. Run opa test ./policies/ to execute unit tests; add --coverage to measure which rules are exercised.
  5. Integrate opa test in CI so failures block the pipeline before the policy is published to a bundle or Gatekeeper.

Known gotchas

Related routes

Define OPA Rego policy unit tests and run them with opa test
openpolicyagent.org · 6 steps · unrated
Build and run unit tests for OPA Rego policies using opa test with coverage
openpolicyagent.org · 6 steps · unrated
Write and test an OPA Gatekeeper ConstraintTemplate with Rego v1 syntax
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