This page describes how to configure Stronghold login through Keycloak using OIDC. For general information about the method, see OIDC auth method.
Keycloak client setup
Select or create a Realm and a Client. Open the client Settings.
Client Protocol:
openid-connect.Access Type:
confidential. In newer Keycloak versions, enable Client authentication.Enable Standard Flow Enabled.
Set Valid Redirect URIs:
https://stronghold.example.com/ui/stronghold/auth/oidc/oidc/callback http://localhost:8250/oidc/callbackThe first URI is used for web interface login, the second one for CLI login. If the method is enabled at a different path, replace
oidcin the first URI with that path.Click Save.
Open the Credentials tab and note the Client ID and Client Secret.
To make Keycloak pass user groups, add a Group Membership mapper with the
groupsclaim name to the client (or its client scope). Disable Full group path if Stronghold needs group names without a path.
Stronghold setup
Enable the OIDC auth method:
d8 stronghold auth enable oidcBy default, the method is enabled at
auth/oidc/. To use a different path, specify-path.Configure the connection to Keycloak. Set
oidc_discovery_urlto the Realm address without/.well-known/openid-configuration:d8 stronghold write auth/oidc/config oidc_discovery_url="https://keycloak.example.com/realms/myrealm" oidc_client_id="<Client ID>" oidc_client_secret="<Client Secret>" default_role="keycloak"In older Keycloak versions, the Realm address contains the
/authprefix, for examplehttps://keycloak.example.com/auth/realms/myrealm.Create a role. In
allowed_redirect_uris, list the same URIs as in the Keycloak client:d8 stronghold write auth/oidc/role/keycloak -<<EOF { "role_type": "oidc", "allowed_redirect_uris": [ "https://stronghold.example.com/ui/stronghold/auth/oidc/oidc/callback", "http://localhost:8250/oidc/callback" ], "oidc_scopes": ["openid", "profile", "email"], "user_claim": "preferred_username", "groups_claim": "groups", "bound_claims": { "groups": ["stronghold-users", "stronghold-admins"] }, "token_policies": ["default"], "token_ttl": "1h" } EOFKey role parameters:
Parameter Description allowed_redirect_urisAllowed redirect URIs. They must exactly match the URIs in Keycloak. user_claimClaim whose value becomes the entity alias name, for example preferred_usernameorsub.groups_claimClaim with the list of user groups ( groupsfrom the Group Membership mapper).bound_claimsClaims and values that must match for login to succeed. In the example, only members of the stronghold-usersorstronghold-adminsgroups can log in.oidc_scopesRequested OIDC scopes. token_policies,token_ttlPolicies and TTL of the issued token.
Mapping Keycloak groups to Stronghold groups
To assign policies based on Keycloak group membership, create external Identity groups and group aliases. For more on external groups, see Identity.
Create an external group with the required policies and save its ID:
d8 stronghold write -field=id identity/group name="keycloak-admins" type="external" policies="admin"Get the accessor of the
oidc/auth method:d8 stronghold auth list -format=json | jq -r '."oidc/".accessor'Create a group alias. The
namevalue must match the group name in thegroupsclaim:d8 stronghold write identity/group-alias name="stronghold-admins" mount_accessor="<OIDC_ACCESSOR>" canonical_id="<GROUP_ID>"Where
<OIDC_ACCESSOR>is the accessor from the previous step, and<GROUP_ID>is the ID of the external group created in the first step.
On every login and token renewal, Stronghold updates the entity’s external group membership based on Keycloak data.
Verifying login
Log in via the CLI:
d8 stronghold login -method=oidc -path=oidc role=keycloakThe CLI opens a browser for Keycloak login and receives the response at
http://localhost:8250/oidc/callback.Check the policies and metadata of the issued token:
d8 stronghold token lookupTo verify web interface login, select the OIDC method, specify the
keycloakrole if needed, and complete the Keycloak login.
If login fails, check that the redirect URIs match and see the troubleshooting tips in OIDC auth method.