Open Policy Agent (OPA) Introduction
What you'll learn: How OPA serves as a unified policy engine for infrastructure governance across your cloud environment.
What Is OPA?
Open Policy Agent (OPA) is an open-source, general-purpose policy engine that decouples policy decision-making from your application and infrastructure code. Think of it as a specialized judge that reviews requests and answers a simple question: "Is this allowed?"
Unlike traditional policy enforcement embedded deep in application logic or scattered across multiple tools, OPA provides a single, unified framework for expressing and enforcing policies across your entire stack—from Kubernetes admission control to Terraform deployments to API authorization.
How OPA Works
OPA uses a declarative language called Rego to define policies. You feed OPA three inputs:
- Data: Context about your infrastructure (resource configurations, user attributes, etc.)
- Policy: Rules written in Rego
- Query: A question about whether something should be allowed
OPA evaluates the query against your policy and data, then returns a decision—typically a boolean (allow/deny) or structured data.
OPA's Role in Infrastructure Governance
In infrastructure testing and compliance, OPA acts as the enforcement layer for "policy as code" (which you learned in the previous lessons). It lets you:
- Validate Terraform plans before apply
- Block non-compliant infrastructure changes in CI/CD pipelines
- Enforce security guardrails (e.g., "no public S3 buckets")
- Audit existing infrastructure against organizational standards
- Maintain consistent policies across multi-cloud environments
This separation means policy authors don't need to know infrastructure tooling, and infrastructure engineers don't need to implement complex policy logic.
Key Takeaway: OPA is a general-purpose policy engine that centralizes and standardizes how you express, enforce, and test infrastructure governance rules across your entire cloud environment.