Core Concepts
SaaSLayer Permissions combines role-based access control, attribute-based policy conditions, relationship-aware hierarchy, and direct resource grants. The model is broad, but the core pieces are small.
Principals
A principal is something that can receive permissions.
Supported principal types include:
USERAGENTSERVICE_ACCOUNT
Users usually represent humans. Agents and service accounts represent automated actors, integrations, or delegated workflows.
Agent and service account ids and names
Agents and service accounts get a server-generated, immutable id (agt_… for agents, sa_… for service accounts). You choose a name, which is unique per owner and principal type and becomes reusable once the principal is deleted:
POST /principals/serviceAccount
Idempotency-Key: deploy-bot-v1
{ "name": "deploy-bot", "ownerType": "org", "ownerId": "org_acme" }201returns the new principal with its generatedid. Store theidwherever you reference the principal (grants, audit, your own data such asnote.createdBy).- Retrying with the same
Idempotency-Key(default: a hash of the payload) and the same payload returns200with the existing principal. - The same name under the same owner with a different key or payload returns
409 NameTaken. - Passing an
idin the body returns400.
Resolve a name to its principal with GET /principals/serviceAccount?name=deploy-bot&ownerType=org&ownerId=org_acme.
Users keep the id you give them. Creating a user never overwrites one: a repeat create whose fields already match is a
no-op, anything else is 409 Conflict. During a maintenance cutover every principal create answers
503 PrincipalCreationPaused with a Retry-After header; retry after that many seconds.
Every decision is keyed by the principal's type as well as its id, so an agent never inherits a user's permissions, grants or orgs even when their ids are equal.
DELETE /principals/{type}/{id} removes the principal together with its role assignments, direct grants, memberships, sessions, delegated grants, standing delegations it owns or grants through, API keys, auth methods and cached permission documents, and frees its name. Re-creating the same name produces a new id, so nothing that referenced the old principal applies to the new one. A principal that still owns other principals returns 409 until they are transferred or deleted.
Authenticating principals (USER, AGENT, SERVICE_ACCOUNT) can also act for another principal via agent delegation.
For workload identity, see federated principal auth.
For an app that keeps its existing human sign-in provider, see keep your existing
sign-in.
Organizations, workspaces, and groups
The hierarchy gives permissions a business context:
Organization
Workspace
GroupUse organizations for customer accounts. Use workspaces (/workspaces) for subdivisions inside an organization, such as environments or product boundaries. Use groups for teams or collections inside a workspace.
Membership and role assignment are separate. A user can belong to a workspace without having any useful permissions there.
Roles
A role is a named bundle of permissions.
Example permissions:
[
{ "effect": "can", "action": "read", "resource": "invoice", "service": "billing" },
{ "effect": "can", "action": "approve", "resource": "invoice", "service": "billing" },
{ "effect": "deny", "action": "delete", "resource": "invoice", "service": "billing" }
]Roles can be assigned globally or at a scope such as a workspace. Roles can also inherit from parent roles.
Assignments and end dates
POST /users/{id}/roles takes an optional expiresAt: the assignment stops granting
at that instant. When the expired assignment is removed, a role.removed audit
entry records the change. A user holds a role at a scope once:
- Assigning it again with the same end (or both without one) answers
201withalreadyAssigned: true; nothing changes. - With a different end it answers
409role_already_assigned,meta.existing.expiresAtnaming the current end (nullfor none). Change the end withPATCH /users/{id}/roles/{roleId}?scope=…{ "expiresAt": "…" | null }, or remove the assignment first. - An assignment that has ended is renewed by assigning it again; a role held only through a parent role becomes a direct assignment.
503expiry_schedule_failed: the end could not be scheduled, and nothing was granted or changed. Retry.
A role included by another role (inheritance) never replaces a direct assignment of it, and lasts as long as the
longest-lasting role that includes it. Invitations refuse a role listed twice at one scope (400 duplicate_grant);
accepting one skips grants the invitee already holds and lists them in skipped.
Policies
Policies are reusable statement bundles that can attach to users, roles, organizations, workspaces, or groups.
Use policies when a rule is more expressive than a simple role permission, or when you want to attach the same conditional logic in multiple places.
Policies can be written as JSON statements or authored in Cedar and compiled into SaaSLayer Permissions statements at write time.
Resources
Resources are the things your application protects: invoices, devices, documents, projects, API routes, tools, or anything else.
Simple resource strings work:
device
invoice
document/doc-123XRNs: a full address for a resource
An XRN (eXtensible Resource Name) identifies a resource within a product,
service, region and scope. Think of it as the full address of an invoice:
inv-123 alone might exist in several teams, but the XRN says which one you mean.
The syntax is:
xrn:<product>:<service>:<region>:<scope>:<resourceType>[/<resourceId>]The square brackets mean the /resourceId part is optional. Don't include the
brackets in an actual XRN. Colons separate the main parts; a slash separates the
resource type from its ID.
Break down this example:
xrn:saas:billing:us-west-1:ws-acme-prod:invoice/inv-123| Part | Example | Meaning |
|---|---|---|
| Prefix | xrn | Identifies the string as an XRN. |
| Product | saas | The product namespace. Use your app's product name consistently in rules and checks; saas is an example value. |
| Service | billing | The service responsible for this kind of resource. |
| Region | us-west-1 | The region associated with the resource. |
| Scope | ws-acme-prod | The business boundary the resource belongs to, such as a workspace or organization. This is an example scope ID, not an AWS account ID. |
| Resource type | invoice | The kind of thing your app is protecting. |
| Resource ID | inv-123 | One particular invoice within that context. |
The XRN names the resource. The action, such as read, approve or delete,
is a separate part of a permission check. Naming an invoice doesn't grant access
to it; your backend still needs to check the caller's permission.
Examples you can adapt
| XRN | What it identifies |
|---|---|
xrn:saas:billing:us-west-1:ws-acme-prod:invoice/inv-123 | Invoice inv-123 in Acme's billing scope. |
xrn:saas:billing:us-west-1:ws-acme-prod:invoice/inv-456 | A different invoice in the same scope. |
xrn:saas:billing:us-west-1:ws-beta-prod:invoice/inv-123 | An invoice with the same ID in a different scope. It is a different resource. |
xrn:saas:devices:us-west-1:ws-acme-prod:device/dev-7 | Device dev-7, addressed through the devices service. |
Choose names that match your application's resource model, and use those same names in its permission rules and checks. The invoice or device record still lives in your application's datastore.
A resource type versus a particular resource
Leave off the ID when checking an action on the resource type, such as creating an invoice or listing invoices:
xrn:saas:billing:us-west-1:ws-acme-prod:invoiceInclude the ID when checking access to an existing invoice:
xrn:saas:billing:us-west-1:ws-acme-prod:invoice/inv-123In a check, omitting the ID means you're asking about the resource type. In a
rule, however, both invoice and invoice/* leave the ID unrestricted: they can
match type-level and instance checks. A rule naming a particular ID or ID prefix,
such as invoice/inv-123 or invoice/inv-*, needs a matching ID in the check.
Use the action to distinguish operations such as create, list and read.
Wildcard patterns in rules
A permission rule can use * to match a whole segment, or a trailing * to
match a prefix. For example:
xrn:saas:billing:us-west-1:ws-acme-prod:invoice/*
xrn:saas:billing:us-west-1:ws-acme-prod:invoice/inv-*The first pattern matches any invoice ID in that scope, and also a type-level
invoice check. The second requires an ID starting with inv-, so it doesn't
match a type-level check. These are resource patterns; the rule also needs an
action and an allow or deny effect.
For a permission check, send the actual resource you're asking about. Don't use
a wildcard to ask for access to every resource or every team. A legacy * in a
request's region or scope is treated as unset and filled from the request or
deployment context; it doesn't mean “all regions” or “all scopes.”
IDs and scopes containing special characters
An XRN needs exactly five colon-separated parts after xrn:. If a scope or
resource ID contains :, / or %, encode those characters inside that value:
| Character inside a scope or ID | XRN encoding |
|---|---|
: | %3A |
/ | %2F |
% | %25 |
For example, scope project:org_acme:proj_1 and document ID folder/report become:
xrn:saas:files:us-west-1:project%3Aorg_acme%3Aproj_1:document/folder%2FreportThe parser decodes them back to the original values. Product, service, region
and resource-type names cannot contain :, / or %.
If you use buildXrn from @saaslayer/permissions/server, pass the original
scope and ID values and let the helper encode them; don't pre-encode them.
Its tenantId option carries the scope, and resource carries the resource type:
import { buildXrn } from '@saaslayer/permissions/server'
const resource = buildXrn({
product: 'saas',
service: 'files',
region: 'us-west-1',
tenantId: 'project:org_acme:proj_1',
resource: 'document',
resourceId: 'folder/report',
})
// xrn:saas:files:us-west-1:project%3Aorg_acme%3Aproj_1:document/folder%2FreportSee resource naming in permission checks and typed scopes for the related check and scope rules.
Actions
Actions are verbs in your product domain:
read
write
delete
approve
export
inviteUse stable product actions instead of HTTP verbs. For example, approve is clearer than POST.
Scopes
A scope limits where a permission applies.
Common scopes:
- Workspace ID
- Organization ID
- Group ID
- Global: no scope restriction on an assignment
When a permission check includes a scope, SaaSLayer Permissions evaluates global permissions plus permissions scoped to that value.
The API represents a global assignment with "scope": null; conceptual docs
call this Global. A check without a scope evaluates global permissions only,
not every workspace's scoped permissions. See Global in the API
for assignment examples.
Denies
Deny rules override allows. If one matching permission says deny, access is denied even if another matching permission says can.
Use denies sparingly. They are useful for hard restrictions, compliance boundaries, and inherited roles where a child role must explicitly block a parent capability.
Permission boundaries
A permission boundary is a maximum-access ceiling. A role or principal might allow an action, but the boundary can still block it.
Use boundaries for administrative guardrails:
- Support users can read customer data but cannot delete it.
- Contractors can manage tickets but cannot export data.
- Service accounts can write events but cannot manage users.
Grants
Grants are direct resource shares. They are useful when role-based access does not naturally express a one-off share.
Example: a user does not have read on every document in a workspace, but someone shares document/doc-123 directly with them.
A grant names the grantee's type and id, the action, and the resource's scope, service, type and id — all required
except scope, which defaults to * (global). A grant answers only checks in its own service and scope, and a global
grant answers only checks with no scope. The caller must be allowed in the grant's scope and hold the permission it
grants. A grant is consulted only when no role or policy allowed or denied the check.
API keys
An API key gives a person or integration a credential for programmatic access. It belongs to a principal and can carry a limited set of allowed actions and a workspace boundary, plus an expiration date.
For example, a reporting integration could read documents in one workspace without being able to change them or access another workspace. Your backend checks the key itself before serving the request.
API key management is part of Permissions and can be used with your existing sign-in provider. See API keys for creation, verification, rotation and revocation.
Materialized permission documents
SaaSLayer prepares each principal’s effective permissions from their roles and policies so checks can read the combined result efficiently. You ask for an access decision rather than combining all the rules in your application.
Changes to roles and policies refresh that permission data. See permission checks for integration and decision behavior.
Sessions
Three session shapes coexist:
| Kind | Subject acts as | When to use |
|---|---|---|
| Assumed-role session | A different role for a bounded window. | Support engineer temporarily assumes a customer-support role. |
| Direct principal session | The subject itself. | Workload authenticates via federated principal auth and acts as itself. |
| Delegated principal session | The subject, but actingFor another principal. | Agent acts on a user's behalf via agent delegation. |
All three use sess_<jwt> bearer tokens with bounded lifetimes. Send the complete
token when calling the API, and revoke sessions through the supported session API.