Skip to main content
Version: 3.13

KubeRocketCI CLI Keycloak Client

The KubeRocketCI CLI authenticates users through the browser (OAuth 2.0 authorization code flow with PKCE). This page describes how to register a public OpenID Connect client in Keycloak so operators can run krci auth login against your KubeRocketCI Portal.

info

Create the client in the same realm the Portal already uses. To confirm the realm, inspect the OIDC settings returned by the Portal, for example the endpoint GET /rest/v1/config/oidc on your Portal base URL (replace the host with yours):

GET https://portal.example.com/rest/v1/config/oidc

Create the client only in the Platform realm you identified above. Application clients belong there, not in Keycloak’s built-in administrative realms.

Select Realm​

In the Keycloak Admin Console, use the realm drop-down in the top-left corner and select the realm your Portal uses.

Create Client​

The next step is to create a Keycloak client itself:

  1. In the left sidebar, open Clients, then click Create client.

  2. On General settings, set the fields as follows:

    FieldValue
    Client typeOpenID Connect
    Client IDkrci-cli
    NameKubeRocketCI CLI (display only)
    DescriptionPublic OIDC client for the KubeRocketCI CLI (PKCE)
    Always display in consoleOff
  3. Click Next.

  4. On Capability config, set the toggles:

    ToggleValueNote
    Client authenticationOffPublic client (no client secret)
    AuthorizationOffβ€”
    Standard flowOnAuthorization code flow
    Direct access grantsOffβ€”
    Implicit flowOffβ€”
    Service accounts rolesOffβ€”
    OAuth 2.0 Device Authorization GrantOffBrowser-based login
    OIDC CIBA GrantOffβ€”
  5. Click Next.

  6. On Login settings, configure URLs:

    FieldValue
    Root URL(empty)
    Home URL(empty)
    Valid redirect URIshttp://127.0.0.1/* and http://localhost/* (add both)
    Valid post logout redirect URIs(empty)
    Web origins+ (allow all origins configured for this client)
    note

    The CLI binds a callback listener on localhost with a random port on each login, so wildcard redirect URIs are required.

  7. Click Save. You are taken to the client Settings page.

The screenshots below illustrate Access settings (client ID, redirect URIs, web origins) and Capability config / Login settings on a typical Keycloak deployment.

Keycloak client access settings β€” client ID, redirect URIs, and web origins

Keycloak client capability and login settings

Enforce PKCE (S256)​

To enforce PKCE, do these steps:

  1. Open the Advanced tab for the krci-cli client.
  2. Under Advanced settings, set Proof Key for Code Exchange Code Challenge Method to S256.
  3. Click Save for that section.

This ensures Keycloak only accepts logins that send a PKCE code challenge, which matches how the CLI performs authorization.

Configure Token Lifetimes​

On the client Advanced tab, you can leave Access Token Lifespan and session timeouts inherited from the realm (for example five to fifteen minutes for access tokens), or set client-specific values.

At realm level (Realm settings β†’ Tokens), confirm OAuth 2.0 Refresh Token Rotation matches your security policy. The CLI refreshes tokens using the standard OAuth2 token endpoint.

Configure Client Scopes​

To configure client scopes (openid, profile, email, roles, groups), follow the steps below:

  1. Open the Client scopes tab for krci-cli.

  2. Under Default client scopes, ensure typical OpenID scopes are present, including openid, profile, email, and roles (exact names can vary slightly by Keycloak version).

  3. If your Platform expects group membership in tokens, add a groups scope (or your realm’s equivalent, for example a custom groups / groups-core scope) as a Default scope:

    • Click Add client scope β†’ choose the groups scope β†’ Add β†’ Default.

If the realm has no suitable groups scope yet:

  1. Go to Client scopes in the left sidebar β†’ Create client scope.
  2. Set Name (for example groups), Type Default, Protocol OpenID Connect, then save.
  3. Open that scope β†’ Mappers β†’ Configure a new mapper β†’ Group Membership with settings such as:
    • Token Claim Name: groups
    • Full group path: Off
    • Add to ID token / Add to access token / Add to userinfo: On (as required by your cluster and Portal)
  4. Return to the krci-cli client β†’ Client scopes β†’ add the new scope as Default.

Keycloak client scopes assigned to krci-cli

Configure Audience Mapper for Kubernetes API​

The same ID token can be validated by the Kubernetes API server (when OIDC is enabled on the cluster). Add an Audience mapper on the dedicated client scope Keycloak creates for this client (name pattern krci-cli-dedicated):

  1. On krci-cli β†’ Client scopes tab, click the dedicated scope krci-cli-dedicated.

  2. Open the Mappers tab β†’ Configure a new mapper β†’ Audience.

  3. Configure the mapper so the issued token’s aud claim includes both the CLI client ID and the value your API server uses for --oidc-client-id (often kubernetes):

    FieldSuggested value
    Namek8s-audience (or any descriptive name)
    Included Client Audience(optional) depends on whether you model audience as another client
    Included Custom Audiencekubernetes (or the exact --oidc-client-id value on the API server)
    Add to ID tokenOn
    Add to access tokenOn
    Add to lightweight access tokenOff
  4. Save the mapper.

warning

If you also change the API server to expect aud: kubernetes, ensure the Portal client’s tokens carry a compatible audience as well, or Portal logins and API calls may fail. Align this step with your EKS / cluster OIDC configuration.

The following screenshots show the Mappers list on the dedicated scope and an example Audience mapper form. Field names and whether you use Included Client Audience vs Included Custom Audience depend on your Keycloak version and how cluster OIDC is configured.

Dedicated client scope β€” mappers list

Audience mapper configuration example

Verify Configuration​

To ensure everything is configured properly, carefully read the checklist below:

  1. Clients β†’ krci-cli β†’ Settings: Client ID, Standard flow enabled, redirect URIs include http://127.0.0.1/* and http://localhost/*.
  2. Advanced: PKCE code challenge method S256.
  3. Client scopes: Default scopes include openid, profile-related scopes, email, roles, and your groups scope as required.
  4. Client scopes β†’ krci-cli-dedicated β†’ Mappers: audience mapper present and aligned with cluster --oidc-client-id.

Test From Workstation​

Run the command below in a terminal (replace the Portal URL with yours):

krci auth login --portal-url https://portal.example.com

Expected behavior:

  1. A browser window opens on the Keycloak login page.
  2. After successful login (and consent, if enabled), the browser redirects to http://localhost:<random-port>/callback?code=....
  3. The terminal prints a success message with the signed-in identity.

Decode the ID token (for example with jwt.io or your own tooling) and confirm claims similar to:

{
"iss": "https://keycloak.example.com/realms/your-realm",
"aud": ["krci-cli", "kubernetes"],
"azp": "krci-cli",
"email": "user@example.com",
"groups": ["admin", "developers"]
}

If aud does not include your Kubernetes OIDC client ID, revisit Configure Audience Mapper for Kubernetes API. If groups (or your chosen claim) is missing, revisit Configure Client Scopes.