Workspaces and access
Adding people and changing roles in the app is in users and access.
Workspaces
A workspace owns everything in it: connections, agents, workflows, runs, the audit log, usage and credits.
- A user belongs to one workspace, through a membership.
- The instance admin (whoever installed Werker) manages the instance and its workspaces. Setup creates the first workspace.
- Sandboxes are never shared between workspaces.
Roles and permissions (RBAC)
- Roles, resources and actions are fixed lists in code. A permission
is
action:resource, for exampleupdate:connection. - Each role's permissions are written out per role.
- A role belongs to a membership, not to a user: someone removed from one workspace and added to another starts with the role given there.
- Instance admin is a separate role above all workspaces: Better
Auth's admin plugin, user role
admin(everyone else hasuser). The first user added becomes one (add_user_to_workspace). can_grant_role()limits who can grant or remove a role: only someone at or above it.- A workspace can adjust a role's permissions without a deploy; the top workspace role cannot be overridden.
Starting lists:
| List | Values |
|---|---|
| Roles | owner, admin, member, viewer |
| Resources | member, agent, workflow, run, connection, settings, audit, billing |
| Actions | view, create, update, delete, run, configure |
Row-level security
The app checks permissions; Postgres row-level security (RLS) is the second line.
- Workspace-owned tables carry
workspace_idand a policy onapp.workspace_id. - Each transaction sets
app.workspace_id(with_workspaceinpackages/db/src/client/client.ts). - The app connects as
werker_app, which does not own the tables. - Workers claim runs across all workspaces with the database function
claim_next_run(queue).
What's built
Sign-in and workspaces use Better Auth (opens in a new tab) (packages/auth) with email and password and its organization plugin.
- Workspaces are organizations. Better Auth's tables (
user,session,account,organization,member,invitation) live in theauthschema, used by thewerker_authrole. Werker's workspace-owned tables referenceauth.organization (id), and RLS on them works as before.werker_appcannot read theauthschema. - Werker's own schemas:
durableholds each run's Pi Durable state,observabilitythe run traces, spend, totals and scores (run_spans,run_usage,run_totals,run_agent_totals,run_scores,score_definitions), andanalyticsthe public site's page views (page_views,page_view_salt). Everything else is inpublic. SQL inpackages/db/srcnames those tables with their schema; the workspace-owned ones have the same row-level security as the rest. - Sign-in: email and password through Better Auth, from a
SvelteKit form action; Better Auth's endpoints are mounted at
/api/auth. Public sign-up is off: an operator adds users withpnpm add-user --email <email> --workspace <slug> --role <role>(password fromWERKER_USER_PASSWORD). A new workspace is created with that user as its owner. - Dev sign-in: under
vite devonly, a request with no session is signed in as[email protected](packages/core/src/access/dev-user.ts), which is created if missing. - One workspace per user: a unique index on
auth.member ("userId")(001_schema.sql).current_userinpackages/auth/src/session.tsgives the one membership, or null.add_workspace_memberandadd_user_to_workspacerefuse someone in another workspace. Being an instance admin adds no workspace. Better Auth'ssession."activeOrganizationId"is not read, and itsset-activeandaccept-invitationendpoints are off. - Name:
rename_workspaceinpackages/core/src/access/access.ts, needingconfigure:settings, changes the organization's name, not the slug operator scripts use. Better Auth'sorganization/updateis off. A new workspace's name is its slug. Two workspaces may have the same name. - Instance settings: Admin → Sandboxes (instance admins) sets where every workspace's sandboxes run, including the hosted providers' keys. Model and service keys belong to one workspace each.
- Roles: owner, admin, member and viewer, defined with Better
Auth's access control in
packages/auth/src/access.ts. Each role lists Better Auth's own organization permissions (members, invitations) plus Werker's resources, written out per role. - Role permissions per workspace: Admin → Roles switches a
permission on or off for admin, member or viewer. Only differences
from the built-in lists are stored (
role_permission_overrides,packages/db/src/workspace/role-permissions.ts);current_userinpackages/core/src/access/access.tsloads them with the membership, sohas_permissionapplies them on every check. Changing one needsconfigure:settings. The owner role cannot be changed, nobody changes their own role's permissions, and nobody switches a permission they do not hold (can_edit_permission). - API keys: a key belongs to a membership (
api_keys) and is deleted with it. Only its SHA-256 hash is kept (packages/core/src/access/api-keys.ts).find_api_keyfinds none that has expired, whose owner is banned, or whose member is in another workspace, and the owner's role is read again on each request. What accepts a key is in API, CLI and MCP. - Invitations:
packages/core/src/access/invitations.tsqueues each email with its invitation. Acceptance rechecks the inviter’s permissions and consumes the link in the transaction that adds the member. The invitation’semail_ididentifies the queued message, not an inbox delivery receipt. - Members:
add_member,change_member_roleandremove_memberinpackages/core/src/access/access.ts, needingcreate:member,update:memberanddelete:member.can_grant_role(packages/auth/src/access.ts) limits both the role given and the member changed to roles at or below the actor's own. Nobody changes or removes themselves, so a workspace keeps an owner. Better Auth's own HTTP endpoints for inviting, removing, changing and leaving are switched off (disabledPathsinpackages/auth/src/auth.ts). - Web: run pages and
/runs/<id>/eventsrequireview:run; a denied request is a 404. - Settings:
WERKER_AUTH_SECRETsigns cookies and is required in production;WERKER_AUTH_DATABASE_URLandORIGIN(Better Auth's base URL) are optional locally.