User Management, Roles, and Permissions
Relevant source files
The following files were used as context for generating this wiki page:
- packages/backend-core/src/security/roles.ts
- packages/backend-core/src/security/permissions.ts
- packages/server/src/api/controllers/public/users.ts
- packages/worker/src/api/routes/global/tests/roles.spec.ts
- packages/server/src/api/routes/tests/user.spec.ts
- packages/builder/src/pages/builder/admin/index.svelte
- packages/types/src/documents/global/userGroup.ts
Budibase employs a robust Role-Based Access Control (RBAC) system to manage user permissions and secure applications. This system allows for global management of users, groups, and roles, providing granular control over access to different parts of the platform and the applications built with it. Administrators can define custom roles, assign them to users or groups, and manage access levels for specific applications.
The core components of this system are Users, Roles, and Permissions. Users are assigned Roles, and Roles are defined by a set of Permissions. This structure allows for flexible and scalable security configurations, from simple public-facing apps to complex internal tools with multiple user levels.
User Management
User management in Budibase covers the entire lifecycle of a user account, from the initial creation of an admin user to the ongoing management of application users via a public API.
Admin User Creation
The first user created in a new Budibase installation is the super admin. This user has the highest level of access across the entire instance. The creation process is handled through a dedicated setup page.
The user provides an email and password, which must meet a minimum length requirement (defaulting to 12 characters). Upon successful creation, the user is automatically logged in and redirected to the workspaces dashboard.
Sources: packages/builder/src/pages/builder/admin/index.svelte:14-34, packages/builder/src/pages/builder/admin/index.svelte:81-87
Public API for Users
Budibase exposes a public API for managing global users. These endpoints allow for programmatic creation, retrieval, updating, and deletion of users.
| Method | Endpoint | Description |
|---|---|---|
POST | /api/public/v1/users | Creates a new global user. |
GET | /api/public/v1/users/:userId | Retrieves a specific user's details. |
PUT | /api/public/v1/users/:userId | Updates an existing user. Requires the user's _rev for subsequent updates. |
DELETE | /api/public/v1/users/:userId | Deletes a user. A user cannot be deleted using their own API key. |
POST | /api/public/v1/users/search | Searches for users by email. |
Sources: packages/server/src/api/controllers/public/users.ts
User Creation and Update Flow
The create and update endpoints share a common response function. When creating or updating a user, the system performs a role check via sdk.publicApi.users.roleCheck. For customers on plans other than business/enterprise, any provided role, admin, or builder properties are ignored, and a message is returned to the user indicating this.
The diagram below shows the sequence for creating a new user via the public API.
This diagram illustrates the user creation process through the public API.
Sources: packages/server/src/api/controllers/public/users.ts:28-40, packages/server/src/api/controllers/public/users.ts:71-74
User Deletion
A user can be deleted via the DELETE endpoint. A critical security check prevents a user from deleting themselves by comparing the logged-in user's ID with the ID of the user to be deleted.
This diagram shows the logic for deleting a user, including the self-deletion check.
Sources: packages/server/src/api/controllers/public/users.ts:91-98
User Flags
The system provides a mechanism to set and retrieve arbitrary flags on a user's record. This is useful for storing miscellaneous metadata.
- Set Flag:
POST /api/users/flagswith a body{ "flag": "flagName", "value": "flagValue" }. - Get Flags:
GET /api/users/flagsretrieves all flags for the currently authenticated user.
Sources: packages/server/src/api/routes/tests/user.spec.ts:110-136
Roles
Roles are the cornerstone of the permission system, defining what a user is allowed to do. Budibase includes several built-in roles and supports the creation of custom roles.
Built-in Roles
Budibase comes with a set of predefined roles, each with a specific level of access.
| Role ID | Description |
|---|---|
ADMIN | Administrative access with full permissions. |
POWER | Power user access, typically for creating and managing apps. This role is conditionally available. |
BASIC | Basic user access, often for interacting with published apps. |
PUBLIC | Access level for unauthenticated users. |
Sources: packages/worker/src/api/routes/global/tests/roles.spec.ts:100-106, [packages/server/src/api/routes/tests/user.spec.ts:60-63]
Role Filtering by Version
The POWER role is considered a legacy role and is only included in API responses for applications created before version 3.0.0. For newer applications, this role is filtered out to simplify the permission model. This logic is checked against the creationVersion property in the app's metadata.
Sources: [packages/worker/src/api/routes/global/tests/roles.spec.ts:74-118]
Custom Roles
In addition to built-in roles, developers can create custom roles. A custom role is defined by a name and is associated with a permissionId, which links it to a specific set of permissions.
A role is represented by the Role class, which takes an ID, name, permission ID, and optional metadata.
Sources: [packages/worker/src/api/routes/global/tests/roles.spec.ts:40-45]
Role Management API
The system provides endpoints for managing roles within an application context.
GET /api/global/roles: Retrieves all roles for all apps the user has access to.GET /api/global/roles/:appId: Retrieves roles for a specific app.DELETE /api/global/roles/:appId: Removes an app-specific role from all users who have it. This is accessible to Admin and Builder users who own the workspace.
Sources: [packages/worker/src/api/routes/global/tests/roles.spec.ts:68-167]
Permissions
Permissions define the specific actions that can be performed. They are grouped together and assigned to roles.
Built-in Permissions
Budibase defines a set of built-in permission levels that can be assigned to roles.
| Permission ID | Description |
|---|---|
READ_ONLY | Allows read-only access to resources. |
WRITE_ONLY | Allows write-only access to resources. |
READ_WRITE | Allows both read and write access. |
ADMIN | Grants full administrative permissions over resources. |
The BuiltinPermissionID enum is used to reference these permission levels when creating roles. For example, a new custom role can be created with READ_ONLY permissions.
Sources: packages/worker/src/api/routes/global/tests/roles.spec.ts:42
Relationship Diagram
The relationship between users, roles, and permissions forms a clear hierarchy for access control.
This diagram shows how Users, User Groups, Roles, and Permissions are related in Budibase's RBAC model.