Free & open · no paywall, ever

IntegrAuth Academy

Identity, security and practical AI — free, from zero. Byte-sized lessons, real diagrams, hands-on labs, zero fluff. Two programs, each with its own exam and certificate.

20 tracks 241 lessons 242 hands-on labs 230+ diagrams 100% free

English is hard? Your browser can translate this page into Tamil, Telugu, Kannada, Malayalam or Hindi. Tech words stay in English so you learn the real names.

How?
  • Chrome on phone: ⋮ menu → Translate
  • Chrome on computer: right-click → Translate to …
  • Edge: the translate icon in the address bar
Identity & API Security Track 4 · Authorization
0/166 lessons read
AUTHORIZATION · LESSON 3

Policy as code — rules kept outside the app

Many apps hide access rules in if (user.role == "admin") lines. The security team cannot change them without a new release. Your goal: keep rules in one place outside the app, where you can review, test and roll them back.

Key points
  • Rules scattered in code cannot be audited or changed fast.
  • The PEP stops the request and asks. The PDP holds the rules and decides.
  • A policy is a versioned file: review it, test it, roll it back.
  • Policies ship as a bundle to a sidecar next to each service.
  • The decision log is your audit trail.

The problem: rules all over the app

Suppose authorization lives in if statements across many handlers. Three bad things follow. You cannot audit it, because nobody can list all the rules. It is inconsistent, because services drift into different rules for the same question. It is slow to change, because a tighter rule needs a code change and a release. Priya's request to "stop contractors opening restricted files" becomes a two-week ticket.

The fix: decide in one place, enforce at the door

You met these two roles in zero trust. The Policy Enforcement Point (PEP) sits in your app or gateway. It stops the request, asks, and obeys the answer. The Policy Decision Point (PDP) is a separate engine. It holds all the rules and answers "allow" or "deny". Your code asks: "PDP, may Priya delete doc:report?"

Think of it like…

a society gate. The watchman (PEP) stops each visitor and follows the rule book, but never invents a rule. The rule book (PDP) says who may enter and when. The committee edits the rule book. Change one page, and every gate follows.

OPA and Rego

Open Policy Agent (OPA) is an open-source engine that works as a PDP. Rego is the language you write its policies in. The syntax matters less than the idea: a policy is a file with a version. You review it in a pull request. You test it with unit tests, such as "this request must be denied". If a change goes wrong, you roll it back like any commit. No service release is needed.

PriyarequestApp / gatewayPEP · enforcesPDP (OPA)decides:allow / denyPolicy bundlesigned · versionedDecision logthe audit trail1 · call2 · query3 · decide4 · logged
Figure — Decide once, enforce everywhere, log always. Policies ship as a signed bundle to the PDP. The PEP asks and obeys. Every answer becomes a line in the decision log.

Bundles near the service, logs as the trail

Calling a far-away server on every request is slow. So OPA packs the policies into a policy bundle. The bundle goes to a sidecar: a small helper program that runs next to each service. Decisions are then local and take microseconds. The PDP also writes each decision to a decision log: who asked, about what, and the answer. This log is your audit trail. It also feeds identity telemetry and SIEM.

Why it matters

Use a policy engine when the decision depends on conditions, such as time or data class. Use a relationship graph when it depends on ownership and sharing. Real systems join both. The graph says "Priya is a viewer". The policy adds "only in business hours, from a managed device." The MCP governance gateway uses the same habit.

Go deeper: what a policy looks like, and other engines

Here is a small policy in Rego (OPA 1.0 or later). It lets a user read a document from their own department, but not outside business hours.

Line of the policyWhat it says
package reports.authzThe name of the policy.
default allow := falseIf no rule says yes, the answer is no.
allow if { input.user.department == input.resource.department; not outside_hours }Allow when the departments match and it is not outside hours.
outside_hours if input.request.hour < 6Before 6 a.m. is outside hours.
outside_hours if input.request.hour >= 22From 10 p.m. is outside hours. Two rules with one name mean "or".

OPA is a CNCF graduated project, and not the only choice. Cedar is an open-source policy language from AWS. It joined the CNCF as a Sandbox project in 2025. One Cedar rule looks like this. permit (principal == User::"priya", action == Action::"export", resource in Folder::"finance") when { context.managed_device }; In Cedar, everything is denied unless a permit allows it, and a forbid always wins. Casbin is an open-source library that checks access inside your app, in many programming languages. OpenFGA and SpiceDB, from the last lesson, are graph engines.

Each engine had its own API. AuthZEN fixes that. It is an OpenID Foundation standard, "Authorization API 1.0", approved as Final in January 2026. A PEP sends a PDP a small JSON request with a subject, an action and a resource: {"subject":{"type":"user","id":"sam"},"action":{"name":"edit"},"resource":{"type":"doc","id":"report"}} The PDP answers {"decision":true} or {"decision":false}. So you can swap the engine without changing the gateway.

🧪 Interactive lab — enable JavaScript to play with this one.

🧪 Try it free

Moving authorization out of your services? Talk to our team about PEP and PDP design and policy as code.