Warden
1.x
Docs/Warden/Resource Types
Open

Reading6 min
Updated31 Jul 2026
Sourcev1/authorization/resource-types.mdx

Overview01

Resource types define the schema for your authorization model. They declare which relations and permissions are valid for each type of object.

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.

ResourceType Fields

FieldTypeDescription
IDid.ResourceTypeIDTypeID (rtype_...) — auto-assigned on Create when unset
NamestringResource type name (e.g., "document")
DescriptionstringHuman-readable description
Relations[]RelationDefValid relations for this type
Permissions[]PermissionDefDerived permission expressions

Defining Relations02

go
import "github.com/xraph/warden/resourcetype"

// IDs and CreatedAt/UpdatedAt timestamps are auto-assigned by the
// store on Create — set them only when you need a specific value.
docType := &resourcetype.ResourceType{
    Name:        "document",
    Description: "A document resource",
    Relations: []resourcetype.RelationDef{
        {Name: "owner",  AllowedSubjects: []string{"user"}},
        {Name: "editor", AllowedSubjects: []string{"user", "team#member"}},
        {Name: "viewer", AllowedSubjects: []string{"user", "team#member", "group#member"}},
        {Name: "parent", AllowedSubjects: []string{"folder"}},
    },
    Permissions: []resourcetype.PermissionDef{
        {Name: "read",   Expression: "viewer or editor or owner or parent->read"},
        {Name: "write",  Expression: "editor or owner or parent->write"},
        {Name: "delete", Expression: "owner"},
    },
}
err := store.CreateResourceType(ctx, docType)
// docType.ID is now populated.

RelationDef03

FieldTypeDescription
NamestringRelation name (e.g., "viewer")
AllowedSubjects[]stringAllowed subject types — bare types (user) or subject sets (group#member)

PermissionDef04

FieldTypeDescription
NamestringPermission name (e.g., "read")
ExpressionstringBoolean expression over relations (e.g., "viewer or editor or owner")

Example: Google Drive-like Model05

go
// Folder type
folderType := &resourcetype.ResourceType{
    Name: "folder",
    Relations: []resourcetype.RelationDef{
        {Name: "owner",  AllowedSubjects: []string{"user"}},
        {Name: "editor", AllowedSubjects: []string{"user", "group#member"}},
        {Name: "viewer", AllowedSubjects: []string{"user", "group#member"}},
    },
    Permissions: []resourcetype.PermissionDef{
        {Name: "read",  Expression: "viewer or editor or owner"},
        {Name: "write", Expression: "editor or owner"},
        {Name: "share", Expression: "owner"},
    },
}

// Document type — `parent->read` traverses the parent relation and
// re-checks read on the resulting folder.
docType := &resourcetype.ResourceType{
    Name: "document",
    Relations: []resourcetype.RelationDef{
        {Name: "owner",  AllowedSubjects: []string{"user"}},
        {Name: "editor", AllowedSubjects: []string{"user", "group#member"}},
        {Name: "viewer", AllowedSubjects: []string{"user", "group#member"}},
        {Name: "parent", AllowedSubjects: []string{"folder"}},
    },
    Permissions: []resourcetype.PermissionDef{
        {Name: "read",   Expression: "viewer or editor or owner or parent->read"},
        {Name: "write",  Expression: "editor or owner or parent->write"},
        {Name: "delete", Expression: "owner"},
    },
}

CRUD Operations06

These are runtime API calls — they don't have a DSL equivalent because the DSL is declarative (you describe the desired end state, not the operation). The applier picks the right CRUD call internally.

// Create
store.CreateResourceType(ctx, rt)

// Get by ID
rt, _ := store.GetResourceType(ctx, rtID)

// Get by name
rt, _ := store.GetResourceTypeByName(ctx, tenantID, "document")

// List
types, _ := store.ListResourceTypes(ctx, &resourcetype.ListFilter{
    TenantID: "t1",
    Limit:    50,
})

// Update
store.UpdateResourceType(ctx, rt)

// Delete
store.DeleteResourceType(ctx, rtID)