Who acts: our engineer reads the CMS log and finds the cause; KIMS's Keycloak admin fixes Keycloak settings; a CMS Admin fixes People screen entries.
#Read the CMS log
The login page shows a short, general message on purpose. The exact reason is in the CMS's log, on lines starting [cms]:
kubectl -n kims logs -l app.kubernetes.io/component=cms --since=15m --prefix | grep "\[cms\]"kubectl -n kims logs -l app.kubernetes.io/component=cms --since=15m --prefix | grep "\[cms\]"kubectl -n kims logs -l app.kubernetes.io/component=cms --since=15m --prefix | Select-String -SimpleMatch "[cms]"The label selects every CMS pod (the chart runs two by default), and --prefix says which pod each line came from. A sign-in's lines are on whichever pod served it.
#Log lines and what they mean
| Log line | Meaning | Go to |
|---|---|---|
[cms] sign-in refused: no-access (no access role) |
The access token has no cms-access for this client |
No roles in the token |
[cms] sign-in refused: no-access (email missing or not verified) |
email_verified is false, or no email |
Email not verified |
[cms] sign-in refused: no-access (directory: unknown) |
Not on the People screen | Not on the People screen |
[cms] sign-in refused: no-access (directory: suspended) |
Suspended on the People screen | A CMS Admin reactivates them |
[cms] sign-in refused: no-access (directory: conflict) |
Their email's People row is linked to a different Keycloak account | Conflict: account recreated |
[cms] code exchange failed followed by Keycloak token endpoint returned 401: unauthorized_client or invalid_client |
Wrong client secret, or client authentication off | Wrong client secret |
[cms] code exchange failed ... invalid_grant ... Code not valid |
The code was used twice or expired | Code not valid |
[cms] code exchange failed ... PKCE verification failed |
Verifier and challenge differ (a proxy rewriting cookies) | PKCE errors |
[cms] sign-in refused: exchange-failed (... "iat" claim timestamp check failed ...) or "exp" claim timestamp check failed |
Clocks differ between the pod and Keycloak | Clock skew |
[cms] sign-in refused: exchange-failed (unexpected "iss" claim value) |
Tokens are issued for another issuer than KEYCLOAK_ISSUER |
Issuer mismatch |
The realm says its issuer is "...", and KEYCLOAK_ISSUER is "..." |
Discovery's issuer differs from the setting | Issuer mismatch |
Could not reach https://.../.well-known/openid-configuration |
The pod cannot reach Keycloak | Keycloak unreachable |
[cms] access check unavailable |
Keycloak or the database could not be asked during a session check | Could not confirm your access |
[cms] back-channel logout refused: <reason> |
A logout token failed verification, or a test call | Revocation |
KEYCLOAK_ISSUER is not set (or another variable) |
The Helm values miss a setting | Helm values |
#What the person sees, and where to look
| On screen | Comes from | Most likely |
|---|---|---|
| Keycloak page: We are sorry... Invalid parameter: redirect_uri | Keycloak | Invalid redirect URI |
| Keycloak page: Client not found. | Keycloak | KEYCLOAK_CLIENT_ID does not match the client, or wrong realm in KEYCLOAK_ISSUER |
| Keycloak page: Account is disabled, contact your administrator. | Keycloak | The account is disabled |
| CMS: Your KIMS account does not have access to the CMS. Ask a CMS Admin to add you, or ask IT for CMS access. | no-access |
The log line says which gate |
| CMS: KIMS sign-in refused the sign-in. Try again, or ask IT to check your account. | exchange-failed |
Secret, clock, issuer |
| CMS: This sign-in took too long, or started in a different browser. Try again. | no-handshake |
More than 10 minutes on Keycloak's page, or cookies blocked |
| CMS: The sign-in did not start here. Nothing has been signed in. Start again from this page. | state-mismatch |
Two sign-ins in two tabs at once; or an old bookmark of Keycloak's page |
| CMS: Sign-in was cancelled. | access_denied from Keycloak |
The person declined consent, or Keycloak denied |
| CMS page Could not confirm your access, so nothing was done | access-unavailable |
Could not confirm your access |
| The browser goes back and forth between the CMS and Keycloak | Sign-in loop |
#Invalid redirect URI
Cause: the CMS sends redirect_uri=<CMS_URL>/api/auth/callback/keycloak, and the client's Valid redirect URIs does not allow it. Usual reasons: CMS_URL has http:// or a different host than the client was set up with; a trailing slash; a port.
Fix: compare env.CMS_URL in the Helm values with Clients, kims-cms, Settings, Valid redirect URIs. They must agree exactly, for example https://<CMS_HOST> and https://<CMS_HOST>/api/auth/callback/keycloak. Change whichever is wrong (KIMS's admin for the client; the values file and a kims-platform run for CMS_URL).
#No roles in the token
Cause, in order of likelihood:
- The person does not have
cms-accesson this client (it is on the UAT client, or is a realm role of the same name). - The
rolesclient scope is Optional or missing on the client. The CMS asks only foropenid email profile, so an Optional scope is never included. - The realm's
rolesscope client roles mapper has Add to access token off. KEYCLOAK_ACCESS_ROLEin the Helm values differs from the role's name, orKEYCLOAK_CLIENT_IDdiffers from the client ID (the CMS looks underresource_access.<KEYCLOAK_CLIENT_ID>).
Check: Clients, kims-cms, Client scopes, Evaluate, the person, Generated access token: it must contain "resource_access": {"kims-cms": {"roles": ["cms-access"]}}.
Fix: Client scopes and Give a person cms-access.
#Email not verified
Cause: the account's email_verified is false. Almost always accounts from Active Directory or LDAP when the provider does not trust the directory's emails.
Check: Evaluate, the person, Generated ID token: "email_verified": true.
Fix: Make sure emails are verified: Trust Email on the federation provider, or Email verified on the user.
#Not on the People screen
Cause: the person has cms-access but no CMS Admin has added them, or they were added under another email than their Keycloak account's.
Fix: a CMS Admin adds them by the exact email Keycloak has (case does not matter). Check the email with Evaluate, Generated ID token, email.
#Conflict: account recreated
Cause: the person's People row was linked to their old Keycloak account at their first sign-in. Their Keycloak account was then deleted and recreated (a new internal id), so the same email now arrives with a different id, and the CMS refuses rather than hand the old account's access to a new one.
Fix: the link must be cleared in the database by someone with database access, for that one row, then the person signs in again and is linked afresh:
UPDATE cms_users SET keycloak_sub = NULL WHERE email = '<PERSON_EMAIL>';Run it with psql against the environment's database (Database tools). Check first that the recreated account really is the same person.
#The first Admin cannot get in
| Symptom | Cause | Fix |
|---|---|---|
"no access", log says no access role or email ... not verified |
Keycloak side | Give cms-access, verify the email |
"no access", log says directory: unknown |
Their email was not in KIMS_BOOTSTRAP_ADMINS when the CMS first started, or was misspelled |
If nobody is on the People screen yet: correct KIMS_BOOTSTRAP_ADMINS in the values file, update kims-helm-values, rerun kims-platform (the new pods add them). If the table already has people, a CMS Admin adds the person instead |
| Nobody at all can open the People screen | KIMS_BOOTSTRAP_ADMINS was empty and the table is empty |
Same as above: set it and redeploy |
KIMS_BOOTSTRAP_ADMINS has a wrong email, and the table is no longer empty |
The wrong address became an Admin row that nobody can use | Add the right person with SQL, as an Admin: INSERT INTO cms_users (email, display_name, roles) VALUES ('<EMAIL>', '<EMAIL>', ARRAY['admin']); then they sign in. Suspend the wrong row from the People screen |
#Wrong client secret
Cause: the kims-keycloak Secret's client-secret is not the client's current secret (copied wrongly, from the UAT client, or the secret was regenerated), or Client authentication is off on the client.
Fix: KIMS's admin copies the current secret from Clients, kims-cms, Credentials, and it is put into the Secret (Secrets). Then restart the CMS so it reads it:
kubectl -n kims rollout restart deploy/kims-cms deploy/kims-worker
kubectl -n kims rollout status deploy/kims-cmskubectl -n kims rollout restart deploy/kims-cms deploy/kims-worker
kubectl -n kims rollout status deploy/kims-cmskubectl -n kims rollout restart deploy/kims-cms deploy/kims-worker
kubectl -n kims rollout status deploy/kims-cmsYou should see deployment "kims-cms" successfully rolled out.
#Code not valid
Cause: an authorization code works once and for about a minute. Seen when the person pressed Back into the callback, double-submitted, or the callback took too long.
Fix: sign in again from the CMS login page. If it happens to everyone, check clocks (Clock skew) and that only one CMS host name is used.
#PKCE errors
Cause: the CMS keeps the PKCE verifier in a short-lived cookie (kims_cms_oauth, 10 minutes). If the callback arrives without it (a different host name than the one the sign-in started on, a proxy stripping cookies, the browser blocking them), there is no verifier, or the wrong one.
Fix: the CMS must be reached on exactly the host in CMS_URL; the ingress or proxy must pass cookies through. On Keycloak, PKCE Method S256 is correct and needs no change.
#Issuer mismatch
Cause: KEYCLOAK_ISSUER is not character for character what Keycloak reports as its issuer. Typical differences: http against https, a trailing slash, /auth/realms/... on an old Keycloak, the realm name's case, or Keycloak reporting an internal host name because its hostname setting is not set for outside callers.
Check: Read the version and the issuer, and the in-cluster check on the same page.
Fix: set KEYCLOAK_ISSUER to exactly what discovery says, if that address works from the pods and the browser. If discovery reports an internal host, KIMS's Keycloak admin fixes Keycloak's hostname configuration (hostname option, Keycloak 25 and later: the full public URL, for example https://<KEYCLOAK_HOST>); that is a change to their Keycloak server, for them to schedule.
#Clock skew
Cause: the CMS checks token times with no tolerance. A CMS node or Keycloak server whose clock is off by more than a second or two fails token checks.
Check: compare the time on a CMS pod and on a Keycloak server:
kubectl -n kims exec deploy/kims-cms -- node -e "console.log(new Date().toISOString())"; date -u +%Y-%m-%dT%H:%M:%SZkubectl -n kims exec deploy/kims-cms -- node -e "console.log(new Date().toISOString())"; date -u +%Y-%m-%dT%H:%M:%SZkubectl -n kims exec deploy/kims-cms -- node -e "console.log(new Date().toISOString())"; (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")KIMS's admin runs date -u on a Keycloak server at the same moment. They should agree to the second.
Fix: time sync (NTP or Amazon Time Sync) on whichever is wrong. Nothing in the CMS loosens it.
#Keycloak unreachable from the pods
Cause: no network path from the EKS pods to Keycloak on 443, DNS for the Keycloak host not resolvable inside the VPC, or a proxy needed.
Check: the in-cluster test on Client. FAILED ENOTFOUND is DNS; FAILED ETIMEDOUT or UND_ERR_CONNECT_TIMEOUT is the network.
Fix: KIMS's network team opens the path (Networking, Outbound access).
#Certificate errors
Cause: Keycloak's certificate is signed by KIMS's internal CA, which the CMS image does not trust. The in-cluster test prints FAILED UNABLE_TO_VERIFY_LEAF_SIGNATURE or SELF_SIGNED_CERT_IN_CHAIN.
Fix: Node.js trusts extra CAs from the file in NODE_EXTRA_CA_CERTS. The Helm chart on main has no value for mounting such a file into the pods, so this needs a small chart change: raise it with us before the deploy. Do not turn off certificate checks.
#Could not confirm your access
Cause: during a normal session check, the CMS could not ask Keycloak (unreachable, a 5xx, the introspection endpoint refusing the client) or its database. Nothing is deleted; the person can try again.
Check: the log line [cms] access check unavailable and the error after it. Keycloak introspection answered 401 means the client secret is wrong (Wrong client secret). A fetch error means the network.
Fix: as the error says. When Keycloak is back, the next click works without signing in again.
#Sign-in loop
Cause, most likely first:
- The CMS is served over
http://: the session cookie isSecurein production builds and the browser drops it on plain HTTP, so every page sends the person to sign in again. Usehttps://end to end, andCMS_URLwithhttps://. CMS_URLis a different host from the one in the browser, so the cookie is set for one host and read on another.- Two CMS host names in use (an old alias). Use only
CMS_URL's.
Check: browser developer tools, Application (or Storage), Cookies: after signing in, kims_cms_session must be there for the CMS host.
#Sources
kims-v2/apps/cms/src/lib/auth/keycloak.ts,sign-in.ts,gate.ts,guard.ts,config.ts,cookie.ts,errors.tskims-v2/apps/cms/src/app/api/auth/callback/keycloak/route.ts,signin/route.ts,backchannel-logout/route.tskims-v2/apps/cms/src/app/login/page.tsx(the messages)kims-v2/apps/cms/src/lib/users/pg-directory.ts(matching, conflict, bootstrap)kims-v2/docs/CONFIG.md, Keycloakkims-v2/docs/ON-SITE-DEPLOYMENT.md(main), "If something goes wrong"kims-v2/deploy/helm/kims/values.yaml(main)- https://www.keycloak.org/docs/latest/server_admin/index.html
- https://www.keycloak.org/server/hostname
- https://nodejs.org/api/cli.html#node_extra_ca_certsfile
- https://github.com/panva/jose (JWT claim checks)