KKIMS on-site docs
Keycloak

Giving people access to the CMS

The two gates every CMS user passes (cms-access with a verified email in Keycloak, and a row on the CMS People screen), how to give access to KIMS and ClinicSpots staff, groups, AD or LDAP accounts, and how the first Admin gets in through KIMS_BOOTSTRAP_ADMINS.

Every person who uses the CMS passes two gates, and both are needed:

Gate Where Who manages it What it decides
1. Keycloak KIMS's Keycloak KIMS's Keycloak admin Who may sign in: an enabled account, with an email, the email verified, and the cms-access role on the CMS client
2. The CMS The CMS's People screen A CMS Admin What they may do: their CMS roles. Stored in PostgreSQL (cms_users), not in Keycloak

There are no CMS passwords and no invitations. A person on the People screen without cms-access cannot sign in; a person with cms-access but not on the People screen is refused too.

#What the CMS checks at sign-in

In this order (apps/cms/src/lib/auth/sign-in.ts):

  1. The ID token and access token verify (signature, issuer, audience, nonce), and both name the same person.
  2. The access token has cms-access in resource_access.<client id>.roles.
  3. The ID token has an email, and email_verified is true.
  4. The People screen has that person: matched by their Keycloak id if they signed in before, otherwise by email (not case sensitive), which then links the Keycloak id to the row.
  5. Their row is active (not suspended).

Any failure shows the CMS login page with: "Your KIMS account does not have access to the CMS. Ask a CMS Admin to add you, or ask IT for CMS access." The exact reason is only in the CMS log (Troubleshooting).

#Make sure emails are verified

The most likely thing to break on KIMS's side. The CMS refuses any sign-in whose token says email_verified: false (or has no email), even with cms-access.

Who does this: KIMS's Keycloak admin.

#For accounts made in Keycloak

Users, the user, Details tab: Email verified must be On. Turn it on and Save for each CMS user whose email KIMS knows is correct.

#For accounts from Active Directory or LDAP

Accounts from User federation arrive with Email verified off unless the provider trusts the directory's emails:

  1. User federation, the LDAP or AD provider.
  2. Find Trust Email (in the provider's settings, usually under Advanced settings) and turn it On.
  3. Save.

From then on, users imported or synchronised from that directory have email_verified: true. Users already imported may need a sync (Action, Sync all users on the provider page) or a fresh sign-in. Check one user afterwards (below).

Also check the provider's email attribute mapper (Mappers tab, email) maps the directory attribute that holds the real address (usually mail).

#For identity brokering (sign-in through another provider)

If KIMS's people sign in to Keycloak through another identity provider (Azure AD, Google), the provider's settings in Keycloak have a Trust Email switch too (Identity providers, the provider). Same rule.

#The Verify Email required action

The alternative is to make people prove their address: Authentication, Required actions, Verify Email enabled, and on a user Required user actions: Verify Email. They get an email with a link at their next Keycloak sign-in. This needs the realm's SMTP settings working (Realm settings, Email). Only use it if KIMS already does.

#Give a person cms-access

Who does this: KIMS's Keycloak admin.

#One person

  1. Users, search for the person, open them.
  2. Role mapping tab, Assign role.
  3. Show client roles: depending on the 26.x version, either choose Client roles from the Assign role menu, or change the filter at the top of the dialog to Filter by clients.
  4. Search cms-access. Tick the row whose client is kims-cms (UAT: kims-cms-uat).
  5. Assign.

The role mapping list now shows kims-cms cms-access.

A group keeps the list of CMS users in one place, and removing someone from it removes their access.

  1. Groups, Create group, Name: kims-cms-users (UAT: kims-cms-uat-users). Create.
  2. Open the group, Role mapping tab, Assign role, client roles, tick kims-cms cms-access, Assign.
  3. For each person: Users, the person, Groups tab, Join Group, tick kims-cms-users, Join.

If people come from AD or LDAP, KIMS can instead map an AD group to this Keycloak group with a group-ldap-mapper on the federation provider, so the directory team manages membership. That is KIMS's choice.

#The first Admin: KIMS_BOOTSTRAP_ADMINS

On day one, the People screen is empty, so nobody could add anybody. KIMS_BOOTSTRAP_ADMINS solves that.

How it works (apps/cms/src/lib/users/): the first time a CMS process opens its user directory (its first request), it checks whether cms_users is empty. If it is, it adds every email in KIMS_BOOTSTRAP_ADMINS (comma separated) as an Admin, under a database lock so two pods do not both do it. If the table has anybody in it, the setting does nothing, so it can stay set.

Steps:

  1. Our engineer: before the first deploy, put the first Admin's KIMS email in the Helm values: env.KIMS_BOOTSTRAP_ADMINS: <FIRST_ADMIN_EMAIL> (several: a@kims...,b@kims...). See Helm values.
  2. KIMS's Keycloak admin: give that person cms-access on the client, and check their Email verified is on.
  3. The first Admin: opens https://<CMS_HOST>/, signs in with their KIMS account.

They land on the CMS dashboard as an Admin. Their name on the People screen is replaced by the name Keycloak knows them by at this first sign-in.

Note

Only the listed emails become Admins. Somebody else who signs in first is not on the People screen and is refused; they do not "take" the Admin role. If the wrong email was listed, see Troubleshooting.

#Add everyone else on the People screen

Who does this: a CMS Admin. Full steps on People.

  1. In the CMS, People, add the person by their KIMS email (the one in their Keycloak account), with their CMS roles.
  2. In Keycloak, give them cms-access (or add them to the group).
  3. They sign in.

The CMS roles, decided only in the CMS, are stored as admin, medical-reviewer, clinical-editor, content-editor, marketing and superadmin. Only admin and superadmin can open the People screen. What each role may do is decided inside the CMS and explained on People; Keycloak knows nothing about them.

#ClinicSpots staff

ClinicSpots people who work on the content need KIMS Keycloak accounts like anybody else: KIMS creates them (or federates them), with a verified email and cms-access, and a CMS Admin adds them on the People screen. There is no separate ClinicSpots login.

#Check a user's token

Clients, kims-cms, Client scopes tab, Evaluate, Users: the person.

Look at Expected
Generated access token "resource_access": {"kims-cms": {"roles": ["cms-access"]}}
Generated ID token "email": "<their email>" and "email_verified": true

Then have them sign in. Expected: the CMS dashboard, showing what their roles allow.

#Taking access away

See Revocation: disable the account or remove cms-access in Keycloak, or suspend on the People screen. Each takes effect on the person's next click.

#If it goes wrong

What they see Likely cause Fix
"Your KIMS account does not have access to the CMS" One of: no cms-access, email not verified, not on the People screen, suspended Read the CMS log line to know which (Troubleshooting)
Keycloak: "Account is disabled" The account is disabled in Keycloak KIMS's admin
Keycloak shows Verify email or Update profile pages before returning Required actions on the account The person completes them; that is Keycloak's flow
Signed in, but cannot see a screen Their CMS roles A CMS Admin changes them on the People screen

#Sources

  • kims-v2/apps/cms/src/lib/auth/sign-in.ts, keycloak.ts (email_verified, resource_access)
  • kims-v2/apps/cms/src/lib/users/index.ts, pg-directory.ts, types.ts (bootstrap, email matching, linking, suspension)
  • kims-v2/apps/cms/src/lib/auth/groups.ts (CMS roles)
  • kims-v2/apps/cms/src/app/login/page.tsx (the messages)
  • kims-v2/docs/CONFIG.md, Keycloak (KIMS_BOOTSTRAP_ADMINS)
  • kims-v2/docs/ON-SITE-DEPLOYMENT.md (main), steps 6 and 7
  • kims-v2/local/keycloak/kims-realm.json (test users with emailVerified and clientRoles; passwords not copied)
  • https://www.keycloak.org/docs/latest/server_admin/index.html (Managing users; Assigning role mappings; Groups; LDAP and Active Directory; Required actions; Identity brokering)
Built 2026-11-29. Commands are shown for the system picked at the top; every block has all three.