Skip to main content

SCIM provisioning

SCIM (System for Cross-domain Identity Management) lets an identity provider such as Okta, Microsoft Entra ID or OneLogin push users and groups into the gateway instead of admins creating them by hand. When someone is assigned the Spanway app in the directory they appear as a user, when their groups change they land in the right teams, and when they are deactivated every key they own stops working. The endpoints live under /scim/v2, follow RFC 7643 and RFC 7644, and need an enterprise license.

A real-world scenario​

A company of four hundred people manages access in Okta. New engineers used to email an admin for a Spanway account and a team, and leavers kept access until someone noticed. The admin creates a SCIM token in the Admin UI, pastes the base URL and token into the Okta app, and assigns the Platform and Data Science groups to it. From then on joiners get an account and the right team on their first day, movers change teams when their groups change, and leavers lose access the minute HR deactivates them.

Steps​

  1. In the Admin UI open Settings, Admin Settings, and the SCIM tab. Copy the SCIM Tenant URL shown there with the Copy button, https://gateway.example.com/scim/v2.

  2. Under Authentication Token give the token a name in Token Name and choose Create SCIM Token. The token is shown once under Your SCIM Token with a Copy button. Store it in the identity provider now, you cannot see it again. The same token through the API is a virtual key restricted to the SCIM routes:

    curl -s -X POST http://localhost:4000/key/generate \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"key_alias": "okta-scim", "allowed_routes": ["/scim/*"]}'
  3. In the identity provider, enable provisioning for the Spanway app, enter the base URL and the token as a bearer token, and assign the users or groups that should have access. Most providers test the connection by calling /scim/v2/ServiceProviderConfig.

  4. If members of one directory group should be proxy admins, name that group in config.yaml. The next push from the identity provider applies it. See settings for what this does and its risk.

    spanway_settings:
    scim_admin_group: gateway-admins
  5. Check what the provider sends by creating a user the way it would.

    curl -s -X POST http://localhost:4000/scim/v2/Users \
    -H "Authorization: Bearer sk-scim" -H "Content-Type: application/scim+json" \
    -d '{
    "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
    "userName": "jane@example.com",
    "active": true,
    "emails": [{"value": "jane@example.com", "primary": true}],
    "groups": [{"value": "team-platform", "display": "Platform"}]
    }'

Expected result​

The gateway answers 201 Created with the SCIM user, and Jane appears on the Internal Users page as a member of the Platform team.

{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"id": "jane@example.com",
"userName": "jane@example.com",
"active": true,
"emails": [{"value": "jane@example.com", "primary": true}],
"groups": [{"value": "team-platform", "display": "Platform"}],
"meta": {"resourceType": "User"}
}

When the provider later sends PATCH /scim/v2/Users/jane@example.com with active: false, Jane can no longer sign in and every virtual key she owns is refused with 401.

Mapping​

SCIMSpanway
User id.user_id
User userName and primary email.user_email
User active.metadata.scim_active. A deactivated user cannot sign in and every virtual key they own is refused with 401.
Group id.team_id
Group displayName.team_alias
Group members.Team membership. Only members that are users are added, nested groups are ignored.

A user's groups on create or replace set their teams. Removing a member from a group in the directory removes them from the team. spanway_settings.scim_admin_group names a group whose members are made proxy admins, and a user who leaves that group loses the role on the next push.

GET /scim/v2/Users?startIndex=1&count=50 pages through users, at most 100 at a time, and PATCH accepts the standard operations for active, emails and group membership. The list routes take equality filters only: userName eq "jane@example.com" and emails.value eq "jane@example.com" on users, and displayName eq "Platform" on groups. Any other filter, such as externalId eq ... or an operator like co or sw, is refused with 400 and a message that starts with invalidFilter, so an identity provider never mistakes the full user list for a match. The discovery endpoints /scim/v2/ServiceProviderConfig, /scim/v2/ResourceTypes and /scim/v2/Schemas describe the implementation so providers can configure themselves, and ServiceProviderConfig reports filter.supported as true with maxResults 100.

POST /scim/v2/Users with an email that already belongs to a gateway account does not create a second account. With a deployment-wide token the gateway links the request to that account instead: it keeps the account's user_id, updates its email, alias and metadata, sets its teams to the groups sent (or keeps them when none are sent), changes its role when scim_admin_group is set, and answers 201 with the existing id. The link is written to the audit log as an updated row on the user. An organization-scoped token answers 409 instead, see below.

Settings​

SettingDefaultWhat it does
spanway_settings.scim_upsert_useron (true)When a group push names a member who has no gateway account yet, on creates that user so the team is complete, off (strict mode) refuses the whole group push with 400 until the provider creates the user through /scim/v2/Users. Turn it off when every account must come from a user push, for example when your security team reviews each assignment. Organization-scoped tokens always behave as off.
spanway_settings.scim_admin_groupunsetUnset, SCIM never makes anyone a proxy admin. Set to a group's display name or id, members of that group become proxy admins on the next push and lose the role when they leave the group. A proxy admin can change every setting and read every key, so use a small group that only the gateway owners are in. Organization-scoped tokens ignore it.

Both are read from the config on every SCIM request, so a changed value applies to the next push. The settings reference lists them too.

Manage, rotate and revoke the token​

A deployment-wide SCIM token is an ordinary virtual key limited to /scim/*, so you manage it on the Virtual Keys page. Find it by the name you gave it, for example okta-scim, in the key alias column.

  1. To rotate it, open the key and choose Regenerate Key, or call POST /key/regenerate, then paste the new token into the identity provider. The old token stops working, so provisioning pauses until the provider has the new one.

    curl -s -X POST http://localhost:4000/key/regenerate \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"key": "<token id of okta-scim>"}'
  2. To revoke it, delete the key on the Virtual Keys page or with POST /key/delete. Every SCIM call with it then answers 401, and the identity provider stops creating, updating and deactivating users until you give it a new token.

    curl -s -X POST http://localhost:4000/key/delete \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"key_aliases": ["okta-scim"]}'

Organization-scoped tokens are listed and revoked on the organization's SSO tab instead.

Audit​

Every change SCIM makes writes a row to the audit log, and the row names the token that made it, as changed_by scim token <name> with the token's hash in changed_by_api_key.

ChangeTableAction
User created, replaced, patched, linked by email or deactivatedSpanway_UserTablecreated or updated, with the user before and after
User deletedSpanway_UserTabledeleted, with the user as it was
Role granted or removed through scim_admin_groupSpanway_UserTableupdated, with the old and new user_role
Key blocked or unblocked because the user was deactivated, deleted or reactivatedSpanway_VerificationTokenblocked or unblocked, one row per key
Group created, replaced, patched or deletedSpanway_TeamTablecreated, updated or deleted
Member added to or removed from a groupSpanway_TeamTableupdated, written by the team membership change
Placeholder mergedSpanway_UserTabledeleted for the placeholder and updated for the account it was merged into
User an organization-scoped token deletes but does not own, so it is only removed from the organizationSpanway_OrganizationMembershipdeleted, with the user id and organization id, plus the team removals written by the same token

Organization-scoped tokens​

A token minted for one organization from the SSO tab of that organization, or with POST /organization/sso/scim_token/new, only sees and changes that organization's members and teams. Users it creates join the organization and need an email on one of its verified domains, groups it creates become teams of the organization, and scim_admin_group is ignored so it can never grant proxy admin. It only changes or deletes accounts the organization owns outright. Any other member, such as a proxy admin, can only be removed from the organization. See organization single sign-on for the full rules.

Placeholders​

An earlier release created a user keyed by the raw member value when it could not match a group member to an account, and that row then shadowed the real account. GET /scim/v2/placeholders lists such rows and POST /scim/v2/placeholders/{user_id}/merge folds one into the account it shadows, adding that account to the placeholder's teams and deleting the placeholder. The merge is refused with 409 when the row has an SSO identity of its own, owns virtual keys, or names no account.

Endpoints​

MethodPathSummary
GET/scim/v2Discover the SCIM resource types
GET/scim/v2/GroupsList or filter SCIM groups
POST/scim/v2/GroupsCreate a SCIM group as a team
GET/scim/v2/Groups/{group_id}Read one SCIM group
PUT/scim/v2/Groups/{group_id}Replace a SCIM group
PATCH/scim/v2/Groups/{group_id}Patch a SCIM group's name or members
DELETE/scim/v2/Groups/{group_id}Delete a SCIM group and its team
GET/scim/v2/ResourceTypesList the SCIM resource types
GET/scim/v2/ResourceTypes/{resource_type_id}Read one SCIM resource type
GET/scim/v2/SchemasList the SCIM schemas
GET/scim/v2/Schemas/{schema_id}Read one SCIM schema
GET/scim/v2/ServiceProviderConfigDescribe what this SCIM service supports
GET/scim/v2/UsersList or filter SCIM users
POST/scim/v2/UsersCreate a SCIM user
GET/scim/v2/Users/{user_id}Read one SCIM user
PUT/scim/v2/Users/{user_id}Replace a SCIM user
PATCH/scim/v2/Users/{user_id}Patch a SCIM user
DELETE/scim/v2/Users/{user_id}Delete a SCIM user
GET/scim/v2/placeholdersList placeholder users that shadow real accounts
POST/scim/v2/placeholders/{user_id}/mergeMerge a placeholder user into the account it shadows

Errors​

What you seeWhyFix
403 saying SCIM is an enterprise feature.The gateway has no enterprise license.Set the license key, see enterprise.
401 on every SCIM call.The token is wrong, was revoked, or is a key without allowed_routes: ["/scim/*"].Create the token on the SCIM tab, or add the SCIM route to the key.
403 on a SCIM route with an ordinary key.A key restricted to other routes, or a user key, is calling SCIM.Use a SCIM token.
409 User already exists with username: <userName>A user with that userName already exists.Let the provider send PUT or PATCH for the existing user instead of creating it again.
409 User already exists with email: <email>An organization-scoped token created a user whose email another account already has.Fix the provider's attribute mapping, or link the person with a deployment-wide token.
409 Identifier '<id>' already names another accountAn organization-scoped token sent a userName or externalId that is another account's id, SSO id or email. This also answers PATCH /scim/v2/Users/{id}.Make each user's identifiers their own.
400 <email> is not on a verified domain of this SCIM token's organizationAn organization-scoped token used an email outside the organization's verified domains.Verify the domain on the organization's SSO tab.
400 Identifier '<id>' looks like an email but is not this user's own emailAn organization-scoped token sent an email-shaped identifier that differs from the user's email.Map userName to the user's own email.
400 User '<id>' is not a member of this SCIM token's organizationAn organization-scoped token named a user outside its organization.Add the user to the organization first, or use a deployment-wide token.
403 User '<id>' has access beyond this SCIM token's organization...The account belongs to more than this organization, so an organization token may only remove it from the organization.Use a deployment-wide token for that account.
400 invalidFilter: only ... filters are supportedThe list filter uses an attribute or operator the gateway does not support.Use userName eq, emails.value eq or, for groups, displayName eq.
400 Filtered or sub-attribute paths are not supported for <attribute>; PATCH the full attributeA PATCH used a path such as emails[type eq "work"].value.Send the whole attribute.
400 Invalid member: user ID cannot be empty.A group member has no value.Fix the group in the provider.
400 User with ID '<id>' does not exist. Please create the user first via POST /Users before adding to group.Strict mode (scim_upsert_user: false) or an organization token, and the group names a member with no account.Assign the user to the app first, or turn scim_upsert_user back on.
400 Member ID '<id>' names more than one Spanway user...The member value matches several accounts, often a leftover placeholder.Merge or delete the placeholder, see placeholders.
404 User not found with ID: <id> or Group not found with ID: <id>No such user or group that the token may see.Check the id the provider sends.
500 No database connectedThe gateway runs without a database.Connect the database. SCIM stores everything there.
500 Failed to create user '<id>' while provisioning group membership.Creating a missing group member failed.Read the gateway log, then let the provider retry.
401 User=<id> has been deactivated via SCIM. Keys owned by this user cannot be used.A call used a key of a user the directory deactivated.Expected. Reactivate the user in the directory to unblock their keys.
Users land in no team.The group id the provider sends is not a Spanway team_id.Create the group through SCIM first, or set the provider's group id to the existing team id.
The merge of a placeholder answers 409.The placeholder has its own SSO identity, owns keys, or names no account.Review the row on the Internal Users page and delete or repoint it by hand.
403 Placeholder repair needs a deployment-wide SCIM tokenAn organization-scoped token called the placeholder routes.Use a token created on the SCIM tab of Admin Settings.

The deactivated user and member errors are also in the error reference.

Logs​

LevelLineMeaningAction
INFOSCIM: blocked <n> virtual key(s) for user_id=<id> (or unblocked)The directory deactivated, deleted or reactivated a user, and their keys followed.None.
INFOSCIM: email <email> already provisioned as user_id=<id>, keeping that id ...A create request matched an existing account by email and was linked to it.None, unless you expected a new account.
INFOSCIM: merged placeholder user '<id>' into '<id>', moving teams ...A placeholder repair finished.None.
WARNINGError reading scim_admin_group setting, defaulting to NoneThe config could not be read, so no SCIM push grants proxy admin until it can.Check the config file and the database connection.
WARNINGError reading scim_upsert_user setting, defaulting to TrueThe config could not be read, so missing group members are created.Check the config file.

The log reference lists these lines too.