Skip to content

How to Configure an ABAC Policy for Fine-Grained Access Control (FGA)

Fine-grained access control decides for each object and each field, not just for each endpoint. "Sales may call /orders" is coarse. "A sales rep may change the orders of their own region, while they haven't shipped, with a discount of at most 15%, and sees every field but the payment" is fine-grained. ObjectsGrid's ABAC policy expresses both in the same Rego file. This post shows how, one level of detail at a time, and ends with one complete policy. Every rule here was run against the platform's own policy engine and field filter before it went in this post.

New to ObjectsGrid policies? Start with How to Initially Configure Your ABAC Policy Upon Organization Account Registration. The access control guide is the reference.

Five levels of detail

Level The question What the rule reads
Operation May this caller do this to this type at all? input.action, input.objectType, the caller's tags
Object ...to this order in particular? the stored object's tags and fields, input.object
Field, read Which of its fields may the caller see? redact and visible rules
Field, write Which fields may the caller change? input.changedFields
Value To what values? input.newObject, the object as the write would leave it

Each request is decided twice. The operation stage comes first, with input.object equal to null. Then the object stage runs for every object the request reads or writes. A rule that reads input.object needs a companion for the operation stage, or the request is refused before any object is checked. Lists leave out the objects the caller may not read.

Object level: match the caller to the object

Sales reps work the orders of their region. Tag reps and orders with region, and compare:

allow if {
    has_role("sales")
    input.action in {"retrieve", "list", "update", "patch"}
    input.objectType == "Order"
    input.object == null # operation stage
}

allow if {
    has_role("sales")
    input.action in {"retrieve", "list", "update", "patch"}
    input.objectType == "Order"
    same_tag("region", input.object) # object stage
}

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

A rep covering two regions gets two region tags. A new region needs a tag, not a new rule. That is the difference from roles: the rule is about the match, not about any particular region.

Object level: decide on the object's state

An order that has left the warehouse shouldn't be changed by people any more, only by your backend:

closed := {
    "https://schema.org/OrderInTransit", "https://schema.org/OrderDelivered",
    "https://schema.org/OrderCancelled", "https://schema.org/OrderReturned",
}

deny if {
    not has_role("user")
    input.objectType == "Order"
    input.action in {"update", "patch", "delete", "retag"}
    input.object.orderStatus in closed
}

input.object is the order as it is stored, so the rule reads its status before the change. It's a deny, so it holds whatever the allow rules say, a sales manager's included.

Field level, write: guard one field

Merchandisers edit offers, but only pricing sets prices:

deny if {
    input.objectType == "Offer"
    "price" in input.changedFields
    not has_role("pricing")
    not has_role("user")
}

input.changedFields lists the top-level fields the write changes, and every field the object has on a create. So the same rule stops a merchandiser from creating an offer with a price, not just from changing it. For a nested field, guard its top-level parent: a change to address.postalCode changes address.

Value level: limit what may be written

A sales rep's discount stays at 15 or less; a sales manager may go higher:

deny if {
    has_role("sales")
    not has_role("sales-manager")
    input.objectType == "Order"
    "discount" in input.changedFields
    input.newObject.discount > 15
}

input.newObject is the order as the write would leave it, for create, update and patch alike. One caution with values that may be missing: input.newObject.orderStatus != "…" is undefined when there is no status, so a rule built on it doesn't hold and refuses nothing. Write not input.newObject.orderStatus == "…" instead.

Field level, read: hide some fields

Support reads customers, without their street address or date of birth:

allow if {
    has_role("support")
    input.action in {"retrieve", "list"}
    input.objectType in {"Person", "Order"}
}

redact contains field if {
    has_role("support")
    input.objectType == "Person"
    some field in {"address.streetAddress", "birthDate"}
}

Paths reach nested fields, so support still sees the city in address. Hidden fields are left out of REST answers and webhook deliveries, read as null in GraphQL, and are listed in the object's meta.redactedFields. Support can't set, filter or sort on them either, so a search can't reveal a hidden value. id, meta, at_type, at_context and url are always shown.

Field level, read: show only some fields

A wholesale partner's integration should see a short, stable list of fields, whatever you add to your products later. That's an allow-list, a visible rule:

partner_fields := {
    "Product": {"name", "sku", "gtin", "category", "offers"},
    "Offer": {"name", "itemOffered", "price", "priceCurrency", "availability"},
}

visible contains field if {
    has_role("partner")
    some field in partner_fields[input.objectType]
}

Read this before you add a visible rule. Once a policy has any visible rule, every caller other than administrators sees only the fields its visible rules name. That holds on every object, for every caller, not just the partner. Without anything else, your merchandisers would suddenly see a product's id, meta and url, and nothing more. Give everyone else a rule that makes every field of the object visible:

visible contains field if {
    not has_role("partner")
    some field, _ in input.object
}

visible contains field if {
    not has_role("partner")
    some field, _ in input.newObject
}

The second rule covers the object a write returns. With both in place, the partner gets exactly its list, and everyone else sees what their redact rules leave.

Access that ends on a date

A contractor's account carries the tag access-until = 2026-12-31. Past that date, every request of theirs is refused, without anyone having to remember to remove them:

deny if {
    some t in input.subject.tags
    t.name == "access-until"
    time.parse_ns("2006-01-02", t.val) < time.now_ns()
}

time.now_ns() is the time of the request. The layout 2006-01-02 is how Rego names the date format YYYY-MM-DD.

The whole policy

Everything above, with the helpers, in one policy you can start from. Your backend's service account carries role = user, as an Organization Account created without signing in already has. The other roles are tags an administrator gives each account.

package abac

import rego.v1

default allow := false

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

# Access that ends: a contractor's account carries access-until = 2026-12-31.
deny if {
    some t in input.subject.tags
    t.name == "access-until"
    time.parse_ns("2006-01-02", t.val) < time.now_ns()
}

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

# Sales reps work the orders of their regions.
allow if {
    has_role("sales")
    input.action in {"retrieve", "list", "update", "patch"}
    input.objectType == "Order"
    input.object == null # operation stage
}

allow if {
    has_role("sales")
    input.action in {"retrieve", "list", "update", "patch"}
    input.objectType == "Order"
    same_tag("region", input.object) # object stage
}

# An order that has left the warehouse is changed only by your backend.
closed := {
    "https://schema.org/OrderInTransit", "https://schema.org/OrderDelivered",
    "https://schema.org/OrderCancelled", "https://schema.org/OrderReturned",
}

deny if {
    not has_role("user")
    input.objectType == "Order"
    input.action in {"update", "patch", "delete", "retag"}
    input.object.orderStatus in closed
}

# A sales rep's discount stays at 15 or less; a sales manager goes higher.
deny if {
    has_role("sales")
    not has_role("sales-manager")
    input.objectType == "Order"
    "discount" in input.changedFields
    input.newObject.discount > 15
}

# Merchandisers run products and offers; only pricing sets prices.
allow if {
    has_role("merchandiser")
    input.objectType in {"Product", "Offer"}
}

allow if {
    has_role("pricing")
    input.objectType == "Offer"
    input.action in {"retrieve", "list", "create", "update", "patch"}
}

deny if {
    input.objectType == "Offer"
    "price" in input.changedFields
    not has_role("pricing")
    not has_role("user")
}

# Support reads customers and orders, without street addresses or birth dates.
allow if {
    has_role("support")
    input.action in {"retrieve", "list"}
    input.objectType in {"Person", "Order"}
}

redact contains field if {
    has_role("support")
    input.objectType == "Person"
    some field in {"address.streetAddress", "birthDate"}
}

# A wholesale partner reads products and offers, and sees only these fields.
allow if {
    has_role("partner")
    input.action in {"retrieve", "list"}
    input.objectType in {"Product", "Offer"}
}

partner_fields := {
    "Product": {"name", "sku", "gtin", "category", "offers"},
    "Offer": {"name", "itemOffered", "price", "priceCurrency", "availability"},
}

visible contains field if {
    has_role("partner")
    some field in partner_fields[input.objectType]
}

# With any visible rule, every caller sees only the fields its visible rules
# name: everyone but the partner sees every field.
visible contains field if {
    not has_role("partner")
    some field, _ in input.object
}

visible contains field if {
    not has_role("partner")
    some field, _ in input.newObject
}

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

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

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

Before you rely on it:

  • Keep accounts out of reach. Roles, regions and access-until are tags on accounts. No rule may let a non-administrator change a UserAccount or ServiceAccount, or they can rewrite their own access.
  • Decide who moves objects. Changing an order's region tag is also decided as the action retag, which no rule here allows to people. Your backend sets the region when it creates the order.
  • Try it in a second Organization Account, call it as each role, and read the access log, which records every decision and the policy version that made it. Keep your previous policy so one PUT puts it back.

ABAC, ReBAC and where tags fit

Fine-grained authorization is often discussed in terms of Google's Zanzibar and the systems built on it, which decide from a graph of relationships: "Ana is an editor of folder X, which contains document Y". That's relationship-based access control (ReBAC). ObjectsGrid's policy is attribute-based: it decides from the caller's and the object's tags and the object's own fields, in one place, at request time.

Most business rules read naturally as attributes: a region, a customer id, an order status, a price, a date. A relationship that matters to access becomes a tag on the object, such as region = north or customer = <user account id>, set by whoever creates the object. What ABAC doesn't do is follow chains of relationships, such as a document inheriting the access of its folder, then of the folder's folder. If your access model is mostly chains like that, it's a ReBAC problem. If it's mostly "who, what, which fields, which values", one policy covers it.

FAQ

What is fine-grained access control (FGA)?

Access decided for each object and each field, not only for each API endpoint: who may read this order, change this field, see this customer's address, or set a discount this high. Coarse-grained access stops at "may call /orders".

Can an ABAC policy hide individual fields?

Yes. A redact rule hides the fields it names, nested ones included, such as address.streetAddress. A visible rule shows only the fields it names. Hidden fields are left out of REST, GraphQL and webhook responses, and the caller can't set, filter or sort on them.

How do I stop someone from changing one field?

With a deny rule on input.changedFields, the top-level fields the write changes: deny if "price" is in input.changedFields and the caller doesn't have the pricing role. A deny overrides every allow.

Can a rule look at the value being written?

Yes. input.newObject is the object as the write would leave it, so a rule can cap a discount (input.newObject.discount > 15) or require a starting status. input.object is the object as it is stored, so a rule can refuse changes to an order once it has shipped.

Why does a visible rule hide fields from everyone else?

Once a policy has any visible rule, every caller other than administrators sees only the fields its visible rules name. Give everyone else a visible rule that names every field of the object: visible contains field if { not has_role("partner"); some field, _ in input.object }.

Is ABAC the same as relationship-based access control (ReBAC)?

No. ReBAC, as in Google Zanzibar, decides from a graph of relationships. ABAC decides from attributes: in ObjectsGrid, the tags of the caller and of the object, and the object's own fields. A relationship that matters to access becomes a tag, such as region or customer.