Skip to content
AI GatewayAI Gateway Manual

Keycloak user provisioning

Sync target rules, Keycloak preparation, settings, and Keycloak-specific troubleshooting for syncing Keycloak users and groups.

When Keycloak is the active auth provider, AI Gateway reads users and groups using the service account of the sign-in client registered in Auth providers. Roles on that same client determine who gets synced. This page covers the Keycloak-side preparation and the rules that apply only to Keycloak.

Assign a role of the sign-in client directly to a user or to a group. A group assignment includes members of its subgroups. For instructions on creating and assigning roles, see Keycloak integration. For how a sync changes members and teams, read How user provisioning works.

Rules that apply only to Keycloak:

  • A team is named after the group path. For example, the /eng/admins group becomes the eng/admins team.
  • If you assign a role to a subgroup as well, it gets its own team. A user who holds a role through both groups joins both teams.
  • A user who receives a role only through a composite or realm default role can sign in, but sync does not count that role as an assignment. An existing member in this situation appears in the removal plan. Review the plan in a dry run before enabling scheduled sync. See Keycloak: Converting a role to a composite role and Keycloak: Using default roles.
  1. In the Keycloak admin console, open the AI Gateway sign-in client. Under Settings → Capability config, turn on Service accounts roles and save. Keep Standard flow on for user sign-in (Keycloak: Using a service account).
  2. Open Service accounts roles → Assign role. Grant the service account view-users and view-clients from realm-management (Keycloak: Dedicated realm admin consoles). These roles can read users, groups, and client information in the realm. Do not grant write permissions such as manage-users or realm-admin.
  3. On Keycloak 26.8.2 or later, open Client scopes → Add client scope and add kc-admin-api as Optional (Keycloak: Admin REST API now enforces an audience check). AI Gateway requests it when obtaining a sync token. Keep it out of ordinary sign-in tokens by leaving it off the Default scope list.

You do not enter the secret again in User provisioning. If you rotate it in Keycloak, update the credentials in Auth providers. Subsequent sign-ins and sync runs use the new secret. The AI Gateway server must be able to reach the displayed issuer over HTTPS.

  1. As an administrator with permission to manage users, open Organization → Auth providers. In the active Keycloak card’s action menu, select Manage provisioning. The User provisioning page shows the realm, issuer, and sign-in client ID.
  2. For the other fields (scheduled sync, removal threshold, Follow Keycloak user status), the dry run, and the run, follow How user provisioning works.

With Follow Keycloak user status on, assigned users whose Enabled is off in Keycloak are deactivated. Members an AI Gateway administrator deactivated manually are activated again too, so to keep a member inactive, turn off Enabled for that user in Keycloak.

Open the run’s details in Run history to see why it stopped.

ReasonWhat to check
Keycloak rejected the sync credentialsCheck Service accounts and the view-users and view-clients roles on the sign-in client. Check the secret in Auth providers. On Keycloak 26.8.2 or later, kc-admin-api must be Optional.
Sign-in client not foundCheck whether the displayed client was deleted or renamed and whether the sync service account has view-clients.
Request rate limitedCheck the limits on Keycloak or its proxy. Wait, then run sync again.
Could not read KeycloakCheck the issuer and connectivity, then try again. The run also stops if the directory changes too much during the read or exceeds the sync limit. If the directory exceeds the limit, grant the role to fewer users and groups.
Removal rate exceeded the thresholdCheck that affected users have the role directly or through a group. The sign-in ID token’s sub must match the Keycloak user ID.
Run interruptedCheck which changes applied in the run details and run a new dry run. Changes applied before the interruption stay in place.