# Authorization Policy Engines
> Externalized decision services (OPA/Rego, Cedar, OpenFGA/SpiceDB) that take authorization out of scattered `if` statements and evaluate it as policy-as-code at a central Policy Decision Point (PDP). The application's Policy Enforcement Point (PEP) only asks and obeys.
## How it works
**PDP/PEP split**: the PEP sits in the service or API gateway, intercepts the request, and asks the PDP `(principal, action, resource, context) → allow/deny`. Policy lives in Git, gets reviewed, tested in CI and deployed independently of app code. This is the remedy Auth0 and OWASP point to for BAC's "check sprawl" problem.
| Engine | Model | Language / data | Sweet spot |
|---|---|---|---|
| **OPA** (CNCF) | rule-based, general purpose | Rego (Datalog-derived), JSON input + `data` | K8s admission, Envoy, infra/config policy, complex ABAC; can return structured output, not just bool |
| **Cedar** (AWS, Rust) | RBAC + ABAC (+ ReBAC via entity hierarchy) | Cedar policies + schema + entities | app authz; behind **Amazon Verified Permissions**; analyzable, type-safe |
| **OpenFGA** (CNCF sandbox, from Auth0) / **SpiceDB** (AuthZed) | ReBAC, Zanzibar-style | type/relation model + relationship tuples | object-level sharing, hierarchies, "who can see this doc" at scale |
| **Teleport ACD** | role YAML + predicate language | default-deny role specs | Teleport infra access |
### What each looks like
Rego, which is default-deny only if you write it that way:
```rego
default allow = false
allow { startswith(input.path, "/admin/"); is_admin }
allow { startswith(input.path, "/public/") }
```
Cedar. Any matching `forbid` wins, otherwise any matching `permit` allows, and no match is an implicit deny:
```cedar
permit (principal, action == Action::"read", resource);
```
OpenFGA. Permissions are computed from relations:
```
model
schema 1.1
type user
type system
relations
define admin: [user]
type cat
relations
define system: [system]
define owner: [user]
define admin: admin from system
define can_manage: owner or admin
```
OpenFGA adds **conditions** and **contextual tuples** (time windows, status-driven access) on top of pure ReBAC.
## Engine-level security issues
The engine becomes the security boundary, so its failure modes matter.
**Trail of Bits / Teleport SPEF benchmark** (dynamic tests run in per-engine containers). Selected results:
| Test | Rego | Cedar | OpenFGA | Teleport |
|---|---|---|---|---|
| Deny enforced even when runtime errors occur | FAIL | FAIL* | PASS | PASS |
| Undefined values don't affect allow/deny | FAIL | PASS | PASS | n/a |
| Negation on undefined still denies | FAIL | PASS | PASS | PASS |
| Built-ins have no side effects / non-determinism | FAIL | PASS* | PASS* | PASS* |
| Resilient to DoS via recursive/expanding input | FAIL | PASS | PASS | PASS |
| Regex built-ins safe (perf/ReDoS) | FAIL | n/a (no regex by design) | FAIL | FAIL |
| Built-ins can't touch host system | FAIL* | PASS* | PASS* | PASS* |
| Policies can't exfiltrate cross-app context | FAIL* | PASS* | PASS* | PASS* |
| Unauthorized policy overrides don't change decisions | FAIL | PASS | n/a | PASS |
| Set ops scale at 10k/100k sets | PASS | PASS | FAIL | PASS |
(* = predicted.) The takeaway: Rego's expressiveness (undefined-as-false, network built-ins, structured output) is also its attack surface. Cedar deliberately omits regex and string formatting for analyzability.
**OPA-specific risks (Tenable research, CNCF write-up):**
- Malicious or untrusted Rego calling `http.send` / `net.lookup_ip_addr` to leak env vars or cloud metadata credentials. Policy code is code execution with network access.
- A Windows **UNC path** passed to the OPA CLI/SDK as a bundle location forces SMB authentication to an attacker share.
- Mitigations: restrict built-ins via OPA **capabilities** in `config.yaml` (`opa run --server --config-file config.yaml`), add tests asserting no `http.send` appears in policies, push data rather than letting OPA pull it (OPAL), keep policy in Git with CI, and pass minimal context in `input`.
**Distributed consistency (ReBAC)**: tuple stores can serve stale relations. Zanzibar-style systems use consistency tokens (zookies) to avoid the "new enemy" problem; see [[Access Control Models]].
## Where engines don't help
- The PEP still has to be **called on every path**. A route that never asks the PDP is a [[Function Level Authorization]] bug regardless of policy quality.
- Wrong inputs give wrong answers. If the PEP passes a client-supplied `tenant_id` or role as `principal`/`context`, the policy is evaluated against attacker data.
- Point-in-time decisions can't express sequence rules ("read secret, then send externally"). AWS **Dogwood** builds on Cedar with temporal conditions over prior tool calls for agents, and generates action schemas from MCP tool definitions. See [[AI Agent Authorization]].
- **RAG**: SpiceDB is used to pre-filter vector search to documents the user can see (LookupResources), rather than post-filtering retrieved chunks.
## Defenses / adoption checklist
- Default-deny at both PEP and policy level. Cedar is implicit-deny; in Rego write `default allow = false`, and test that deny holds when evaluation errors.
- Treat policy repos like code: review, unit tests (`opa test`, OpenFGA CLI YAML model tests), CI gates.
- Lock down engine capabilities (no network built-ins, bounded eval time), authenticate PDP endpoints, and protect the tuple store and bundle source as tier-0.
- Start by replicating the existing RBAC model, then add org-level relations, then finer-grained rules (OpenFGA migration guidance).
## Related
- [[Authorization Security]]
- [[Access Control Models]]
- [[Broken Access Control]]
- [[Multi-Tenant Isolation]]
- [[AI Agent Authorization]]
- [[Authorization Testing Automation]]
## Sources
- [[raw/auth0.com/why-broken-access-control-dominates-owasp-top-10-in-2026-3693|Why Broken Access Control Dominates OWASP Top 10 in 2026]]
- [[raw/goteleport.com/security-benchmarking-authorization-policy-engines-rego-cedar-openfga-4306|Security Benchmarking Authorization Policy Engines: Rego, Cedar, OpenFGA]]
- [[raw/cncf.io/opa-best-practices-for-secure-deployment-cncf-3971|OPA: Best Practices for Secure Deployment - CNCF]]
- [[raw/spacelift.io/opa-rego-language-tutorial-3969|OPA Rego Language Tutorial]]
- [[raw/wiz.io/what-is-open-policy-agent-opa-3970|What is Open Policy Agent (OPA)?]]
- [[raw/docs.cedarpolicy.com/cedar-policy-language-reference-3967|Cedar Policy Language Reference]]
- [[raw/strongdm.com/cedar-policy-language-complete-guide-3965|Cedar Policy Language Complete Guide]]
- [[raw/aws.amazon.com/amazon-verified-permissions-cedar-3966|Amazon Verified Permissions - Cedar]]
- [[raw/auth0.com/announcing-openfga-3963|Announcing OpenFGA]]
- [[raw/helpnetsecurity.com/openfga-open-source-engine-for-access-control-3962|OpenFGA: Open-Source Engine for Access Control]]
- [[raw/getlarge.eu/how-to-protect-your-api-with-openfga-rebac-concepts-to-practical-usage-4900|How to Protect Your API with OpenFGA: ReBAC Concepts to Practical Usage]]
- [[raw/madappgang.com/opa-vs-openfga-a-technical-comparison-of-policy-engines-4898|OPA vs OpenFGA: A Technical Comparison of Policy Engines]]
- [[raw/dev.to/opa-cedar-openfga-why-are-policy-languages-trending-right-now-4897|OPA, Cedar, OpenFGA: Why Are Policy Languages Trending Right Now?]]
- [[raw/permit.io/policy-engine-showdown-opa-vs-openfga-vs-cedar-3955|Policy Engine Showdown: OPA vs OpenFGA vs Cedar]]
- [[raw/permit.io/policy-as-code-fine-grained-authorization-3954|Policy as Code: Fine-Grained Authorization]]
- [[raw/grabtheaxe.com/fine-grained-authorization-technical-guide-for-microservices-4312|Fine-Grained Authorization: Technical Guide for Microservices]]
- [[raw/authzed.com/fine-grained-authorization-using-spicedb-for-rag-3959|Fine Grained Authorization using SpiceDB for RAG]]
- [[raw/blog.gitguardian.com/ai-agent-authorization-beyond-authentication-a-look-at-aws-dogwood-12173|AI Agent Authorization Beyond Authentication: A Look At AWS Dogwood]]