Beta

Create a tenant

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

Writing rules with attributes

Roles describe people, but many access requirements depend on the thing being requested, the device or the time. A rule tests attributes of the subject, the resource, the action and the environment, so one sentence the organization agrees with can cover every person and every request.

When roles are not enough

All names, domains and identifiers in these examples are fictional.

The photo service's role list has started to multiply. Its picture editors, who check and approve photos before they are published, needed slightly different access for sports and news albums, freelancers needed less than staff, and agency photos licensed for some countries couldn't be handled like the service's own. Each difference became another version of a role, and each new requirement multiplied the list again.

Three requirements show where that leads. Unpublished photos shouldn't end up on personal laptops, so a picture editor may download one only on a device the photo service manages. Some photos arrive under embargo: a picture of the relay winner in the Sports day album can't be used before the result is announced, so no one may download it before its release time. And some agency photos are licensed only for certain countries, so they must not be downloaded from anywhere else.

Try writing the first requirement as a role. A "Picture editor on a managed device" role would have to be assigned to Jo, one of the picture editors, while she sits at the office laptop and removed when she opens a personal laptop at home. The device is a fact about the request, not about Jo, and roles describe people. The embargo fits even worse. It depends on which photo is requested and on the time, so a role that kept Jo away from the relay photo would have to change at the moment of release, and every embargoed photo would need its own.

Even the differences that do describe people multiply quickly. Two kinds of album and two contract types already make four versions of Picture editor. Add three licensing regions and there are twelve, before the device or the embargo has been expressed at all. The next requirement doubles the list again.

A rule says it once. "No one may download a photo before its embargo ends" covers every person, every photo and every moment, and it needs no change when someone joins or a new embargo arrives. The rule doesn't name anyone. It names properties of the person, the photo and the request, and the service looks up their values when each decision is made. Those properties are attributes.

Four kinds of attributes

Deciding what someone can do named four kinds of attributes: those of the subject, the resource, the action and the environment. For one request, Jo downloading draft photo 9003 from the Sports day album on the office laptop, they look like this:

subject
  id: user-1316
  employment: staff
  desk: sports
  roles: ["picture-editor"]

resource: photo 9003
  status: draft
  embargo_until: 2026-06-13T22:00:00Z
  license_regions: ["worldwide"]
  uploaded_by: user-1460
  legal_hold: false

action
  name: photo.download

environment
  time: 2026-06-14T13:30:00Z
  device.managed: true
  network: office
  country: US

The subject attributes describe Jo, account user-1316: a staff member on the sports desk who holds the Picture editor role where this photo lives. They change when Jo's job changes, which isn't often.

The resource attributes describe photo 9003, and they change as the photo moves through review. A draft becomes approved and then published. An embargo passes. The legal team places a hold. Some resource attributes are useful mainly in comparison with the subject. uploaded_by holds Cora's account, user-1460, because she took the picture. A rule can require that it differs from subject.id before anyone approves the photo, which turns the separation of duties from Administering roles safely into a single condition: photographers can't approve their own pictures.

The action is usually just its name, but actions have properties too. photo.view and photo.download both read a photo, yet only one hands over the full-resolution file, which can then be copied anywhere. A rule can name one action, or apply to every action that shares a property, such as every action that changes a photo.

The environment attributes describe this one request: when it arrived, from what kind of device, over which network and from which country. The licensing requirement compares that country with the photo's license_regions. The service's own pictures, such as Cora's, may be used anywhere, while an agency photo lists only the countries its agency allows. Unlike the subject and the photo, the environment can change between two requests a minute apart, when Jo closes the office laptop and opens a personal one.

From a sentence to a rule

A good rule starts as a sentence the photo service's team would agree with. Here is the device requirement, with the embargo added because both apply to downloads:

A picture editor may download a photo that hasn't been published yet, but only on a managed device. No one may download a photo before its embargo ends.

Each phrase becomes a test of one attribute. "A picture editor" means the subject's roles include Picture editor. "Hasn't been published yet" means the photo's status is draft or approved. "On a managed device" means the request came from a managed device. "Before its embargo ends" compares the time of the request with the photo's embargo_until. In the small illustrative format these lessons use for policy, the two sentences become three rules:

permit photo.download
  when "picture-editor" in subject.roles
   and resource.status in ["draft", "approved"]
   and environment.device.managed is true

permit photo.download
  when "picture-editor" in subject.roles
   and resource.status is "published"

forbid photo.download
  when environment.time is before resource.embargo_until

The second rule is easy to miss. The sentence restricts unpublished photos, which implies that picture editors may download published ones on any device, and a rule grants only what it says. The embargo became a forbid because it applies to everyone. If the service later lets another role download photos, the embargo still holds without anyone remembering to repeat it.

The photo service combines its rules the same way throughout these lessons. A request is allowed only when at least one permit matches and no forbid does, a combination often called deny overrides. When nothing matches, the answer is no: the default deny from Designing permissions.

Here are three requests from Jo on the afternoon after Sports day. Photo 9003 is a draft, and its embargo ended the night before. Photo 9005, the relay winner, is in the same album, also a draft, and embargoed until 14:00 UTC.

Three of Jo's download requests and how the three rules decide them
RequestDevice and timeResultWhy
Jo downloads photo 9003, a draft, embargo overManaged office laptop, 13:30 UTCAllowedThe first permit matches. The forbid doesn't, because the embargo has already ended.
Jo downloads photo 9003, a draft, embargo overPersonal laptop, not managed, 13:30 UTCDeniedThe photo is unpublished and the device isn't managed, so neither permit matches. Nothing grants the request.
Jo downloads photo 9005, a draft, embargoed until 14:00 UTCManaged office laptop, 13:30 UTCDeniedThe first permit matches, but so does the embargo forbid, and a forbid overrides a permit.

Managed laptop

Photo
9003, draft
Embargo
Over
Device
Managed
Draft permit
Matches
Embargo forbid
No match

Allowed

Personal laptop

Photo
9003, draft
Embargo
Over
Device
Not managed
Draft permit
No match
Embargo forbid
No match

Denied: nothing grants it

Embargoed photo

Photo
9005, draft
Embargo
Until 14:00 UTC
Device
Managed
Draft permit
Matches
Embargo forbid
Matches

Denied: the forbid wins

A request is allowed only when at least one permit matches and no forbid does.

Jo's three requests beside the three rules. Each answer changes with one attribute: the device in the second request, the time in the third.

At 14:00 the third request succeeds, with no change to a role, a rule or the code that asks the question. Only the time moved. Ava's requests never get that far. She uses the photo service for her own albums and holds no Picture editor role, so each permit fails at its first condition on any device and at any time.

Roles as attributes

The role didn't disappear from the rules. It became one condition, "picture-editor" in subject.roles, beside the photo's status and the device. This is how most systems combine roles with attributes. Roles still answer the question they are good at, what job a person does here, and the service's administrators still assign them in the usual way. Attributes answer a different question: under what conditions that job may be done.

The value of subject.roles isn't a fixed list stored on Jo's account. It is worked out for each request from the assignments that apply where the photo lives. Photo 9003 is in the Sports library, where Jo's group, Sports picture editors, holds Picture editor, so the role is in the list. For photo 7310 in the News library, where Jo holds only Viewer, the same rules see ["viewer"], and neither permit can match on any device. The scoped assignments from Roles, assignments, and scope keep working. The rules read their result.

The role list shrinks as a result. Desk and contract type no longer need to be part of a role's name, because a rule can test subject.desk or subject.employment directly. The twelve versions of Picture editor become one role and a few rules, and the next requirement adds a rule instead of doubling the roles.

The cost is visibility. With roles alone, "who can download photo 9003?" has an answer you can read from the assignments: everyone who holds Picture editor in the Sports library. With rules, the honest answer is "those people, on a managed device, after the embargo, and for an agency photo from a licensed country", and whether a particular download succeeds depends on facts that exist only when the request arrives. Nobody can print a list of who has access, which makes audits and reviews harder. Rules need to stay few and readable, and they need tests that show which requests they refuse as well as which they allow.

Check your understanding

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

The photo service wants to stop anyone downloading a photo before its embargo ends. A developer proposes a new role, Picture editor without embargoed photos. Why does a rule fit this requirement better? 1 of 3

Choose one answer.

At 13:30 UTC, Jo asks to download draft photo 9005 on a managed office laptop. The photo is embargoed until 14:00 UTC, and the permit for picture editors on managed devices matches. What is the result? 2 of 3

Choose one answer.

A rule reads: permit photo.download when resource.status is "draft". Ava holds no Picture editor role. What happens when she asks to download a draft? 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