plugins/scim
A SCIM 2.0 server (RFC 7643, 7644) per organization. A directory (Okta, Entra ID, Google,
JumpCloud, …) provisions the organization’s members as Users and its roles as Groups with a
connection token the organization creates and rotates itself; operators see every connection. A
SCIM User is a Polaris user with a membership in the organization (its id is the Polaris user id);
a Group is one of the organization’s roles. plugins/audit and
plugins/admin are optional.
Install
Section titled “Install”import "github.com/univeros/polaris.go/plugins/scim"
cfg, err := polaris.FromEnv(db, audit.New(audit.Config{}), admin.New(admin.Config{}), scim.New(scim.Config{}))p, err := polaris.New(cfg) // a relative BaseURL fails here_, err = p.Migrate(ctx) // creates polaris_scim_connection, polaris_scim_resource, polaris_scim_membership_provenance, polaris_scim_user_nameConfig
Section titled “Config”| Field | Default | Purpose |
|---|---|---|
BaseURL | Auth.Issuer + Config.PathPrefix | absolute http(s) URL where Polaris is mounted, prefix included ("https://app.example.com/auth"); every meta.location and a connection’s scim_base_url derive from it |
Routes
Section titled “Routes”Organization admins (bearer, org.update in the active organization):
| Method | Path | Purpose |
|---|---|---|
| GET | /orgs/{id}/scim/connections | the organization’s connections |
| POST | /orgs/{id}/scim/connections | create {name, deprovision?, sso_provider_id?}; answers the token (shown once) and scim_base_url |
| GET | /orgs/{id}/scim/connections/{connectionId} | read a connection |
| POST | /orgs/{id}/scim/connections/{connectionId}/rotate | new token; the previous one stops at once |
| DELETE | /orgs/{id}/scim/connections/{connectionId} | decommission (the users stay) |
The directory (Authorization: Bearer <connection token>, application/scim+json), under
/scim/v2/{connectionId}:
| Method | Path | Purpose |
|---|---|---|
| GET | /ServiceProviderConfig, /Schemas, /ResourceTypes | discovery |
| GET, POST | /Users | list (filter) / create |
| GET, PUT, PATCH, DELETE | /Users/{id} | read / replace / patch / deprovision |
| GET, POST | /Groups | list (filter) / create |
| GET, PUT, PATCH, DELETE | /Groups/{id} | read / replace / patch / delete |
Operators (admin plugin principals): GET /admin/scim/connections (admin read; an
organization-scoped operator sees their organization’s), DELETE /admin/scim/connections/{id}
(admin own). Without the admin plugin these answer 401.
Events and permissions
Section titled “Events and permissions”scim.connection_created, scim.connection_rotated, scim.connection_decommissioned,
scim.user_created, scim.user_updated, scim.user_deactivated, scim.user_reactivated,
scim.user_deleted, scim.group_created, scim.group_updated, scim.group_deleted,
scim.request_rejected (scim.Audit* constants, each a scim.Event). A directory’s request has the
connection as its actor. Without audit nothing is recorded, but the events still fire. Uses core’s
org.update.
What a directory may vouch for
Section titled “What a directory may vouch for”Any user can create an organization and connect a directory to it, so a directory’s word is proof
of a mailbox only on a domain its organization verified (the sso plugin’s domains; without sso
there is none).
-
Creating a user. The account is verified when its email is on a verified domain, and unverified otherwise. An unverified account has no password; its owner takes it by proving the mailbox (a password reset, an email code or magic link).
-
Whose account it is. The directory owns an account it created (it may rename, disable or erase it) until the mailbox’s owner proves it: the first proof removes the directory’s provenance (
scimimplementswiring.AccessEraser), the account stays a member, and from then on the directory changes the membership only, as for any account it did not create. On a verified domain the directory keeps the account: the organization answers for those mailboxes. -
Renaming (
userName). An owned account moves as it would be created: verified at the new address on a verified domain, unverified anywhere else. A verified account is refused an address outside the verified domains (403mutability). The reset and verification messages sent to the old address stop working with the move. -
Who connects a directory. A directory assigns any role of the organization, the owners’ included, so creating a connection or rotating its token takes every permission the organization’s roles grant (the escalation rule of role changes): in practice an owner. Others holding
org.updateread and decommission connections and get 403scim/forbiddenon those two.Connections().Create/Rotatefrom code are the host’s and are not checked. -
What a uniqueness conflict tells. RFC 7644 makes a directory learn that a
userNameis taken (409uniqueness), so whoever holds a connection’s token can tell whether an address has an account: the address of a free one is created instead, and both are recorded (scim.request_rejected,scim.user_created). The SCIM routes have no rate limit of their own, since a directory’s first sync creates every member in a burst. An instance where anyone may create an organization and where that matters limits these routes at its proxy, or who may create organizations.
Problems
Section titled “Problems”Organization routes: https://polaris.univeros.io/problems/scim/forbidden (403, not your active
organization, or creating or rotating a connection without every permission its roles grant), …/scim/not_found (404), …/scim/invalid_input (422), …/scim/conflict (409, the
connection is decommissioned). SCIM routes answer SCIM error documents (scim.ErrorSchema: status,
detail, scimType such as invalidFilter, invalidValue, uniqueness, mutability), which also
carry error and message. Admin routes answer the admin plugin’s problems.
Host integration
Section titled “Host integration”- Erasing a user, by any path, deletes its directory provenance, user mappings and stored name
parts inside the erasure’s transaction (
wiring.UserEraser). - Tokens start with
pst_(scim.TokenPrefix), carry 256 random bits and are stored as a keyed hash. deprovisionisscim.DeprovisionDeactivate(default: the user is banned, their sessions end, the membership this connection created is removed) orscim.DeprovisionDelete(the account is anonymised). It applies to the SCIM DELETE;activesuspends and reactivates the membership only (an account an operator disabled stays disabled). An account nobody has proven (the directory created it outside the organization’s verified domains and its owner never showed up) is anonymised in either mode (recorded asscim.user_deleted): disabled, it would keep the address from its owner. Verify the organization’s domains if deprovisioning should keep the accounts. The organization keeps its last active owner (409) in both modes.- Filters accept what directories send:
attr eq|co|sw "value"joined byand; anything else isinvalidFilter. The value is a JSON string (RFC 7644 §3.4.2.2): JSON escapes are decoded, an unknown escape, a raw control character or a NUL isinvalidFilter. - Input follows RFC 7643/7644 strictly; a non-conforming value is a 400
invalidValue:activeis a JSON boolean or the string"true"/"false"in any case ("on","yes","1",1are refused, in POST, PUT and PATCH);membersis a list of{"value": id}objects (not bare ids, not{});startIndexandcountare integers (decimal digits, an optional sign; below 1 reads as 1, a negative count as 0, at mostscim.MaxCount); a PATCH operation without apathcarries an object. The admin listing’slimitis a positive integer (422 otherwise). The strings are accepted for Microsoft Entra ID, which sendsactiveas"True"/"False"in PATCH (with"op": "Replace"; op names are matched in any case) unless the enterprise application opts into its SCIM 2.0 compliant behaviour with?aadOptscim062020on the Tenant URL. Both work. - Timestamps (
meta.created,meta.lastModified, a connection’screated_at,last_sync_at,decommissioned_at) are RFC 3339 in UTC withZ. - The built-in owner, admin and member roles take members but are never renamed or deleted.
- A User’s
displayNameandname.formattedare the account’s display name;name.givenNameandname.familyNameare kept per connection as the directory sent them (for accounts it manages), and answered back so the directory sees no difference. - From code:
scim.Of(g).Connections()(Create,Rotate,Decommission,List,Delete) andscim.Of(g).BaseURL(connectionID).
Example
Section titled “Example”Example in example_test.go — go doc github.com/univeros/polaris.go/plugins/scim.