Skip to content

Access control with ABAC

ObjectsGrid decides every request with your Organization Account's ABAC policy: attribute-based access control, where the attributes are the tags of the account making the request and the tags of the objects it touches. You write the policy in Open Policy Agent Rego.

For example, the rule members of the marketing department may update brands tagged department: marketing needs no role per brand and no list of users: tag the users and the brands, and one rule covers them all. If you are new to ABAC, read Attribute Based Access Control and ABAC vs RBAC.

Tags

Accounts and objects carry tags, name and value pairs:

"tags": [
  {"name": "department", "val": "marketing"},
  {"name": "role", "val": "brand-manager"}
]
  • A name may repeat (role: buyer and role: approver), so read a name as a set of values. The same name and value appear only once.
  • Names use lowercase letters, digits and -, in parts separated by ., such as cost-center or acme.region. Values are compared exactly, case included.
  • Names starting with security. are security tags: the platform defines them and who may write them, whatever your policy says. Any other security. name or value is refused.
  • Every account also has the tag organization_account_id with your Organization Account id. The platform sets it, and nobody can change or remove it.

See Tag for how tags behave on create, replace and patch.

Administrators

The tag security.role with the value organization-account-administrator makes a User Account or a secret Service Account an administrator. The policy isn't evaluated for administrators: they may do everything in their Organization Account. The person who registered the Organization Account is its first administrator.

To protect your Organization Account from being locked out:

  • Only an administrator can grant or remove the role, or change, disable or delete an account that holds it.
  • An administrator can't remove their own role, or disable or delete their own account, so there is always one left.
  • A public service account can't be an administrator.
  • Only administrators can replace the ABAC policy, change identityProviders, monthlyQuota and customerDataRetentionYears, and revoke refresh tokens.
  • The accounting role: security.role = accounting lets an account read what an erased person's Orders keep for accounting. Every other account, administrators included, reads those fields as hidden, whatever the policy says. See Personal data and erasure.
  • The legal hold: security.legal-hold = true on a Person stops its erasure.
  • The erase action: administrators can erase a Person. Let others with a rule on input.action == "erase".
  • Linking an account to a Person: creating or changing a UserAccount so that its person points to a Person needs the right to update that Person, so the right to create accounts doesn't let anyone attach one to someone else's Person. The answer is 401 without it.

Like the administrator role, only administrators can add or remove these tags.

The default policy

A new Organization Account starts with a policy that gives accounts other than administrators no access, and shows examples in comments. Read yours with GET /abacpolicies/abac-policy--<organization account id>.

package abac

import rego.v1

default allow := false

Add rules to it, then replace it with PUT /abacpolicies/abac-policy--<organization account id>, sending {"policy": "<the Rego text>"}. A policy that doesn't compile, or isn't in package abac, is refused with 400 and the old one stays.

How a request is decided

Each request is decided in two stages, with the same policy:

  1. Operation stage. May this account perform this action on this type at all? input.object is null.
  2. Object stage. May it perform the action on this object? It runs once for each object the request reads or writes, with input.object set to the stored object. A create is decided at the operation stage, on the new object.

A request is allowed when an allow rule holds and no deny rule holds, at both stages. In a list, objects the account may not read are left out.

Let the operation stage through

A rule that only looks at input.object can't hold at the operation stage, where input.object is null, so the request is denied before any object is checked. Give such rules a companion rule for input.object == null, as in the examples below.

The input

Field What it holds
input.subject The account making the request: id, objectType (UserAccount or ServiceAccount) and tags.
input.action create, retrieve, list, update, patch, delete or retag.
input.objectType The catalog name of the type the request addresses, such as Product, Order, ABACPolicy, LogEvent, or Enum for /enums.
input.object At the object stage, the stored object, every field the API returns except credentials. null at the operation stage and on create. Its own type is input.object.meta.objectType.
input.newObject For create, update and patch: the object as the write would leave it.
input.changedFields With input.newObject: the top-level fields the write changes. On create, every field the new object has.

The policy's own outputs are allow, deny, redact and visible.

Examples

A small helper keeps rules readable:

has_tag(x, name, val) if {
    some t in x.tags
    t.name == name
    t.val == val
}

Let everyone read the catalog

Every signed-in account, and your anonymous visitors, may read products and offers:

allow if {
    input.action in {"retrieve", "list"}
    input.objectType in {"Product", "Offer"}
}

Department access

Members of the marketing department may read and update brands of their department:

allow if {
    input.action in {"retrieve", "list", "update", "patch"}
    input.objectType == "Brand"
    input.object == null                                 # operation stage
    has_tag(input.subject, "department", "marketing")
}

allow if {
    input.action in {"retrieve", "list", "update", "patch"}
    input.objectType == "Brand"
    has_tag(input.subject, "department", "marketing")
    has_tag(input.object, "department", "marketing")     # object stage
}

Owners manage their own objects

Each account may change and delete the reviews it created:

allow if {
    input.action in {"update", "patch", "delete"}
    input.objectType == "Review"
    input.object == null
}

allow if {
    input.action in {"update", "patch", "delete"}
    input.objectType == "Review"
    input.object.meta.createdBy == input.subject.id
}

Guard a field with deny

A deny rule overrides every allow rule, so a guard is written once. Only brand managers rename brands:

deny if {
    input.objectType == "Brand"
    "name" in input.changedFields
    not has_tag(input.subject, "role", "brand-manager")
}

Changing tags: the retag action

Tags decide access, so changing them is a separate permission. An update or patch that changes an object's tags is also decided as the action retag: allowing update doesn't allow changing tags. For example, marketing may move brands only between tags they hold themselves:

allow if {
    input.action == "retag"
    input.objectType == "Brand"
    has_tag(input.object, "department", "marketing")
    has_tag(input.newObject, "department", "marketing")
    every t in input.newObject.tags {
        has_tag(input.subject, t.name, t.val)
    }
}

A create isn't a retag: the tags a new object starts with are decided with the create, on input.newObject.

Hiding fields

A policy can hide fields from some readers:

  • redact contains "<field>" if { ... } hides a field.
  • visible contains "<field>" if { ... }, when the policy has any visible rules, shows only the fields they name.

Paths reach nested fields and lists: brand.url, or offers.price for the price of every offer. Only buyers see what brands cost:

redact contains "cost" if {
    input.objectType == "Brand"
    not has_tag(input.subject, "role", "buyer")
}

Hidden fields are left out of every response: REST, GraphQL (where they read as null) and webhook deliveries. The object's meta.redactedFields lists them. An account can't set, change, filter or sort on a field hidden from it, and a PUT that leaves hidden fields out keeps them. id, meta, at_type, at_context (on Schema.org types) and url are always shown.

Testing a policy

A policy change can lock people out, or let them in. Test it before you rely on it:

  • Try changes in a separate Organization Account first.
  • Keep the previous policy, so you can put it back with one PUT.
  • Check the access log: each entry shows which objects access was granted or denied to, and the version of the policy that decided.

Need help with a policy? Contact support.