Skip to content
AI GatewayAI Gateway Manual

Keycloak integration

Before bootstrap, create the AI Gateway client in Keycloak and grant its client role to the users who sign in.

To use Keycloak as the identity provider, create one AI Gateway client in the realm before bootstrap, and grant a role of that client to every user who will use AI Gateway. Screen names on this page follow the Keycloak 26.4 admin console.

AI Gateway checks the client’s roles in the access token at every sign-in. A user with no role of the client is turned away even after signing in to Keycloak, and no member is created. Keycloak issues tokens to users without any role, so this check takes the place of Okta’s application assignment.

The redirect URI, scopes, and network constraints follow IdP app registration in Bootstrap.

  1. In the admin console, select the realm AI Gateway will use and open Clients → Create client (Keycloak: Creating an OpenID Connect client).
  2. In General settings, keep Client type as OpenID Connect and enter a Client ID (for example ai-gateway). Click Next.
  3. In Capability config, turn on Client authentication. Under Authentication flow, Standard flow is the only flow needed. AI Gateway does not use Direct access grants, so you can turn it off. Click Next.
  4. In Login settings, enter the redirect URI in Valid redirect URIs and click Save.

After saving, the client details open with a Credentials tab. If the tab is missing, Client authentication is off; turn it on in the Settings tab.

  1. Open the client’s Credentials tab.
  2. Check that Client Authenticator is Client Id and Secret (Keycloak: Confidential client credentials).
  3. Copy the Client Secret. You enter it at bootstrap step 3.

AI Gateway authenticates the client with HTTP Basic, and Keycloak accepts both Basic and POST. Unlike Okta, bootstrap therefore has no client authentication method to choose.

AI Gateway does not look at role names. Any role of this client allows sign-in.

  1. In the client’s Roles tab, click Create role, enter a Role name (for example user), and click Save (Keycloak: Client roles).
  2. Grant the role to users directly or to a group.
    • User: open the user under Users and click Role mapping → Assign role. Switch to Filter by clients, select the role from step 1, and click Assign (Keycloak: Assigning role mappings).
    • Group: open the group under Groups and grant the role from its Role mapping tab the same way. Members of the group and of its subgroups receive the group’s roles (Keycloak: Groups).
  3. Grant the role to the first administrator account you will enter at bootstrap as well. Without it, the first administrator sign-in is also turned away.

Once granted, the role appears in the user’s Role mapping tab.

Roles reach AI Gateway in the access token’s resource_access claim. If either setting below differs from its default, the roles are left out of the token and every user is turned away.

LocationExpected value
The client’s Client scopes tabThe roles row has Assigned type Default
The client’s Advanced tab → Advanced settingsAlways use lightweight access token is off

Keycloak documents both in Keycloak: Role mappings in the token and Keycloak: Using lightweight access token.

AI Gateway shows users by the email in the ID token and identifies the first administrator by email. A user without an email address cannot sign in. Under Users, check that each user’s Email is set.

At bootstrap step 3, select Keycloak and enter these values.

FieldValue
Issuer URLhttps://<Keycloak host>/realms/<realm>. If Keycloak is served below a path such as /auth, include that path (for example https://sso.example.com/auth/realms/corp; Keycloak: Default context path changed).
Client IDThe Client ID from step 1
Client secretThe Client Secret copied in step 2
CA certificate (PEM)Optional. If an internal CA issued the Keycloak certificate, or it is self-signed, that CA (or the certificate). See Internal CA certificate below.

The issuer URL must equal the issuer value of <issuer URL>/.well-known/openid-configuration. If the Keycloak hostname setting (KC_HOSTNAME, Keycloak: Configuring the hostname) differs from the address AI Gateway connects to, the two values differ and step 3 rejects the URL.

To sync Keycloak users and groups, configure the registered sign-in client’s service account. See Keycloak user provisioning for the required roles and setup steps.

If an internal CA issued the Keycloak certificate, paste that CA into CA certificate (PEM), which appears in step 3 when you select Keycloak. AI Gateway trusts it in addition to the system trust store. Paste one or more -----BEGIN CERTIFICATE----- blocks; leave it empty to use the system trust store only. Okta and Google Workspace use publicly trusted certificates, so they do not have this field.

  • If Keycloak uses a self-signed certificate, paste that certificate itself into CA certificate (PEM). A publicly trusted certificate is not required.
  • The certificate’s host names (SAN) must match the host of the issuer URL. If you connect by IP address, the certificate must contain that IP. There is no setting that turns certificate verification off.
  • Keycloak must use an https:// address. A private IP address is fine.
  • The certificate is used for sign-in (discovery, token exchange, and signing key retrieval), for the issuer check in step 3, and for directory sync.
  • After installation, change it in the same field of the auth provider edit dialog in the administration console. See After installation in Bootstrap.
SymptomCause and action
“No AI Gateway role is assigned to your account” on the sign-in screenThe user has no role of the client. Grant one as in step 3. If every user sees the message, check the token settings in step 4.
Issuer URL rejected at step 3Check that the URL starts with https:// and ends with /realms/<realm>, and that it equals the issuer value of the discovery document.
“Your account is not authorized to access AI Gateway” on the sign-in screenThe user has no email address, or the first administrator signed in with another account. Check step 5 and Bootstrap troubleshooting.

A sign-in turned away for a missing role is logged as a warning with error_category role_not_assigned, and its reason field tells the cause.

reasonMeaning
client_roles_missingThe token has no role of this client. Grant the user a role.
resource_access_missingThe token has no role claim at all. Check both settings in step 4.
Terminal window
cd aig/current
docker compose logs server | grep role_not_assigned