SqlOS

Fine-Grained Auth

Data Model

Resources, subjects, roles, permissions, and grants.

6 sections

FGA has five pieces. Learn how they connect. Then model your app.

Resources#

A resource is a node in a tree. Every resource has a type, a parent (except root), and a name.

CSHARP
// SqlOSFgaResource
{
    Id: "chain_walmart",
    ParentId: "org::acme",
    Name: "Walmart",
    ResourceTypeId: "chain"
}

Resources form a tree. Grants on a parent apply below it. Resource hierarchy.

Subjects#

A subject is the entity being authorized. SqlOS supports four subject types:

TypeUse case
userHuman users synced from AuthServer
agentAutomated bots or AI agents
service_accountService-to-service access with API keys
user_groupGroups of users sharing permissions

See Subject Types.

Roles#

A role bundles permissions. Name them to match how your app works:

RolePermissions
Company AdminCHAIN_VIEW, CHAIN_EDIT, LOCATION_VIEW, LOCATION_EDIT, INVENTORY_VIEW, INVENTORY_EDIT
Store ManagerLOCATION_VIEW, LOCATION_EDIT, INVENTORY_VIEW, INVENTORY_EDIT
Store ClerkINVENTORY_VIEW

See Roles.

Permissions#

A permission is a string key for one resource type. Common style: RESOURCETYPE_ACTION in caps.

PermissionResource typeAction
CHAIN_VIEWchainRead
CHAIN_EDITchainWrite
LOCATION_VIEWlocationRead
INVENTORY_EDITinventoryWrite

See Permissions.

Grants#

A grant = subject + role + resource. Parent grant flows down the tree to children.

PLAINTEXT
Subject: "jane"
Role: "Company Admin"
Resource: "org::acme"
 
→ jane can CHAIN_VIEW, CHAIN_EDIT on all chains under org::acme
→ jane can LOCATION_VIEW, LOCATION_EDIT on all locations under those chains
→ jane can INVENTORY_VIEW, INVENTORY_EDIT on all inventory items

See Grants.

How authorization works#

Example: check CHAIN_VIEW on chain_walmart.

  1. Load grants for the subject.
  2. See if any role on the path includes CHAIN_VIEW.
  3. Walk up: chain_walmartorg::acmeroot.
  4. Match on any ancestor? Allow.

SQL Server runs this as a TVF. EF uses it in Where. No giant loads into memory.