Appearance
0010. SCIM 2.0 provisioning
Status: proposed (awaiting the security reviewer and the architecture owner). Applies to the new scim module, the new crates/api-scim door, crates/kernel (one new command), crates/authz (two definer functions), crates/doors (identity mapping for the door), modules/core (one policy), services/auth (an internal provisioning endpoint), and the web app's Settings > Provisioning page. Phase 5 (contract section 13).
Context
Larger customers manage people in an identity provider (Okta, Microsoft Entra ID, OneLogin, JumpCloud) and expect it to create, update and deactivate accounts in Orbit over SCIM 2.0 (RFC 7643 for the schema, RFC 7644 for the protocol). Orbit's identities live in the sign-in sidecar (services/auth), its memberships are synced from sidecar tokens (ADR 0002), and contract rule 2.2 says every action goes through the bus and Cedar. A SCIM client is a machine, not a person, and holds a long-lived bearer token.
Decision
1. Scope
/scim/v2on the web role:ServiceProviderConfig,ResourceTypes,Schemas,UsersandGroups. Bulk,/Me, sorting, password changes and.search(POST) are not supported and say so inServiceProviderConfig.- Users carry
urn:ietf:params:scim:schemas:core:2.0:User(userName, externalId, name, displayName, title, emails (one work address), active) and the enterprise extensionurn:ietf:params:scim:schemas:extension:enterprise:2.0:User(employeeNumber, department, manager.value). Other attributes are accepted and ignored. - Filters:
eq ne co sw ew pron strings,eq neon booleans,gt ge lt leonmeta.createdandmeta.lastModified, withand,or,notand parentheses; at most 1024 characters, 8 levels of nesting and 32 comparisons. Pagination bystartIndexandcount(default 100, at most 200).meta.versionis an ETag (W/"<n>"), honoured inIf-Matchon PUT, PATCH and DELETE (412 on a mismatch). - PATCH takes
add,replaceandremovein any case (Entra sendsReplace), string booleans ("False"), paths with the extension URN, and value-path filters (emails[type eq "work"].value), at most 50 operations per request. - Requests:
application/scim+json(orapplication/json), at most 64 KiB. Errors use the RFC 7644 shape (schemas,status,scimType,detail), never echoing input.
2. Tokens
- Owners only, in the web app (Settings > Provisioning):
scim.token.create,scim.token.list,scim.token.revoke. Sensitive, never MCP tools, refused on doormcpand for any principal but a person. Each is audited by the bus. - A token is
oscim_<tenant>_<token id>_<secret>(ids as 32 hex digits, a 256-bit random secret in base64url). It is shown once. Orbit stores the token id, a display prefix (the secret's first 8 characters), a name, an optional expiry, the creator and an HMAC-SHA256 of the whole token under a key derived fromORBIT_AUDIT_KEY(AuditKey::subkey("orbit-scim-token-v1")), which never enters Postgres. The door recomputes the HMAC and compares in constant time. - The tenant comes from the token only. The door reads the stored hash through the definer function
scim.token_for(tenant, id)(executable byorbit_doorsonly). A missing, malformed, wrong, revoked or expired token, or one of another tenant, is the same401. - A token is an API client. Creating one adds an
api_clientmembership whose id is the token id, with a fixed list of grants (authz.set_scim_client, callable only from thescimmodule's role and only with grants from the list written in the function). Revoking deletes that membership, so the bus refuses the token's next request even if a door missed the revocation. Every SCIM request runs asActor::ApiClient(<token id>)on doorweb. - Rate limits per token: 600 requests and 120 rejected attempts a minute, 8 in flight. The token is checked before the body is read, and at most 16 token checks run at once per process, so requests with made-up tokens cannot take the doors' database pool.
3. Mapping
| SCIM | Orbit |
|---|---|
| User | a row in scim.users (the SCIM resource, its version and its person) |
| User's sign-in account | a sidecar user with that email, created unverified and without a password (at most 1000 a day per organisation); the person sets one from the set-password email, which verifies the address. An existing account with that email is linked instead |
| User, active | a kernel member: kernel.member.provision (role admin or member) |
User, active: false or DELETE | kernel.member.remove (event kernel.member.removed) and the sidecar membership is deleted |
| User reactivated (or re-created with the same externalId or email) | kernel.member.restore (event kernel.member.restored), then kernel.member.provision; only for a removal SCIM made. A person an admin removed in Orbit stays removed (409) until an admin restores them |
Group admin | tenant role admin |
Group member | tenant role member |
| enterprise employeeNumber, when the token's "create employees" setting is on | core.employee.create (number, names, work email, joining date today) and core.employee.link_person |
| department, manager | stored on the SCIM resource only |
Groups are fixed: exactly admin and member. Creating or deleting a group is refused (mutability). Adding a user to admin makes them an admin; removing them from admin or adding them to member makes them a member.
4. How a request runs
The door (crates/api-scim) is an adapter. For every request it verifies the token, then dispatches bus commands as the token's API client, in this order:
- For a create, the sign-in account: the sidecar's internal endpoint finds or creates the user by email (no membership yet), and
doors.map_usermaps it to an Orbit person. - The
scim.*command, which validates the resource, applies the filter or the patch, checks the ETag and the rules in section 5, and stores the result. - Reconciliation of the person's membership with the stored resource (
kernel.member.provision/remove/restore), and the optional employee. - The sidecar's membership and role, so the role synced from the next sign-in token (ADR 0002) is the one SCIM set.
Each step is idempotent and a retry re-runs every step, so an identity provider's retry after a partial failure converges. A failure before step 4 can leave a sidecar user without a membership, which reaches no tenant. A failed step 4 leaves the person unable to sign in until the retry: never with more access than SCIM asked for.
5. What SCIM may never do
- Grant or take away owner: groups map only to
adminandmember; an owner's role, activity and membership cannot be changed over SCIM (mutability), so SCIM can never remove the last owner. - Grant module roles (payroll duties or any other
<module>.roles_ofrole), API client grants, agent tokens or MCP tokens. - Run anything but its grants:
scim.user.*,scim.group.*,kernel.member.provision|remove|restoreand, with the setting,core.employee.createandcore.employee.link_person. Grants are a ceiling (base policy), so no module policy can widen them, andauthz.set_scim_clientrefuses any other grant. - Create or manage its own tokens, read the audit log, or read personal fields.
- Act in another tenant: the tenant is the token's, and every query is tenant-scoped and under row-level security.
- Change a sign-in account it did not create, or one it shares. Accounts are global: the sidecar changes an account's email or name only if this organisation's provisioning created it and no other organisation holds it and it is no owner's; an account the tenant only linked is left as it is, and a shared one is refused. An owner's userName and email cannot be changed over SCIM (
mutability). A changed address is unverified and every session of the account ends; the set-password email goes to the new address. - Undo an admin's removal:
kernel.member.restoreby anyone but a person lifts only a removal an API client made, and never a former owner's.
6. Sidecar interface
POST /internal/scim/user (for an organisation: find or create by email; update email and name under the rule in section 5), POST /internal/scim/membership (set or delete a membership with role admin or member; an owner's membership is never changed). Served by the sidecar on the same port as /api/auth but outside it, so the web role's /api/auth proxy never forwards it; that port is reachable on the internal network only (the dev stack publishes it on 127.0.0.1). It is authenticated by AUTH_PROVISION_SECRET (ORBIT_AUTH_PROVISION_SECRET on the Orbit side), compared in constant time. Without it, the SCIM door is not mounted. Every refusal of an update (a taken address included) is the same invalidValue to the SCIM client, so a tenant cannot probe which addresses have accounts elsewhere.
Consequences
- SCIM-provisioned people sign in with a password they set from the reset email. With an OIDC provider, their SSO identity is not linked automatically (implicit linking stays off, ADR 0002): linking an SSO identity to a provisioned account is future work.
- The audit log has one entry per bus command of a SCIM request, attributed to the token's API client, with digests only (no names or emails).
- The joining date of an employee created from SCIM is the day it was provisioned (pending HR confirmation; a later
core.employee.updatecorrects it). - Shortcuts: rate limits are per process; groups are fixed rather than mapped from arbitrary IdP groups.