# IdP groups to team membership

**Last updated:** 2026-11-17T01:26:21-03:00 (UTC-3)

With `idp_team_sync`, exact group IDs from your identity provider decide part of each user's **team memberships**: an OIDC claim, a SAML attribute or SCIM groups. A mapped group makes its members **members** of an existing team. Every membership records where it came from, `manual` or `idp:<group id>`; a sync adds and removes only `idp:` memberships and never touches manual ones. The IdP never grants a console role (admin, viewer, operator, team admin) and never creates a team: groups to roles stay out of scope, as decided in [JIT provisioning](/docs/features/jit-provisioning/).

## How to turn it on

```yaml
features:
  console_users: true
  team_management: true
  team_scoped_console: true
  oidc_login: true                 # or saml_login, or scim_groups (source: scim)
  idp_team_sync: true              # operator control, default false; requires PostgreSQL
admin:
  idp_team_sync:
    source: login                  # login (OIDC claim / SAML attribute at sign-in) or scim
    oidc_groups_claim: groups      # top-level ID-token claim with an array of strings
    saml_groups_attribute: groups  # assertion attribute; its values are merged
    mappings:
      - {group: "gateway-engineering", team: team_platform}
      - {group: "00000000-1111-2222-3333-444444444444", team: team_research}   # Entra object ID
```

The mapping can also be edited, and reverted to YAML, in **Console users → IdP groups to teams** or with `GET`/`PUT`/`DELETE /api/v1/admin/idp-team-sync` (global admin, `users:manage`, CSRF, versioned).

| Field | Default | Bounds and meaning |
| --- | --- | --- |
| `source` | `login` | `login`: each console OIDC or SAML sign-in syncs the user from the groups of that sign-in. `scim`: each SCIM group change syncs every user it adds or removes. Only one source drives the sync, so two sources can never undo each other. |
| `oidc_groups_claim` | `groups` | A top-level claim name; identity and protocol claims (`sub`, `email`…) are refused. |
| `saml_groups_attribute` | `groups` | An attribute name of up to 256 characters. |
| `mappings[].group` | — | The **exact** group ID, compared byte for byte: no prefixes, globs or case folding. 1–256 bytes, no control characters. For SCIM, a group is identified by its `externalId`, or by its `displayName` when the IdP sent none. |
| `mappings[].team` | — | An existing team ID. The console and the API refuse a team that is not active; a YAML mapping to a missing or deleted team is skipped at sync time. |

Up to 200 mappings. One group may map to several teams and several groups to one team.

## What a sync does

For one user, from the groups the IdP asserts now:

- **Add:** each mapped team the user does not hold yet becomes a `member` membership tagged `idp:<group>`.
- **Remove:** each `idp:` membership whose group is no longer asserted is deleted. A claim that is missing or malformed counts as no groups, so it can only remove.
- **Keep manual:** a team the user already holds manually stays manual, with its role; a sync never adds, changes or removes it, even when its group disappears.
- **Ignore the unknown:** groups without a mapping are ignored. Nothing creates a team.
- **Retag:** when another asserted group still maps the same team, the membership stays and names that group.
- Only users with the read-only team roles `user` and `team_viewer` are synced. Team administrators and global roles are never synced: without `membership_roles` every membership of a team administrator administers its team, so a group would grant administration. A sync never takes a user above 20 memberships.
- A disabled user loses synced memberships but never gains one, so a group removal made while it was disabled is not undone by its reactivation.

At sign-in the sync runs after the identity is verified and before the console checks the user's teams, so a removed group never survives into the new session; a SAML assertion is spent first, so a replayed one cannot restore an old group set. If the sync cannot be stored, the sign-in fails. With `source: scim`, a SCIM group create, update, patch or delete syncs every member before and after the change; if the sync fails the SCIM call answers 503 and the IdP retries it.

While `idp_team_sync` is on, a console edit of a `user` or `team_viewer` replaces only manual memberships: synced ones stay synced, always with the `member` role; remove one by changing the mapping or the IdP group. Changing the user to `team_admin` or a global role, or any edit while the flag is off, replaces every membership, synced ones included, so turning the flag off never freezes a synced membership. A retag is audited as `membership.idp_retag`. Sessions reread teams on every request, so a removal applies to the next request.

## Console and API

**Console users** shows, for each team of a scoped user, where it comes from: `team_x (IdP group gateway-engineering)` or `(SCIM group)` for a [bound SCIM group](/docs/features/scim/#groups); manual teams show the bare team ID. The API returns the same in `memberships[].source` (`manual`, `idp:<group>` or `scim_group`), which requests never accept. The user editor leaves synced teams out of the selection and lists them apart: while the sync manages the user (`user` or `team_viewer` with the flag on) they are sent back unchanged; otherwise (promotion to `team_admin` or a global role, or the flag off) the edit drops them instead of rewriting them as manual memberships. Migration 175 removes, audited, the synced memberships that a team administrator or global role still held.

```http
PUT /api/v1/admin/idp-team-sync
Content-Type: application/json
X-CSRF-Token: <token>

{"version": 0, "source": "login", "mappings": [{"group": "gateway-engineering", "team": "team_platform"}]}
```

## Audit

Every add and remove is in the identity audit trail (and its hash chain), in the same transaction: `membership.idp_add` and `membership.idp_remove`, with target `<user id>/<team id>` and actor `idp:<group>@<oidc|saml|scim>`. Mapping changes are `idp_team_sync.update` and `idp_team_sync.revert`. Logs record `idp_team_sync` with counts, never the groups.

## Limits

- Membership only, always with the `member` role; groups to roles, including admin, are not supported.
- Named OIDC providers (`oidc_providers`) keep their explicit subject links and do not sync groups: one source drives the sync (`login` is the console's own OIDC or SAML sign-in, or `scim`), and a second login path would remove the memberships the first one added whenever its token carries other groups.
- With `source: login`, a user's teams change only when they sign in again; remove access immediately with SCIM, by disabling the user or by removing the membership in the IdP and asking for a new sign-in.
- Nested groups are not expanded: map each group the IdP actually asserts.
- SCIM groups without an `externalId` are matched by `displayName`, which the IdP can rename; prefer IdPs that send `externalId`.
- A SCIM group replacement that races with another change of the same group may leave one user unsynced until its next group change or sign-in.
- While the flag is off, existing synced memberships stay in force until a console edit or the user's next sync after the flag is turned back on.

## Upgrade

Migration 173 adds the `source` column to team memberships (existing rows become `manual`), the source in the effective-membership view and the mapping table. An older binary treats synced memberships as manual ones, and any user edit it makes rewrites them as manual for good: the IdP can no longer remove them after rolling forward again. Upgrade every replica before turning the flag on; before rolling back, turn the flag off, remove `idp_team_sync` and `admin.idp_team_sync` from YAML and review the `idp:` memberships.
