Skip to content

How to Initially Configure Your ABAC Policy Upon Organization Account Registration

Right after you register an ObjectsGrid Organization Account, decide who may read and change what. Your ABAC policy decides that for every request. This post shows where a new account starts, the five decisions to make before you write a rule, and two complete policies: one for a shop and one for a service business such as a salon, a repair service or a clinic. Both policies were checked against the platform's own policy engine, one request at a time, before they went in this post.

If ABAC is new to you, read Attribute Based Access Control first. The access control guide is the reference for everything used here.

Where a new account starts

Administrators are never held to the policy: an account tagged security.role = organization-account-administrator may do everything in its Organization Account. The policy decides for everyone else, and what it starts with depends on how you registered:

You registered The policy you start with
By signing in with Google or Apple No access for anyone but administrators. The policy is default allow := false, with examples in comments
Without signing in, with one request Three API keys. admin is an administrator. user (tag role = user) reads and writes every business object. anonymous (role = anonymous) reads the catalog, keeps shoppers' carts by id, reads configuration and feature flags tagged public, and sends frontend logs

Either way, the starting policy is a default, not a design. It doesn't know your customers or your staff yet. Read yours with:

curl https://apis.objectsgrid.com/abacpolicies/abac-policy--<organization account id> \
  -H 'X-ObjectsGrid-AccessPoint: EU' \
  -H "Authorization: Bearer $ADMIN_TOKEN"

Five decisions before the first rule

  1. Who calls your API. Usually four kinds of caller: anonymous visitors (your storefront's public API key), your own backend (a secret service account), your staff (user accounts with a role tag) and your customers or clients (user accounts with no role tag).
  2. What each may do, per type. Make a short table: Product, Offer and the rest of the catalog; Order; Person; Inventory. Write it down as allowed actions: retrieve, list, create, update, patch, delete.
  3. Own or all. For every "yes" in the table, decide whether it means every object or only the caller's own. "Own" means a tag, such as customer = their account id, or meta.createdBy, the account that created the object.
  4. Which fields to hide. Payment details from warehouse staff, a client's date of birth from the front desk. redact rules hide fields without a second API.
  5. Who never gets a rule. Accounts, the policy, webhooks and access logs. If any rule lets a non-administrator change a user account, that person can give themselves a role. Keep these types for administrators alone.

Three things every policy needs

  • Both stages. Each request is decided twice: once for the operation, where input.object is null, and once for each object it reads or writes. A rule that looks at input.object can't hold at the first stage. Give it a companion rule for input.object == null, or the request is refused before any object is checked. Lists leave out the objects a caller may not read.
  • deny for guards. A deny rule overrides every allow rule. Use it for "may update orders, but only their status": one guard, whatever the allow rules say.
  • Tags are a permission of their own. An update that changes an object's tags is also decided as the action retag. Allowing update doesn't allow moving an order to another customer or location.

Retail: a shop

Who Tagged May
Visitors the anonymous API key, role = anonymous Read the catalog and the return and shipping policies; keep their carts; send frontend logs
Your backend a secret service account, role = user Every business object: it checks carts out into orders and records the payments
Merchandisers role = merchandiser Manage the catalog and the stock
Fulfillment role = fulfillment Read orders and stock; change an order's status, nothing else; never see how it was paid
Customers signed-in user accounts with no role Read the orders tagged with their account id; write and edit their own reviews

Your backend tags each order it creates with customer = the customer's user account id. That tag, not the order's contents, is what lets a customer read it.

package abac

import rego.v1

default allow := false

# What the shop shows to visitors who aren't signed in.
catalog := {
    "Product", "ProductGroup", "ProductModel", "Offer", "OfferCatalog",
    "Brand", "Review", "Rating", "Organization", "Place", "Enum",
    "MerchantReturnPolicy", "ShippingService",
}

# Only administrators manage accounts, the policy, webhooks and access logs.
administrator_only := {
    "OrganizationAccount", "ABACPolicy", "UserAccount", "ServiceAccount",
    "AccessLogEntry", "Webhook",
}

# Your backend's service account: every business object.
allow if {
    has_role("user")
    not input.objectType in administrator_only
}

# Everyone, visitors included: read the catalog.
allow if {
    input.action in {"retrieve", "list"}
    input.objectType in catalog
}

# The storefront's anonymous key sends frontend logs.
allow if {
    has_role("anonymous")
    input.action == "create"
    input.objectType == "LogEvent"
}

# The storefront keeps each visitor's cart by its id, which only that
# visitor's browser holds. Listing carts and checking them out are your
# backend's: the checkout makes the order.
allow if {
    has_role("anonymous")
    input.action in {"create", "retrieve", "update", "patch"}
    input.objectType == "Cart"
}

# Merchandisers: the catalog and the stock (reviews are the customers').
merchandise := (catalog - {"Review", "Rating"}) | {"Inventory"}

allow if {
    has_role("merchandiser")
    input.objectType in merchandise
}

# Fulfillment: read orders and stock, move orders on, count stock...
allow if {
    has_role("fulfillment")
    input.action in {"retrieve", "list", "update", "patch"}
    input.objectType in {"Order", "Inventory"}
}

# ...but on an order, change only its status...
deny if {
    has_role("fulfillment")
    input.objectType == "Order"
    input.action in {"update", "patch"}
    some field in input.changedFields
    field != "orderStatus"
}

# ...and never see how it was paid.
redact contains field if {
    has_role("fulfillment")
    input.objectType == "Order"
    some field in {"paymentMethod", "paymentMethodId", "paymentUrl"}
}

# Customers read the orders tagged with their account id.
allow if {
    customer
    input.action in {"retrieve", "list"}
    input.objectType == "Order"
    input.object == null # operation stage
}

allow if {
    customer
    input.action in {"retrieve", "list"}
    input.objectType == "Order"
    has_tag(input.object, "customer", input.subject.id) # object stage
}

# Customers write reviews, and edit or delete their own.
allow if {
    customer
    input.action == "create"
    input.objectType == "Review"
}

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

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

customer if {
    input.subject.objectType == "UserAccount"
    not has_any_role
}

has_role(role) if has_tag(input.subject, "role", role)

has_any_role if {
    some t in input.subject.tags
    t.name == "role"
}

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

What this policy gets right:

  • Customers can't create orders. An order your backend didn't create was never paid for: the storefront fills a cart, and your backend checks it out (POST /carts/{id}/checkout) once the payment provider confirms. Customers can't change orders either, or retag them to read someone else's. Payments (PayActions) stay with your backend.
  • Persons stay closed. No rule names Person except your backend's. Visitors, staff and customers can't list your customers' names and emails.
  • A staff member isn't a customer. customer means a user account with no role tag at all, so a merchandiser doesn't also get the customer rules.
  • New object types stay private. Every rule names the types it allows. A type you add later is closed until you decide who may use it.

Services: appointments at several locations

A service business books appointments: a salon, a repair service, a clinic, a consultancy. An appointment is a Reservation of a Service with a provider, the staff member, and a startTime and endTime; the client is a Person. ObjectsGrid refuses an appointment that overlaps another of the same provider (409), whatever the policy says, and GraphQL's availableSlots lists a provider's free slots from their EmployeeRole's work schedule. The new need is location: staff at one location shouldn't see another location's appointments or clients.

ABAC handles that with one tag, location, on staff, appointments and clients, and one rule: allow when the caller and the object share a location. A new location needs no new rule, just its tag.

Who Tagged May
Visitors the anonymous API key Read services, channels, offers, places and reviews
Your backend role = user Every business object; it shows visitors the free slots
Front desk role = front-desk, location = each location they work at Book, move and cancel appointments, and keep clients' details, at their locations; read staff schedules; edit the services. Clients' date of birth and gender stay hidden
Practitioners role = practitioner, location Read their locations' appointments and change their status; no client records, no prices
Clients signed-in user accounts with no role Request an appointment, which starts as pending; read their own; write reviews
package abac

import rego.v1

default allow := false

# What anyone may see before booking.
catalog := {
    "Service", "ServiceChannel", "Offer", "OfferCatalog", "Place",
    "Organization", "Review", "Rating", "Enum",
}

administrator_only := {
    "OrganizationAccount", "ABACPolicy", "UserAccount", "ServiceAccount",
    "AccessLogEntry", "Webhook",
}

allow if {
    has_role("user")
    not input.objectType in administrator_only
}

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

allow if {
    has_role("anonymous")
    input.action == "create"
    input.objectType == "LogEvent"
}

# Front desk: appointments and clients at their own locations, staff
# schedules, and the services.
allow if {
    has_role("front-desk")
    input.objectType in {"Reservation", "Person"}
    input.object == null # operation stage
}

allow if {
    has_role("front-desk")
    input.objectType in {"Reservation", "Person"}
    same_location(input.object)
}

allow if {
    has_role("front-desk")
    input.action in {"retrieve", "list"}
    input.objectType == "EmployeeRole"
}

allow if {
    has_role("front-desk")
    input.objectType in {"Service", "ServiceChannel", "Offer", "OfferCatalog"}
}

# An appointment or client the front desk writes stays at one of its locations.
deny if {
    has_role("front-desk")
    input.action in {"create", "update", "patch"}
    input.objectType in {"Reservation", "Person"}
    not same_location(input.newObject)
}

# Clients' details the front desk doesn't need.
redact contains field if {
    has_role("front-desk")
    input.objectType == "Person"
    some field in {"birthDate", "gender"}
}

# Practitioners: their locations' appointments, read and moved on, nothing else.
allow if {
    has_role("practitioner")
    input.action in {"retrieve", "list", "update", "patch"}
    input.objectType == "Reservation"
    input.object == null
}

allow if {
    has_role("practitioner")
    input.action in {"retrieve", "list", "update", "patch"}
    input.objectType == "Reservation"
    same_location(input.object)
}

deny if {
    has_role("practitioner")
    input.objectType == "Reservation"
    input.action in {"update", "patch"}
    some field in input.changedFields
    field != "reservationStatus"
}

redact contains field if {
    has_role("practitioner")
    input.objectType == "Reservation"
    some field in {"totalPrice", "priceCurrency"}
}

# Clients: request an appointment (it starts as pending; the front desk
# confirms it), read their own appointments, and write reviews.
allow if {
    client
    input.action == "create"
    input.objectType in {"Reservation", "Review"}
}

deny if {
    client
    input.action == "create"
    input.objectType == "Reservation"
    not input.newObject.reservationStatus == "https://schema.org/ReservationPending"
}

allow if {
    client
    input.action in {"retrieve", "list"}
    input.objectType == "Reservation"
    input.object == null
}

allow if {
    client
    input.action in {"retrieve", "list"}
    input.objectType == "Reservation"
    input.object.meta.createdBy == input.subject.id
}

client if {
    input.subject.objectType == "UserAccount"
    not has_any_role
}

# x carries a location tag the caller carries too.
same_location(x) if {
    some t in input.subject.tags
    t.name == "location"
    has_tag(x, "location", t.val)
}

has_role(role) if has_tag(input.subject, "role", role)

has_any_role if {
    some t in input.subject.tags
    t.name == "role"
}

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

What this policy gets right:

  • Locations without a rule each. Staff working at two locations get two location tags and see both. Opening a third location needs a tag, not a policy change.
  • Nothing moves between locations by accident. The deny on input.newObject means the front desk can't create an appointment elsewhere, or move one there. Changing tags is also decided as retag, which no front-desk rule allows.
  • Clients can't confirm their own appointments. An appointment must start as https://schema.org/ReservationPending; a missing status is refused too. Clients read only the appointments they created (meta.createdBy) and can't change them: they cancel through the front desk or your backend. Two clients can't take the same slot: the second gets 409.
  • Least data. Practitioners need the appointment, not the client record or the price, so they get neither.

Put it in place

1. Give your callers their tags. As an administrator, create a service account for your backend, and the public one for your storefront if you registered by signing in (accounts created without signing in already have both):

curl -X POST https://apis.objectsgrid.com/serviceaccounts \
  -H 'Content-Type: application/json' -H 'X-ObjectsGrid-AccessPoint: EU' \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  -d '{"type": "secret", "description": "Shop backend", "tags": [{"name": "role", "val": "user"}]}'

curl -X POST https://apis.objectsgrid.com/serviceaccounts \
  -H 'Content-Type: application/json' -H 'X-ObjectsGrid-AccessPoint: EU' \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  -d '{"type": "public", "description": "Storefront", "tags": [{"name": "role", "val": "anonymous"}]}'

Make the public account's API key with POST /serviceaccounts/{id}/apikey; see public API keys. Staff sign in like anyone else; then an administrator gives them their role (and locations, for services). A PATCH replaces the whole tags list, so send every tag the account keeps (the platform keeps organization_account_id itself):

curl -X PATCH https://apis.objectsgrid.com/useraccounts/<user account id> \
  -H 'Content-Type: application/json' -H 'X-ObjectsGrid-AccessPoint: EU' \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  -d '{"tags": [{"name": "role", "val": "front-desk"}, {"name": "location", "val": "lyon"}]}'

2. Replace the policy. Keep the one you have first, so you can put it back. The policy text goes in a JSON string, which jq builds for you:

POLICY_URL=https://apis.objectsgrid.com/abacpolicies/abac-policy--<organization account id>
curl -s $POLICY_URL -H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $ADMIN_TOKEN" > previous-policy.json

jq -Rs '{policy: .}' retail.rego | curl -X PUT $POLICY_URL \
  -H 'Content-Type: application/json' -H 'X-ObjectsGrid-AccessPoint: EU' \
  -H "Authorization: Bearer $ADMIN_TOKEN" -d @-

A policy that doesn't compile is refused with 400, and the old one stays.

3. Test it with a caller of each kind. The anonymous key should list products but not persons. A fulfillment account should read an order without its payment fields, and get 401 when it changes the discount. A customer should see only their own orders. Then open the access log: each entry shows what was granted or denied, and the version of the policy that decided. Better still, try a new policy in a second Organization Account before your real one.

Mistakes we see most

  • A rule that only looks at input.object. It fails at the operation stage, so the request is refused before any object is read. Add the input.object == null companion.
  • != on a missing field. In Rego, input.newObject.orderStatus != "…" is undefined when the field is absent, so the rule doesn't hold and nothing is refused. Write not input.newObject.orderStatus == "…".
  • Letting anyone change user accounts. Roles are tags on accounts. A rule that allows updating UserAccount lets its holders promote themselves.
  • "Own" by email. Match on the account id (input.subject.id), in a tag or in meta.createdBy. Emails change, and can be typed by anyone.

FAQ

What access does a new ObjectsGrid Organization Account give?

Administrators may do everything; the policy doesn't apply to them. An account registered by signing in starts with a policy that gives every other account no access. One created without signing in starts with a policy that gives its user key every business object and its anonymous key the public catalog.

How do I give a staff member a role?

An administrator tags their User Account, for example role = merchandiser, with PATCH /useraccounts/{id}. The policy reads input.subject.tags. Keep accounts out of reach of every rule, so nobody but an administrator can change roles.

How do customers see only their own orders?

Your backend creates each order with the tag customer = the customer's user account id, and the policy lets a customer read the orders tagged with their own id. Objects a customer may not read are left out of lists.

How do I keep staff at one location from seeing another location's appointments?

Tag staff and appointments with location, for example location = lyon, and allow access only when the caller and the object share a location tag. One rule covers every location; adding a location needs no policy change.

How do I hide payment details from some staff?

Add a redact rule: redact contains "paymentMethodId" when the caller has the fulfillment role and the type is Order. Hidden fields are left out of REST, GraphQL and webhook responses for that caller.

How do I test a policy before relying on it?

Try it in a separate Organization Account first, keep the previous policy to put it back with one PUT, call the API with an account of each role, and check the access log, which records the decisions and the policy version that made them.