Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Policy as code

The Gazette's authorization rules have been written in a readable notation so far. This lesson moves them into a real policy language kept in a repository, where every change is validated, tested and reviewed before the decision service loads it, and where applications ask their questions in one standard format.

A policy in a repository

The Gazette's policy has a version number because it lives in version control, as Evaluating a policy mentioned. Until now the lessons wrote its rules in a readable notation made up for them. The Gazette's decision service runs real code, and when the newsroom chose a policy language, the choice came with tools: a way to declare what attributes exist, a checker that refuses a policy that uses one wrongly, a test runner and a standard way for applications to ask questions.

Policy as code means treating authorization rules the way software is treated. The policy is a set of text files in a repository. A change is proposed as a pull request, a request to merge an edited copy of the files that shows exactly which lines changed, read by a reviewer, checked automatically, and published as a numbered version that the decision point loads. Anyone can see who changed what and why, and any version can be restored. The newsroom chose Cedar, an open-source policy language, for version 15. Others choose Rego, the language of the Open Policy Agent, an open-source policy engine, or an engine built on relationships between people and resources, such as OpenFGA; the practices in this lesson are the same for all of them.

The embargo in Cedar

A Cedar policy starts from a schema, which declares the kinds of entities, their attributes and which actions apply to which entities. Here is the part of the Gazette's schema that the download rules use:

text
namespace Gazette {
  entity Role;
  entity User in [Role] { department: String };
  entity Photo {
    status: String,
    uploadedBy: User,
    embargoUntil?: Long,
    legalHold: Bool
  };
  action "photo.download", "photo.delete", "photo.approve" appliesTo {
    principal: [User],
    resource: [Photo],
    context: { now: Long, managedDevice: Bool }
  };
}

User in [Role] says a user can be a member of roles, so Omar, user-1187, can be placed in the role picture-editor. The question mark on embargoUntil makes it optional, because most photos have no embargo. Times are whole seconds since 1970 in UTC, so the rules compare numbers rather than text.

The rules from version 14 become these policies:

text
@id("editor-published")
permit (
  principal in Gazette::Role::"picture-editor",
  action == Gazette::Action::"photo.download",
  resource
) when { resource.status == "published" };

@id("editor-unpublished")
permit (
  principal in Gazette::Role::"picture-editor",
  action == Gazette::Action::"photo.download",
  resource
) when { ["draft", "approved"].contains(resource.status) && context.managedDevice };

@id("embargo")
forbid (principal, action == Gazette::Action::"photo.download", resource)
when { resource has embargoUntil && context.now < resource.embargoUntil };

@id("legal-hold")
forbid (principal, action == Gazette::Action::"photo.delete", resource)
when { resource.legalHold };

@id("own-approval")
forbid (principal, action == Gazette::Action::"photo.approve", resource)
when { resource.uploadedBy == principal };

Each policy has the parts the earlier lesson named. The scope in parentheses is the target: which principals, actions and resources the policy is about. The when clause holds the conditions, and permit or forbid is the effect. resource has embargoUntil checks that the optional attribute is present before comparing it, which the schema checker insists on.

Cedar combines policies the way the Gazette already did. A request is allowed only if at least one permit matches and no forbid does, so a forbid always overrides, and a request nothing permits is denied. Omar's 13:30 download of photo 9002, with an embargo until 14:00, arrives with context.now set to 1781443800 against an embargoUntil of 1781445600. Both editor-unpublished and embargo match, so the answer is deny, with embargo named as the policy that decided it.

Testing a policy

Writing rules in a real language buys three kinds of checking before a change reaches the decision point.

The first is validation against the schema. If a developer writes resource.embargo_until, misspelling the attribute, or compares resource.status with a number, the validator refuses the policy with the line and the reason. In the made-up notation, that rule would have loaded and silently never matched, and an embargo that never matches is a leak.

The second is the table of test cases from Testing, auditing, and changing policy, run against the real engine. Each case is a request, its entities and the decision it should get, kept in the same repository as the policy. The pull request cannot be merged while a case fails, which is how the 13:59:59 and 14:00:00 pair keeps guarding the embargo boundary through every later change.

The third is analysis. Because Cedar's rules have precise meanings, tools can compare two versions of a policy and report every kind of request whose answer would change, without anyone writing a test for it. Running that comparison on version 15 is a cheaper first look than the week in shadow mode, though not a replacement for it, since only real traffic shows which of those changes people will actually hit.

A change travels from a pull request to the decision service; a request travels from the photo API through AuthZEN to the same decision service.

Asking through AuthZEN

The photo API, the Gazette's mobile backend and its nightly archive job all ask the decision service the same kind of question. If each speaks a format invented for one engine, switching engines means changing every caller. AuthZEN, the OpenID Foundation's Authorization API, standardizes that question and answer. Its version 1.0 became a Final Specification, the foundation's name for a finished standard, in January 2026.

An evaluation request names the subject, action, resource and context, the four parts every decision has:

http
POST /access/v1/evaluation HTTP/1.1
Host: decisions.photos.example
Authorization: Bearer (the photo API's own access token)
Content-Type: application/json

{
  "subject": { "type": "user", "id": "user-1187" },
  "action": { "name": "photo.download" },
  "resource": { "type": "photo", "id": "9002" },
  "context": { "device": { "managed": true } }
}

The answer is a boolean, with an optional object for whatever else the decision service wants to say:

http
HTTP/1.1 200 OK
Content-Type: application/json

{ "decision": false, "context": { "reason": "embargoed", "policy_version": 15 } }

The same API has a batch form, /access/v1/evaluations, that asks several questions in one request, which suits a page of thumbnails, and search forms that ask which resources a subject may act on, which suits the lists that Enforcing access across a system turned into queries. A decision service publishes what it supports in a metadata document at /.well-known/authzen-configuration.

AuthZEN standardizes only the conversation. It says nothing about the policy language behind it, so the decision service translates the request into Cedar entities, fetching the photo's attributes itself. The API sends only what it knows from the request, the device's state here, and never the attributes the decision service can look up, so a caller cannot make a photo look published by saying so.

Mapping to the four points

Decision and enforcement points named four parts of every decision. Policy as code gives each a concrete form:

The four points in the Gazette's policy as code
PointAt the Gazette
Administration point (PAP)The policy repository: pull requests, review, validation, tests and the pipeline that publishes each version
Decision point (PDP)The decision service running the Cedar engine, answering AuthZEN requests
Enforcement point (PEP)The photo API, mobile backend and archive job, each sending AuthZEN requests and carrying out the answer
Information points (PIP)The photo library, the directory's role memberships and device management, read by the decision service

The arrangement leaves each part replaceable. The newsroom could move from Cedar to another engine by changing the decision service and translating the policy, while the photo API kept sending the same AuthZEN requests. And it could change who may download embargoed photos without touching any application, by merging a reviewed, tested pull request, which is what the earlier lessons meant when they said to change the policy, not the API.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

A developer writes the embargo rule with resource.embargo_until, but the schema names the attribute embargoUntil. What happens when the change is proposed? 1 of 3

Choose one answer.

The Gazette moves its decision service from Cedar to another engine. What has to change in the photo API, which asks for decisions through AuthZEN? 2 of 3

Choose one answer.

Version 15 adds a rule for downloads in risky sessions. Before a week in shadow mode, the newsroom wants a first look at every kind of request whose answer would change from version 14, including ones no test describes. What gives it that? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity