Warden

Roles & Permissions

Managing roles, permissions, and role assignments for RBAC.

Roles

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

Role Fields

FieldTypeDescription
IDid.RoleIDTypeID (wrol_...)
NamestringDisplay name
SlugstringURL-safe identifier (unique)
DescriptionstringHuman-readable description
ParentID*id.RoleIDParent role for inheritance
IsSystemboolSystem roles cannot be deleted
IsDefaultboolAuto-assigned to new subjects
MaxMembersintMaximum assignments (0 = unlimited)
Metadatamap[string]anyCustom key-value data

Create a Role

r := &role.Role{
    ID:          id.NewRoleID(),
    Name:        "Editor",
    Slug:        "editor",
    Description: "Can read and write documents",
    CreatedAt:   time.Now(),
    UpdatedAt:   time.Now(),
}
err := store.CreateRole(ctx, r)

Role Hierarchy

Roles can inherit permissions from parent roles:

admin := &role.Role{ID: id.NewRoleID(), Name: "Admin", Slug: "admin"}
editor := &role.Role{ID: id.NewRoleID(), Name: "Editor", Slug: "editor", ParentID: &admin.ID}
viewer := &role.Role{ID: id.NewRoleID(), Name: "Viewer", Slug: "viewer", ParentID: &editor.ID}

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

Permissions

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

Permission Fields

FieldTypeDescription
IDid.PermissionIDTypeID (wprm_...)
NamestringDisplay name
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

p := &permission.Permission{
    ID:       id.NewPermissionID(),
    Name:     "Read Documents",
    Resource: "document",
    Action:   "read",
}
err := store.CreatePermission(ctx, p)

Attach to Role

err := store.AttachPermission(ctx, roleID, permID)

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

Assignments

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

Assignment Fields

FieldTypeDescription
IDid.AssignmentIDTypeID (wasn_...)
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{
    ID:          id.NewAssignmentID(),
    RoleID:      editorRole.ID,
    SubjectKind: "user",
    SubjectID:   "user-42",
}

Resource-Scoped Assignment

// User is an editor only for project-123
ass := &assignment.Assignment{
    ID:           id.NewAssignmentID(),
    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{
    ID:          id.NewAssignmentID(),
    RoleID:      adminRole.ID,
    SubjectKind: "user",
    SubjectID:   "user-42",
    ExpiresAt:   &expires,
}

Listing

// 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.ListPermissionsForRole(ctx, roleID)

On this page