Comment on page
StackState for Kubernetes troubleshooting Self-hosted
StackState can authenticate using KeyCloak as an authentication provider, you will need to configure both StackState and KeyCloak to be able to talk to each other. The following sections describe the respective setups.
When using Keycloak as an authentication provider, StackState will use OIDC (OpenID Connect) to authenticate users. The following diagram describes the authentication flow.
Keycloak authentication flow
Before you can configure StackState to authenticate using KeyCloak, you need to add a new client configuration to the KeyCloak Authentication Server. The necessary settings for the client are:
- Client ID - The ID of the client that's connecting, we recommend naming this
- Client Protocol - Set to
- Access Type - Set to
confidential, so that a secret is used to establish the connection between KeyCloak and StackState
- Standard Flow Enabled - Set to
- Implicit Flow Enabled - Set to
- Root URL - The root location of StackState (the same value configured in as base URL of the StackState configuration
- Valid redirect URIs - This should be
- Base URL - This should point to the root location of StackState
To configure StackState to authenticate using KeyCloak, KeyCloak details and user role mapping needs to be added to the file
authentication.yaml. For example:
# scope is optional. By default `openid`, `profile` and `email` are requested
# scope: ["openid", "profile", "email"]
# usernameField: preferred_username
# groupsField: roles
# map the roles from Keycloak to the
# 4 standard subjects in StackState (guest, powerUser, admin and platformAdmin)
Note: By default when authenticating a user the request to KeyCloak specifies a default scope of
openid profile emailif a custom scope has not been specified on the configuration. Verify the
Client scopeson your KeyCloak instance to be sure that the default scope is correct or you need a custom one.
Follow the steps below to configure StackState to authenticate using KeyCloak:
authentication.yaml- add details of the KeyCloak authentication provider (see the example above). The KeyCloak specific values can be obtained from the client configuration in KeyCloak:
- url - The base URI for the KeyCloak instance
- realm - The KeyCloak realm to connect to
- authenticationMethod - Set to
client_secret_basic, this is currently the only supported value.
- clientId - The ID of the KeyCloak client as configured in KeyCloak
- secret - The secret attached to the KeyCloak client, which is used to authenticate this client to KeyCloak
- redirectUri - Optional: The URI where the login callback endpoint of StackState is reachable. Populated by default using the
stackstate.baseUrl, but can be overridden (must be a fully qualified URL that points to the
- jwsAlgorithm - Set this to
RS256, this is currently the only supported value.
- jwtClaims - Optional: The roles or username can be retrieved from a different attribute than the Keycloak default behavior
- usernameField - Optional: The field in the OIDC user profile that should be used as the username. By default, this will be the
- groupsField - Optional: StackState will always, and by default only, use the
rolesKeycloak provides. But it can also add roles from the field specified here. This is mainly useful when Keycloak is mapping roles/groups from a third-party system.
authentication.yaml- map user roles from KeyCloak to the correct StackState subjects using the
roles.adminsettings (see the example above). For details, see the default StackState roles. More StackState roles can also be created, see the RBAC documentation.
- 3.Store the file
authentication.yamltogether with the
values.yamlfile from the StackState installation instructions.
- 4.Run a Helm upgrade to apply the changes:helm upgrade \--install \--namespace stackstate \--values values.yaml \--values authentication.yaml \stackstate \stackstate/stackstate-k8s
- The first run of the helm upgrade command will result in pods restarting, which may cause a short interruption of availability.
- The authentication configuration is stored as a Kubernetes secret.