liveBook · Manning

Open Policy Agent

As explained in Effective Platform Engineering

Open Policy Agent is an open-source policy engine that evaluates declarative policies independently of the application or infrastructure being governed.

Open Policy Agent (OPA) is a declarative policy engine for making decisions about data. Supply JSON input and requirements written in Rego; OPA evaluates them to produce a policy decision. The same approach can serve governance needs beyond Kubernetes. section 4.2.1 section 4.1.1

For a development team that owns its deployment pipeline, compliance checks embedded in a centrally managed pipeline would undermine autonomy. An admission controller instead checks a requested change at the deployment boundary. OPA can provide the policy engine for that check, allowing teams to retain their pipelines while shared requirements remain enforceable. section 4.2 section 4.4

Build a policy gate incrementally:

  • Choose a requirement that can be checked against the requested change, such as whether a Kubernetes deployment has labels needed for cost tracking. section 4.1.1
  • Identify the data needed for the decision. OPA can use data included with its deployment or fetched when the policy runs. section 4.2.1
  • Express the requirement as Rego assertions and test both approval and rejection. For example, a coverage rule can compare a deployment’s source identifier with code-quality data and deny coverage below 80%. section 4.2.1
package test   #1
default allow := false   #2
allow if user_is_over_12  #3

user_is_over_12 if {  #4
    data.user_attributes[input.user].age > 12
}

This small Rego policy defaults to denying access, then allows it when a predicate finds that the input user’s recorded age exceeds 12. It makes the relationship between input, stored data, and decision visible before applying the same pattern to deployment controls. section 4.2.1

Gatekeeper offers a Kubernetes admission controller based on OPA and Rego, but formats policies more like Kubernetes resources. If policies will span multiple disciplines, decide early whether that format and its distribution assumptions fit a shared policy standard; differences can create friction later. section 4.1.1

How Effective Platform Engineering covers it

How deep it goes
Explains JSON inputs, Rego assertions, and admission-controller decisions with examples, while leaving agent deployment and policy publishing details aside.
Examples
Uses an age-based allow rule, a code-coverage threshold, and Kubernetes deployment-label checks.
What it assumes
Assumes familiarity with deployment pipelines and Kubernetes requests but introduces Rego predicates through a small data-and-input example.
What you can do after
Apply it via OPA and Rego to evaluate deployment requirements at an admission controller while preserving team-owned pipelines.
How it connects
Connects policy-as-code and Rego to Kubernetes admission controllers, deployment governance, and team-owned pipelines.

Also explained in

Compare how 2 books explain Open Policy Agent →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Platform Engineering. The section links point to the parts of the book it draws on.