Course contentsShow
← Cloud and Infrastructure
Lesson 2338 of 2,98950. Compliance and GovernanceFree lesson

Open Policy Agent (OPA) Fundamentals

Understanding OPA architecture, Rego language basics, and its role in policy-based control across systems.

Open Policy Agent (OPA) Fundamentals

What you'll learn: How OPA provides unified, policy-based control across your infrastructure using a declarative language called Rego.

What Is Open Policy Agent?

Open Policy Agent (OPA) is an open-source policy engine that decouples policy decisions from your application and infrastructure code. Think of it as a specialized "decision-making service" that answers yes/no questions based on rules you define. Instead of hardcoding authorization logic into every service, you centralize policy enforcement in OPA.

OPA Architecture Components

OPA runs as a lightweight daemon that receives queries (questions about whether something should be allowed) and returns decisions (yes/no answers). It evaluates policies written in Rego against input data you provide.

The three key pieces:

  • Policy: Rules written in Rego that define what's allowed
  • Input data: Context about the request (who, what, when)
  • Output decision: Boolean result or structured data

OPA doesn't enforce policies itself—it only makes decisions. Your systems must query OPA and act on its responses.

Rego Language Basics

Rego is a declarative query language designed for policy definition. Rather than saying "if X then deny," you define what's allowed and let OPA figure out the logic. It uses pattern matching and logical rules.

Basic Rego syntax expresses rules as assignments:

allow = true {
    input.user.role == "admin"
}

This reads: "allow is true when the input user's role is admin."

OPA's Role in Policy-Based Control

OPA enables policy as code across heterogeneous systems—Kubernetes admission control, API gateways, CI/CD pipelines, cloud resource provisioning. One policy engine, consistent enforcement everywhere. This supports compliance requirements by ensuring controls apply uniformly regardless of where resources are created.

Key Takeaway: OPA decouples policy decisions from application logic using the Rego language, enabling consistent, auditable policy enforcement across your entire infrastructure stack.