Changelog - 2026-07-20
Casbin Custom Grants
New Feature EnhancementIn one line. A grant row can now express any subset of a subject's operations, not only a full tier, and planGrant composes the smallest correct set of rows for you.
What changed
- Custom grant mode. New
AuthorizationActions.CUSTOM('custom') andAuthorizationPolicyBuilder.customGrant(). A custom row carriesmetadata: { ops: [...] }against a subject-level resource node.opsholds method names, soops: ['find']on nodeOrdermeansOrder.find. planGrant(). The supported way to build an operations-subset grant. It uses a tier row wherever a tier is fully covered, then one custom row for the rest (or a per-operation row if only one operation is left). Passexact: trueto turn collapsing off.- New
metadatacolumn. A nullablemetadatajsonb column is added toextraPolicyDefinitionColumns. - Same result as per-operation rows.
ScopedCasbinAdapter.queryGrantsexpands a custom row into the same casbin lines that equivalent per-operation rows produce, at the cost of one extra batched catalog query per extraction.
typescript
const rows = planGrant({
subject: { type: 'Role', id: roleId },
resource: { type: 'Permission', id: orderResourceNodeId, subject: 'Order' },
intent: { ops: ['find', 'deleteById'] },
catalog, // [{ subject, method, code, action }, ...] resolved from your Permission table
});Who is affected
- Every consumer of
ScopedCasbinAdapterandAuthorizationPolicyBuilder. No action needed. Themetadatacolumn is nullable. - Apps that provision
PolicyDefinitionviaextraPolicyDefinitionColumns. Themetadatacolumn appears in your schema on the next migration. No backfill is required. - Apps that want to grant a few operations without a full tier. Call
planGrantinstead of writing acustomGrantrow by hand.
Details
- Reading a custom row is opt-in. Map
entities.policyDefinition.metadata.columnName, or the adapter never selectsmetadataand logs and skips any custom row it finds. managecollapses only when the selection covers at least one operation in each ofread,write, andexecute. Each narrower tier collapses on its own when fully covered.- When the target's
supportsCustomMetadataisfalse, every leftover operation becomes its own per-operation row. planGrantthrows on an unknown tier, an emptyops, or an operation missing from the resource's catalog slice. On read, a malformed custom row is only logged and skipped, so one bad row does not deny a user their other permissions.