Skip to content

Resources

A resource is a named entity that declares which actions can be performed on it. Resources are the foundation of Grant's permission model — every permission is a (resource, action) pair, optionally scoped with conditions.

How It Fits Together

  1. A resource declares its allowed actions (e.g. ApiKey allows Create, Revoke, Exchange)
  2. A permission binds a resource + action, optionally with a condition (e.g. "only keys you created")
  3. Permissions are bundled into groups, groups into roles, and roles are assigned to users

TIP

Resources are always scoped to a project. Each project can have the platform defaults plus any custom resources you define.

Built-in Resources

Grant ships with 16 platform resources. These are seeded automatically and cover the core domain:

ResourceActions
UserCreate Read Update Delete Query ExportData UploadPicture
AccountRead Delete Query
OrganizationCreate Read Update Delete Query
ProjectCreate Update Delete Query
ProjectAppCreate Update Delete Query
ResourceCreate Update Delete Query
RoleCreate Update Delete Query
GroupCreate Update Delete Query
PermissionCreate Update Delete Query
TagCreate Update Delete Query
ApiKeyCreate Delete Query Revoke Exchange
OrganizationMemberRead Update Remove Query
OrganizationInvitationCreate Read Query Revoke ResendEmail Renew
ProjectUserRead Query
UserSessionRead Query
UserAuthenticationMethodRead Query

The canonical source is packages/@grantjs/constants/src/permissions/resources.ts.

Available Actions

Actions are shared across resources — each resource picks the subset it supports:

ActionMeaning
CreateCreate a new instance
ReadRead a single instance
UpdateModify an existing instance
DeleteSoft- or hard-delete
QueryList / paginate / search
ExportDataExport user data (GDPR)
UploadPictureUpload a profile image
RemoveRemove a membership (e.g. org member)
RevokeRevoke an active entity (API key, invitation)
ResendEmailResend an invitation email
RenewRenew an expired invitation token
ExchangeExchange API key credentials for a JWT

Conditional Permissions

Permissions can include conditions that restrict access beyond the action itself. Conditions compare a field on the request context against a known value using operators like StringEquals or In.

Example — an ApiKeyOwner group might grant Delete on the ApiKey resource only when resource.createdBy equals the requesting user:

json
{
  "StringEquals": {
    "resource.createdBy": "{{user.id}}"
  }
}

This is how Grant implements attribute-based rules within the RBAC model — no separate ABAC engine required. See Permission Conditions for full syntax reference.

Custom Resources

Projects can define their own resources with custom actions via the GraphQL createResource mutation or the REST API. Custom resources participate in the same RBAC chain as built-in ones: you create the resource, create permissions for it, bundle them into groups, and assign groups to roles.

This is the primary extension point for integrating Grant's permission system with your application's domain.


Related:

Released under the MIT License.