Opscraft
Kubernetes, EKS, GitOps & releases

Open Policy Agent

Must-know9 lessons · 36 min · 3 tests ·

Open Policy Agent (OPA) is a general-purpose policy engine. You write rules as code in a language called Rego, give OPA some JSON describing a request or a configuration, and it returns a decision: allow or deny, plus reasons. In Kubernetes it usually runs as Gatekeeper, blocking non-compliant objects at admission time; in CI it runs as conftest, failing pipelines before bad manifests or Terraform plans reach production. Senior interviews expect you to explain policy-as-code, write a basic Rego rule, design a safe rollout of policies across clusters, and compare Gatekeeper with Kyverno and Kubernetes' built-in options.

Stage 3 · Production platforms

Know these first

After this topic you can

  • Write basic Rego policies
  • Enforce rules on Kubernetes with Gatekeeper or Kyverno
  • Test the same policies in CI with conftest

Lessons

  1. 1Policy as code: the idea and the architecture 4 min read
    • Why policy as code
    • Decoupling decisions from enforcement
    • Inputs, data and deployment options
  2. 2The Rego language 6 min read
    • Mental model
    • A first policy
    • Rule types
    • Undefined vs false
    • Iteration, quantifiers and comprehensions
    • Useful built-ins
    • Testing Rego
  3. 3Gatekeeper: OPA for Kubernetes admission 7 min read
    • Architecture
    • ConstraintTemplate and Constraint
    • Enforcement actions
    • The Gatekeeper policy library
    • Referential policies: syncing cluster data
    • Mutation
    • Testing Gatekeeper policies
  4. 4Kyverno and Kubernetes' built-in policy options 3 min read
    • Kyverno
    • Gatekeeper vs Kyverno
    • Built-in options
  5. 5Rolling out policies safely and operating them 4 min read
    • A rollout plan that doesn't break teams
    • Availability and failure modes
    • Performance
    • Managing policies across many clusters
  6. 6Shift-left: the same rules in CI with conftest 3 min read
  7. 7A starter policy set for EKS 3 min read
  8. 8OPA beyond Kubernetes admission 3 min read
  9. 9Interview questions and model answers 3 min read
    • "What is OPA and how does it work with Kubernetes?"
    • "How would you introduce policies without breaking teams?"
    • "What happens if Gatekeeper is down?"
    • "OPA vs RBAC?"
    • "Gatekeeper or Kyverno?"
    • "Write a Rego rule that blocks images not from our ECR."
    • "How do you test policies?"