Welcome to Nebutra Sailor Docs šŸŽ‰
ChangelogIntroductionLicensing
Help Center (External) ↗

Permissions & RBAC

The @nebutra/permissions model — 6 default roles, CASL action/resource rules, and how to enforce them.

Overview

@nebutra/permissions wraps CASL for in-process RBAC/ABAC. It ships:

  • 6 default roles: owner, admin, member, viewer, billing_admin, guest
  • Action/resource rules, not a fixed scope-string list — { action: "delete", resource: "Project" }, with optional conditions (e.g. createdBy: "${user.userId}")
  • In-process enforcement via CASL (no network round-trip)
  • React UI gates via <Can> / <Cannot>

CASL is the only permissions backend — per ADR 2026-09-24 Sailor convergence, the OpenFGA (Zanzibar-style) adapter that used to be offered for graph-based authorization was deleted, and nothing replaces it. If you need cross-tenant sharing or graph-based access beyond what CASL's in-process rules express, write your own adapter against the @nebutra/permissions interface.

Default roles (packages/iam/permissions/src/roles.ts)

RoleDescription
ownerFull control — create/read/update/delete/manage/invite/publish/export/share across every default resource
adminInherits owner's rules, minus deleting the workspace; Billing is read/update only, read-scoped
memberCRUD on resources it created (conditions: { createdBy: "${user.userId}" }); read/update on resources shared with it; can invite
viewerRead-only, and only on resources marked public or explicitly shared with it
billing_adminInherits viewer; can create/read/update Billing, read Workspace
guestRead-only on resources explicitly shared with it AND flagged guestAccess: true

Roles can inherit from another role (admin inherits owner's rule set minus one override; member and billing_admin inherit viewer). This is a rule set per role, not a linear hierarchy of 4 tiers.

Default resources and actions

Actions: create, read, update, delete, manage, invite, publish, export, share (the Action type also accepts any string, so you can add your own).

Resources: Document, Project, Workspace, User, Billing, ApiKey, Team, Invite, Integration, AiProviderKey, Automation, Workflow (also extensible via string).

There is no fixed resource:action scope-string catalog (project:delete, api_key:create, …) — permission checks always take an (action, resource, subject?) triple.

Enforcing permissions

API Gateway (Hono middleware)

import { requirePermission } from "@nebutra/permissions";

// Returns 401 with no user context, 403 if the action/resource pair is denied
app.delete("/api/projects/:id", requirePermission("delete", "Project"), handler);

requirePermission(action, resource, options?) returns Hono middleware. options.extractSubject lets you pass the specific record (for conditions like createdBy) instead of just the resource type; options.onDenied lets you customize the 403 response.

Server Actions / manual checks

requirePermission is Hono middleware, not a standalone assertion — call the permissions manager directly outside a Hono context:

"use server";
import { getPermissions } from "@nebutra/permissions";

export async function deleteProject(projectId: string, user: PermissionContext) {
  const permissions = getPermissions();
  if (!permissions.can(user, "delete", "Project", { id: projectId })) {
    throw new Error("Forbidden");
  }
  // ...
}

React UI gates

import { Can, Cannot } from "@nebutra/permissions/react";

// Only renders children if the user can perform the action on the resource
<Can action="delete" resource="Project" subject={project}>
  <DeleteButton />
</Can>

// fallback renders instead, when denied
<Can action="update" resource="Billing" fallback={<UpgradePrompt />}>
  <BillingSettings />
</Can>

// Cannot is the inverse — renders when the check fails
<Cannot action="create" resource="Project">
  <ReadOnlyBanner />
</Cannot>

Both read from a <PermissionProvider> (exported as PermissionProviderComponent from @nebutra/permissions) wrapping your app, or use the usePermission(action, resource, subject?) hook directly for an imperative boolean.

Custom roles and resources

DEFAULT_ROLES in packages/iam/permissions/src/roles.ts is a plain object of RoleDefinitions (role, optional inherits, description, rules: PermissionRule[]). Add a role by adding an entry; add a resource or action by using any string — both types accept arbitrary strings alongside their named constants.

Related

Authentication

Session cookies and service-to-service tokens.

Multi-Tenancy

How tenant membership maps to roles.

How is this guide?

Edit on GitHub

Last updated on

On this page

Overview
Default roles (packages/iam/permissions/src/roles.ts)
Default resources and actions
Enforcing permissions
API Gateway (Hono middleware)
Server Actions / manual checks
React UI gates
Custom roles and resources
Related