SpiceDB Component
Overview
The SpiceDB component in Gitpod provides authorization and permission management using the SpiceDB authorization system. It defines the relationship-based access control (ReBAC) schema that governs permissions across the Gitpod platform, enabling fine-grained access control for users, organizations, projects, workspaces, and other resources.
Purpose
The primary purposes of the SpiceDB component are:
Define the authorization schema for Gitpod
Model relationships between entities (users, organizations, projects, workspaces)
Specify permissions based on these relationships
Provide a consistent authorization system across the platform
Enable fine-grained access control
Support complex permission scenarios
Facilitate permission checks in other components
Ensure secure access to resources
Architecture
The SpiceDB component consists of:
Schema Definition: YAML-based schema that defines entities, relationships, and permissions
Go Library: Code for loading and managing the schema
TypeScript Bindings: Generated TypeScript code for frontend components
Validation: Tests and assertions to verify schema correctness
Integration: Connection to the SpiceDB service for permission checks
The component follows the SpiceDB authorization model, which is based on the Google Zanzibar paper. It uses a relationship-based approach where permissions are derived from relationships between entities.
Key Entities and Relationships
Entities
User: Individual users of the Gitpod platform
Installation: The global Gitpod installation
Organization: Groups of users with shared resources
Project: Repositories or codebases within an organization
Workspace: Development environments for projects
Relationships
User-Installation: Users can be members or admins of the installation
User-Organization: Users can be members, owners, or collaborators of organizations
Organization-Installation: Organizations belong to an installation
Project-Organization: Projects belong to organizations
Project-User: Users can be viewers or editors of projects
Workspace-Organization: Workspaces belong to organizations
Workspace-User: Users can own or share workspaces
Permissions
The schema defines various permissions for each entity type:
User Permissions
read_info
: View user informationwrite_info
: Edit user informationdelete
: Delete user accountmake_admin
: Make a user an adminadmin_control
: Administrative control over usersread_ssh
: View SSH keyswrite_ssh
: Manage SSH keysread_tokens
: View access tokenswrite_tokens
: Manage access tokensread_env_var
: View environment variableswrite_env_var
: Manage environment variableswrite_temporary_token
: Create temporary tokenscode_sync
: Synchronize code
Organization Permissions
read_info
: View organization informationwrite_info
: Edit organization informationdelete
: Delete organizationread_settings
: View organization settingswrite_settings
: Edit organization settingsread_env_var
: View organization environment variableswrite_env_var
: Manage organization environment variablesread_audit_logs
: View audit logsread_members
: View organization membersinvite_members
: Invite new memberswrite_members
: Manage organization membersleave
: Leave the organizationcreate_project
: Create new projectsread_git_provider
: View Git provider informationwrite_git_provider
: Manage Git provider settingsread_billing
: View billing informationwrite_billing
: Manage billing settingsread_prebuild
: View prebuildscreate_workspace
: Create workspacesread_sessions
: View user sessionswrite_billing_admin
: Administrative billing control
Project Permissions
read_info
: View project informationwrite_info
: Edit project informationdelete
: Delete projectread_env_var
: View project environment variableswrite_env_var
: Manage project environment variablesread_prebuild
: View project prebuildswrite_prebuild
: Manage project prebuilds
Workspace Permissions
access
: Access the workspacestart
: Start the workspacestop
: Stop the workspacedelete
: Delete the workspaceread_info
: View workspace informationcreate_snapshot
: Create workspace snapshotsadmin_control
: Administrative control over workspaces
Configuration
The SpiceDB component's core configuration is its schema, defined in components/spicedb/schema/schema.yaml
. This YAML file is central to Gitpod's authorization model and specifies:
Object Definitions: The types of resources being protected (e.g.,
user
,organization
,project
,workspace
).Relations: How different objects can be related to each other (e.g., an
organization
has anowner
which is auser
; aproject
belongs to anorg
).Permissions: What actions can be performed on objects, and how these permissions are derived from relations (e.g.,
permission write_settings = owner + installation->admin
for anorganization
).Validation & Assertions: Rules and tests to ensure the schema's integrity and correctness.
New permissions (like the maintenance
permission for organizations) are added by modifying this schema file. Other components, such as the server
component, then use a SpiceDB client to check these permissions at runtime to authorize operations.
Integration Points
The SpiceDB component integrates with:
Server: For permission checks on API requests
Dashboard: For UI permission enforcement
Public API: For permission checks on API requests
Workspace Manager: For workspace access control
SpiceDB Service: The actual authorization service that evaluates permission checks
Usage Patterns
Permission Checking
Relationship Management
Security Considerations
The component implements several security measures:
Least Privilege: Permissions follow the principle of least privilege
Defense in Depth: Multiple layers of permission checks
Separation of Concerns: Clear separation between different entity types
Validation: Schema validation to ensure correctness
Assertions: Tests to verify expected permission behavior
Dependencies
Internal Dependencies
None specified in the component's build configuration.
External Dependencies
SpiceDB service for authorization checks
YAML parsing libraries
Code generation tools
Related Components
Server: Uses SpiceDB for API permission checks
Dashboard: Uses SpiceDB for UI permission enforcement
Public API: Uses SpiceDB for API permission checks
Workspace Manager: Uses SpiceDB for workspace access control