Warden
1.x
Docs/Warden/Roles & Permissions
Open

Reading6 min
Updated31 Jul 2026
Sourcev1/authorization/roles-permissions.mdx

Every config example on this page comes in two flavours: Go (programmatic — call the store directly) and DSL (declarative — write .warden source and apply it via warden apply or dsl.ApplyFS). They produce identical state.

Roles01

A role is a named collection of permissions that can be assigned to subjects.

Role Fields

FieldTypeDescription
IDid.RoleIDTypeID (role_...) — auto-assigned on Create when unset
NamestringDisplay name
SlugstringURL-safe identifier (unique per tenant)
DescriptionstringHuman-readable description
ParentSlugstringParent role slug for inheritance — empty means no parent
IsSystemboolSystem roles cannot be deleted
IsDefaultboolAuto-assigned to new subjects
MaxMembersintMaximum assignments (0 = unlimited)
Metadatamap[string]anyCustom key-value data

Create a Role

go
// IDs and CreatedAt/UpdatedAt timestamps are auto-assigned by the
// store on Create — set them only when you need a specific value
// (idempotent inserts, fixtures, etc.).
r := &role.Role{
    Name:        "Editor",
    Slug:        "editor",
    Description: "Can read and write documents",
}
err := store.CreateRole(ctx, r)
// r.ID is now populated.

Role Hierarchy

Roles can inherit permissions from parent roles via slug:

go
admin  := &role.Role{Name: "Admin",  Slug: "admin"}
editor := &role.Role{Name: "Editor", Slug: "editor", ParentSlug: "admin"}
viewer := &role.Role{Name: "Viewer", Slug: "viewer", ParentSlug: "editor"}

When checking permissions, Warden walks up the role hierarchy to collect all inherited permissions.

Permissions02

A permission represents a single (resource, action) authorization grant.

Permission Fields

FieldTypeDescription
IDid.PermissionIDTypeID (perm_...) — auto-assigned on Create when unset
Namestring<resource>:<action> natural key
ResourcestringResource type (e.g., "document")
ActionstringAction verb (e.g., "read", "write")
DescriptionstringHuman-readable description
IsSystemboolSystem permissions cannot be deleted
Metadatamap[string]anyCustom key-value data

Create a Permission

go
p := &permission.Permission{
    Name:     "doc:read",
    Resource: "document",
    Action:   "read",
}
err := store.CreatePermission(ctx, p)

Attach to Role

go
err := store.AttachPermission(ctx, roleID, permission.Ref{Name: "doc:read"})

Glob Matching

Permission matching supports wildcards:

PatternMatches
document:readExactly document:read
document:*document:read, document:write, document:delete
*:readdocument:read, user:read, project:read
*:*Everything

Assignments03

An assignment links a subject (user, API key, service) to a role.

Runtime-only. Assignments are not expressible in .warden source — that file describes the configuration (roles, permissions, policies, resource types, relations) but not the runtime data of who has which role. Assignments are created via the store API or HTTP endpoints when subjects are provisioned.

Assignment Fields

FieldTypeDescription
IDid.AssignmentIDTypeID (asgn_...) — auto-assigned on Create when unset
RoleIDid.RoleIDThe role to assign
SubjectKindstringSubject type ("user", "api_key", "service")
SubjectIDstringSubject identifier
ResourceTypestringOptional: scope to resource type
ResourceIDstringOptional: scope to specific resource
ExpiresAt*time.TimeOptional: auto-expire assignment

Global Assignment

// User is an editor everywhere
ass := &assignment.Assignment{
    RoleID:      editorRole.ID,
    SubjectKind: "user",
    SubjectID:   "user-42",
}
_ = store.CreateAssignment(ctx, ass)

Resource-Scoped Assignment

// User is an editor only for project-123
ass := &assignment.Assignment{
    RoleID:       editorRole.ID,
    SubjectKind:  "user",
    SubjectID:    "user-42",
    ResourceType: "project",
    ResourceID:   "project-123",
}

Time-Limited Assignment

expires := time.Now().Add(24 * time.Hour)
ass := &assignment.Assignment{
    RoleID:      adminRole.ID,
    SubjectKind: "user",
    SubjectID:   "user-42",
    ExpiresAt:   &expires,
}

Listing04

// List roles for a subject
roles, _ := store.ListRolesForSubject(ctx, "", "user", "user-42")

// List assignments with filters
assignments, _ := store.ListAssignments(ctx, &assignment.ListFilter{
    SubjectKind: "user",
    SubjectID:   "user-42",
    Limit:       50,
})

// List permissions for a role
perms, _ := store.ListRolePermissions(ctx, roleID)