This document provides a detailed technical overview of Dify's Role-Based Access Control (RBAC) system. The RBAC system governs user permissions and access within multi-tenant workspaces, defining a hierarchy of roles through the TenantAccountRole enum. It supports five roles: OWNER, ADMIN, EDITOR, NORMAL, and DATASET_OPERATOR.
The system integrates tightly with an enterprise-grade RBAC service to allow fine-grained resource permission checks. This page explains role definitions, the tenant-account role association model, enterprise RBAC integration, permission validation wrappers, and summarizes the permission matrix applied across the platform.
For related details on tenant modeling, authentication, and workspace management, see:
Dify defines workspace roles via the TenantAccountRole enum in api/models/account.py. Roles express increasing levels of privilege and scope:
Role-checking utilities are statically defined on the TenantAccountRole class, supporting role validation such as:
is_valid_role(role: str) -> boolis_privileged_role(role: Optional[TenantAccountRole]) -> boolis_admin_role(role: Optional[TenantAccountRole]) -> boolis_editing_role(role: Optional[TenantAccountRole]) -> boolis_dataset_edit_role(role: Optional[TenantAccountRole]) -> boolThese methods simplify permission gating throughout the codebase by classifying roles according to capability sets.
Sources: api/models/account.py21-79
The many-to-many relationship between users (Account) and tenants (Tenant) is managed via the TenantAccountJoin model, capturing the assigned role per user per tenant. This table is critical for mapping a user's workspace-specific role.
The Account model caches the current workspace and role for efficient permission checking and sets these via dedicated session-scoped methods. The tenant and role are lazy-loaded or refreshed from TenantAccountJoin entries.
Sources: api/models/account.py21-180 api/controllers/service_api/wraps.py29
Dify integrates an enterprise-tier RBAC system that supports fine-grained resource-level permission controls in addition to the coarse workspace roles.
The RBACService in api/services/enterprise/rbac_service.py serves as the API boundary for interacting with enterprise RBAC backends. It defines resource types such as:
RBACResourceType.APPRBACResourceType.DATASETThe service sends requests to internal enterprise APIs (/inner/api/rbac/*) for permission resolution.
Permissions are scoped by resource type and are enforced accordingly:
| Scope | Resource Type | Function |
|---|---|---|
APP | RBACResourceType.APP | Controls application lifecycle and configuration access. |
DATASET | RBACResourceType.DATASET | Controls dataset/document management. |
The system recognizes roles and permission keys via models such as RBACRole, AccessPolicy, and AccessPolicyRoleBinding.
Sources: api/services/enterprise/rbac_service.py44-154 api/controllers/console/wraps.py29-40
Dify enforces access control through decorators and wrappers applied to API endpoints, validating tokens, roles, and billing status.
The validate_app_token decorator verifies that incoming API requests are authenticated with a valid ApiToken. It confirms the associated app exists and is enabled for API access.
Sources: api/controllers/service_api/wraps.py105-116 api/controllers/service_api/wraps.py120-124
The decorator cloud_edition_billing_resource_check integrates RBAC with billing quota enforcement, blocking operations if the user exceeds subscription resource limits such as vector space or member seats.
The check supports multiple resource kinds and integrates with feature flags for granular control.
Sources: api/controllers/console/wraps.py187-202 api/services/billing_service.py207-217
| Operation | OWNER | ADMIN | EDITOR | NORMAL | DATASET_OPERATOR |
|---|---|---|---|---|---|
| App Management | ✅ | ✅ | ✅ | ❌ | ❌ |
| - Create App | ✅ | ✅ | ✅ | ❌ | ❌ |
| - Edit App | ✅ | ✅ | ✅ | ❌ | ❌ |
| Dataset Management | ✅ | ✅ | ✅ | ❌ | ✅ |
| - Create Dataset | ✅ | ✅ | ✅ | ❌ | ✅ |
| - Edit Dataset | ✅ | ✅ | ✅ | ❌ | ✅ |
| Workspace Management | |||||
| - Member Management | ✅ | ✅ | ❌ | ❌ | ❌ |
| - RBAC Configuration | ✅ | ✅ | ❌ | ❌ | ❌ |
This matrix summarizes role capabilities with respect to key platform resources.
Sources: api/models/account.py21-79 api/controllers/console/app/app.py33-36 api/services/enterprise/rbac_service.py16
Dify's Role-Based Access Control system is a layered permission framework that distinguishes user capabilities within a tenant by the TenantAccountRole roles. This system is backed by a many-to-many association table and extended for precision via an enterprise RBAC service that enables resource-level permission policies. The RBAC enforcement is implemented through a combination of static role checks and dynamic enterprise permission queries via internal APIs, guarded by validation decorators that secure both Console and Service API endpoints. Integration with billing further guards against quota violations in resource use.
Sources:
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.