Database governance built for humans and agents — controlling changes and access across every major database.
SaaS Migration Progress
Current status of the workspace isolation implementation. 185+ files changed, ~4700 lines modified.
Completed
Database Migration
-
server_configtable — Global config (single row), storesauth_secretviapayloadJSONB -
workspacetable — Workspace identity withresource_idPK -
workspacecolumn added to 13 root tables +oauth2_client - Workspace-scoped unique indexes for tables with non-globally-unique PKs
-
oauth2_authorization_code/oauth2_refresh_token— No workspace column (scoped throughclient_idFK) - Auth secret migrated from
SystemSettingJSON toserver_config.payload -
SystemSettingproto —auth_secretandworkspace_idfields reserved - LATEST.sql —
plan,task,task_run,plan_check_run,issuechanged fromserialtobigint NOT NULL - LATEST.sql —
worksheet.idcolumn dropped (PK isresource_id) - LATEST.sql — Audit log composite index
(workspace, created_at DESC)replaces separate indexes - LATEST.sql — Seed data: only
server_config(workspace created by Go signup flow) - Migration 0006 — Drops worksheet
idcolumn (fixes "null value in column id" error) - Migration 0009 — Composite audit log index created
Store Layer
- All root tables enforce workspace on CRUD (INSERT, SELECT, UPDATE, DELETE)
-
workspace.go:GetWorkspaceID()returns("", nil)when no workspace exists,ListWorkspacesByEmail(),FindWorkspace(),CreateWorkspace()with proto-based settings/policy -
runner_queries.go: Cross-workspace methods (GetProjectByResourceID,GetInstanceByResourceID,ListAllInstances,DeleteExpiredExportArchivesAll) -
account.go:AccountMessage+GetAccountByEmail()for auth layer -
GetServerConfig()/GetAuthSecret()— reads fromserver_configtable -
CountActiveEndUsersPerWorkspace— counts via IAM policy membership (explicit members only, notallUsers) -
CountAllActivePrincipals— counts all principals globally (forallUsersadmin check) -
GetDefaultProjectID(ctx, workspace)— checks new format first, falls back to legacy"default" -
BatchGetUsersByEmails— workspace-scoped via IAM join - Cache fixes —
settingCache,groupCache,groupMembersCache,memberGroupsCacheall include workspace in keys.UpdatePolicysetsWorkspaceon cached entry.DeletePolicyinvalidatesiamPolicyCache.UpdateUserReferenceInPoliciesinvalidatesiamPolicyCacheand purges group caches. -
SearchAuditLogs— workspace filter is optional (empty = cross-workspace for login lockout)
Auth & Token Flow
- Workspace in JWT claims (
WorkspaceIDfield) - Auth middleware injects workspace into context, verifies membership
- Login workspace resolution via
ListWorkspacesByEmail(IAM policy). Workspace resolved early in Login flow, passed as parameter (not via context). -
SignupAPI (POST /v1/auth/signup,allow_without_credential) — Creates principal + workspace. Self-hosted: joins existing workspace or creates if none exists. SaaS: creates new workspace per user. -
CreateUserrefactored — Admin-only (bb.users.createpermission), self-hosted only. SaaS blocked. - Login lockout —
countRecentLoginFailuressearches audit logs cross-workspace (per-email rate limit) - IDP (SSO) login — resolves workspace from
idp.Workspace, passes workspace explicitly (no context injection) - ExchangeToken — uses
GetWorkloadIdentityByEmail(cross-workspace) andwi.Workspace - All
allow_without_credentialAPIs audited — noGetWorkspaceIDFromContextin unauthenticated paths
API Layer
- All auth_service functions accept
workspaceIDas parameter (not from context):validateLoginPermissions,checkMFARequired,needResetPassword,isUserWorkspaceAdmin,validateEmailWithDomains,syncUserGroups,generateLoginToken -
UpdateUser— SaaS: self-updates only. Self-hosted: admin can update others. -
DeleteUser/UndeleteUser/UpdateEmail— SaaS: blocked. -
GetUser/BatchGetUsers— workspace-scoped via IAM join -
SetIamPolicy— blocksallUsersin SaaS. No member count check (enforced at CreateUser/IDP level). -
ListIdentityProviders— self-hosted falls back tostore.GetWorkspaceIDfor unauthenticated login page -
GetSubscription— falls back to free subscription if no workspace context - ACL simplified — removed
rawResourcestruct,getResourceFromRequestreturns[]string - Default project —
CreateProjectblocks"default"and"default-*"project IDs as reserved.IsDefaultProjecthandles both legacy and new formats. -
userCountGuard— uses explicitworkspaceIDparameter
Background Runners
- Runners use cross-workspace store methods
- Workspace resolved from loaded entities
-
CheckReplicaLimitskips in SaaS mode - Schema sync —
CreateDatabaseDefaultusesGetDefaultProjectID(handles legacy)
OAuth2
-
oauth2_clientworkspace-scoped - Workspace-scoped URLs:
/api/workspaces/:workspaceID/oauth2/... - Legacy routes preserved for self-hosted (
!profile.SaaS)
Infrastructure
- Server startup — No workspace dependency. Loads settings if workspace exists, skips on first boot.
-
server_config— Onlyauth_secret(JSONB payload) - Self-hosted features guarded by
!profile.SaaS -
DisallowSignupoverride removed — SaaS no longer forces it true (signup always allowed) - Per-workspace licensing —
LoadSubscription,StoreLicense,GetUserLimit,GetActivatedInstanceLimitall workspace-scoped with workspace in cache key
Frontend
-
isDefaultProject— reads fromuseActuatorV1Store().serverInfo?.defaultProjectinternally. Single-arg call. -
SignupAPI — frontend usesauthServiceClientConnect.signup()instead ofCreateUser+Login - Auth interceptor — skips token refresh for
Signupmethod -
DEFAULT_PROJECT_PREFIX— unexported, used only internally bygetDefaultProjectName
SaaS vs Self-hosted Behavior Differences
See 06.saas-vs-selfhosted.md for a comprehensive catalog of every code path difference.
Workspace Isolation Audit (Code Review)
A full code review was conducted to verify workspace isolation across the entire backend. All previously flagged API gaps were investigated and found to be properly isolated.
Fixes Applied
| # | Fix | Files Changed |
|---|---|---|
| 1 | ACL now validates instance-scoped resources (e.g. instances/{id}, instances/{id}/roles/{role}) by looking up the instance with workspace filter |
backend/api/v1/acl.go |
| 2 | Added missing Workspace param to GetDatabase/ListDatabases calls |
backend/api/lsp/handler.go, backend/api/lsp/completion.go, backend/component/export/resources.go (4 calls), backend/component/sampleinstance/manager.go |
| 3 | LSP handler refactored: user and workspaceID injected into context at WebSocket connection time, removed from handler struct. Now uses common.GetWorkspaceIDFromContext(ctx) consistently |
backend/api/lsp/lsp.go, backend/api/lsp/handler.go, backend/api/lsp/completion.go |
| 4 | Added cross-workspace documentation comments to ACL populateRawResources (resource resolution strategy, per-case comments) |
backend/api/v1/acl.go |
| 5 | db_schema.go GetDBSchema now JOINs to instance table and filters by instance.workspace when workspace param is provided |
backend/store/db_schema.go |
API Layer Verification
All previously flagged services were verified to properly enforce workspace isolation:
instance_role_service.go— usesgetInstanceMessagehelper which filters by workspace. ACL layer now also validates instance ownership.changelog_service.go—ListChangelogsandGetChangeloglook up the database withWorkspace: common.GetWorkspaceIDFromContext(ctx). ACL's database case also validates.database_group_service.go— all methods callstore.GetProjectwith workspace filter before accessing database groups.database_service.go—GetDatabase,BatchGetDatabases,UpdateDatabaseall use workspace-filtered lookups.revision_service.go— validates database with workspace filter before querying revisions.issue_service.go—getIssueFind()sets workspace from context;getIssueMessage()passes workspace.plan_service.go— allGetPlan/ListPlanscalls pass workspace.rollout_service.go— all task/plan lookups pass workspace.access_grant_service.go—GetAccessGrantwith workspace filter before any update.release_service.go— project lookup with workspace filter before accessing releases.worksheet_service.go— project lookup with workspace filter before accessing worksheets.
Store Layer Verification
Every public store method was audited:
- Root tables (
project,instance,policy,setting,role,group, etc.): All enforce workspace via directWHERE workspace = ?. - Child tables (
changelog,revision,worksheet,db_schema, etc.): Scoped via globally unique parent PKs. API layer validates workspace on the parent before calling these methods. - Global tables (
principal,sheet_blob): Intentionally cross-workspace by design. Principals are global identities. Sheet blobs are content-addressed (SHA256 dedup). - All API-layer callers of optional-workspace store methods properly pass
common.GetWorkspaceIDFromContext(ctx). Verified forGetDatabase,ListDatabases,GetIssue,ListIssues,GetPlan,ListPlans,ListTasks,ListTaskRuns.
Remaining
High Priority
- Workspace switching — Issue new JWT with different
workspace_id(login auto-selects the first workspace; users switch after login) - Invite users
- ListWorkspacesByEmail must expand groups
- User count limit in the SaaS mode
Medium Priority
- Schema sync perf — when database count grows, consider querying per instance or adding
InstanceIDsbatch filter toFindDatabaseMessage
Low Priority
- Workspace admin panel — Manage workspace settings, members
Impact on Existing Self-hosted Customers
Breaking Changes
- Signup API moved —
CreateUser(POST /v1/users) now requiresbb.users.createpermission. Self-service signup moved toSignup(POST /v1/auth/signup). API consumers usingCreateUserfor registration will break. CreateUserno longer adds to workspace IAM — Admin creates principal only. Must separately add to IAM for the user to login.
Non-breaking Changes
- Default project — New workspaces get
default-{workspaceID}. Existingdefaultproject preserved. Code handles both formats. - Workspace table + migration — Instant
ADD COLUMNwith default. No table rewrite. - Login flow — Self-hosted with
allUsersin IAM works identically to before. - Cache fixes — Fixes potential stale cache bugs.
- Server startup — Resilient to missing workspace on first boot.
Design Decisions
server_configonly storesauth_secret— All other settings live in per-workspace WORKSPACE_PROFILE.Root table PKs (
resource_id) are globally unique — No composite PK migration needed.Three access patterns for store queries:
- API layer:
common.GetWorkspaceIDFromContext(ctx)from JWT - Runners: Cross-workspace methods
- Login/startup:
store.GetWorkspaceID(ctx)orListWorkspacesByEmail
- API layer:
OAuth2 child tables don't need workspace — scoped through
client_idFK.Default project naming — New workspaces:
default-{workspaceID}. Legacy:default.IsDefaultProjectand frontend handle both. No data migration needed.SignupvsCreateUser— Signup is self-service (both modes). CreateUser is admin-only (self-hosted). SaaS admins add members via workspace IAM policy.disallow_signup— Self-hosted only. Not applicable in SaaS (admin invites via IAM, signup always allowed for new workspace creation).allow_without_credentialAPIs — NoGetWorkspaceIDFromContextin unauthenticated paths. Workspace resolved from entity data orstore.GetWorkspaceIDfor self-hosted.