Skip to content

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.

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_name
FieldDefaultPurpose
BaseURLAuth.Issuer + Config.PathPrefixabsolute 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

Organization admins (bearer, org.update in the active organization):

MethodPathPurpose
GET/orgs/{id}/scim/connectionsthe organization’s connections
POST/orgs/{id}/scim/connectionscreate {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}/rotatenew 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}:

MethodPathPurpose
GET/ServiceProviderConfig, /Schemas, /ResourceTypesdiscovery
GET, POST/Userslist (filter) / create
GET, PUT, PATCH, DELETE/Users/{id}read / replace / patch / deprovision
GET, POST/Groupslist (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.

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.

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 (scim implements wiring.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 (403 mutability). 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.update read and decommission connections and get 403 scim/forbidden on those two. Connections().Create / Rotate from code are the host’s and are not checked.

  • What a uniqueness conflict tells. RFC 7644 makes a directory learn that a userName is taken (409 uniqueness), 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.

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.

  • 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.
  • deprovision is scim.DeprovisionDeactivate (default: the user is banned, their sessions end, the membership this connection created is removed) or scim.DeprovisionDelete (the account is anonymised). It applies to the SCIM DELETE; active suspends 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 as scim.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 by and; anything else is invalidFilter. 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 is invalidFilter.
  • Input follows RFC 7643/7644 strictly; a non-conforming value is a 400 invalidValue: active is a JSON boolean or the string "true"/"false" in any case ("on", "yes", "1", 1 are refused, in POST, PUT and PATCH); members is a list of {"value": id} objects (not bare ids, not {}); startIndex and count are integers (decimal digits, an optional sign; below 1 reads as 1, a negative count as 0, at most scim.MaxCount); a PATCH operation without a path carries an object. The admin listing’s limit is a positive integer (422 otherwise). The strings are accepted for Microsoft Entra ID, which sends active as "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 ?aadOptscim062020 on the Tenant URL. Both work.
  • Timestamps (meta.created, meta.lastModified, a connection’s created_at, last_sync_at, decommissioned_at) are RFC 3339 in UTC with Z.
  • The built-in owner, admin and member roles take members but are never renamed or deleted.
  • A User’s displayName and name.formatted are the account’s display name; name.givenName and name.familyName are 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) and scim.Of(g).BaseURL(connectionID).

Example in example_test.go — go doc github.com/univeros/polaris.go/plugins/scim.