CodamAIDocs
Topicdone

Reconciliation with Keycloak

At startup and at the push of a button, CIAS brings roles, profile attributes, claim mappers and the names of the sign-in levels in Keycloak up to date, and reports sign-in levels the login does not reach. Why Keycloak first and then the catalog, and why nothing is ever deleted but retired instead.

Variants
at startupon requestnew rolewithdrawn role → retiredrequired attribute without default → rejectedsign-in level reachablesign-in level unreachable or not checkable → reported

What this is about

Modules register their roles and attributes, see Modules register their roles. For this to have any effect, someone has to bring Keycloak and the catalog up to date. The reconciliation does that. It writes four things:

  • the names of the sign-in levels in the realm, so that Keycloak writes them into the token
  • the user profile in Keycloak: which attributes an account can have
  • the client roles and the claim mappers per module. A claim mapper makes sure that an attribute arrives in the client’s token
  • the catalog in CIAS

It also checks whether the sign-in sequence in Keycloak reaches every sign-in level a module requires.

When it runs

OccasionHowWho
at startupafter startup, when codamai.cias.authorization.startup.enabled=truethe application itself
on requestPOST /cias/admin/roles/reconcileonly a platform administrator, otherwise 403

There is no timer, on purpose. In Keycloak, the user profile is one document that is replaced completely on every write. Two runs at the same time would overwrite each other. So only one run runs at a time within a process: whoever presses the button while a run is going gets back a report “already running”, and nothing happens twice.

At startup, before the reconciliation, CIAS also creates the realm roles that the installation names in its configuration (startup.realm-roles, for example user). These never come from a declaration.

Three phases: read, reject, write

One run
  1. 1
    CIAS
    read: query every configured declaration; a module that cannot be reached is noted and otherwise left alone
  2. 2
    CIAS→Keycloak
    sign-in levels: write the names of the levels, then compare the required levels with the reachable ones
    This happens before all rejections and independently of them. An unreachable level is reported but holds nothing up.
  3. 3
    CIAS
    reject: faulty declarations drop out, attribute conflicts stop the whole run, key collisions stop their client
  4. 4
    CIAS→Keycloak
    write 1: the user profile, once for all modules
  5. 5
    CIAS→Keycloak
    write 2: per module, create missing client roles, then the claim mappers
  6. 6
    CIAS
    write 3: per module, the catalog, in its own transaction
    Result: One report per module: what was created, changed, retired, reinstated

First read everything, then check everything, then write. A run that already wrote while reading would apply a conflicting configuration halfway, and afterwards nobody would know which half. The rejections in detail are described in When CIAS does not accept a declaration.

Keycloak first, then the catalog

Keycloak and CIAS have no shared transaction. If something fails between the two, one half is left alone. The order decides which one:

What is left when the run fails in the middle

When: The role is created in Keycloak, the catalog is not written anymore.

A role without holders in Keycloak changes nothing for anyone. The next run adds it to the catalog.

Result: harmless

When: The role is in the catalog but missing in Keycloak.

An administrator grants it, CIAS stores the grant, and the token still does not carry the role.

Result: a permission that CIAS offers and cannot deliver

If creating in Keycloak fails for a module, the report shows it as UNPROVISIONED, and its catalog stays unchanged, including renames and retirements. The next run catches up on everything at once, because every step can be repeated.

What happens to a module’s roles

Before and after, per role

When: The module registers order-export, the catalog does not know it.

Created in Keycloak, entered in the catalog: owner is the module, scope TENANT, delegation from the installation's configuration.

Result: in the report under defined

When: The module registers order-edit with a new display name.

Display name and display group are taken over. Description and delegation stay as an administrator set them. The module says nothing about those.

Result: in the report under updated

When: The module no longer registers order-archive.

The role is retired, with date and time. It stays in Keycloak, and all grants stay. It can no longer be granted again.

Result: in the report under deprecated

When: The module registers a retired role again.

The retirement is lifted. The grants were never gone, so nothing has to be given back.

Result: in the report under reinstated

When: The module does not answer.

Nothing changes, not even a retirement. A role is never retired just because its service is restarting.

Result: UNREADABLE

Why retire instead of delete: if CIAS deleted a withdrawn role, every person who has it would lose their permission, just because a module cleaned up its list. And nobody could check later that the role ever existed.

Only what belongs to this module is retired. If several modules share a client, the silence of one never retires the roles of the other. Roles without an owner, for example the installation’s realm roles, are never retired by a reconciliation.

Attributes

The same principle applies to attributes, only stricter:

  • An attribute that no module registers anymore stays in the user profile. Deleting it would destroy the value in every account. A role is a permission, an attribute is content.
  • CIAS rejects a required attribute without a default value, together with the whole declaration of this module. Otherwise, accounts that existed before would have no value. The profile would then claim that such accounts cannot exist, and after that Keycloak would even refuse changes to these accounts, including suspending them.

More in Registering attributes.

Unreachable sign-in levels

A module can require sign-in levels in its declaration, such as mfa. Which factors Keycloak asks for, however, is set by the operator in the realm’s browser flow, the sign-in sequence. If the step for a level is missing there, Keycloak silently issues a token with the lower level. So that this is not first noticed by a person who is sent to sign in again and again, every run checks the levels:

  1. It writes the names basic, mfa and phishing-resistant into the realm’s ACR-to-LoA mapping. It does this always, even when no module requires more than basic. Only the names make sure that the token carries CIAS’s levels.
  2. It reads which levels the browser flow can reach and compares every required level with them. basic is never compared. Being signed in is exactly what basic means.

How CIAS reads and writes both in Keycloak is described in The Keycloak adapter.

What the run does with a required level

When: The browser flow has an enabled step for the level.

Nothing to report.

Result: unreachableLevels is empty

When: The browser flow has no step for the level.

The report names module and level under unreachableLevels, and there is an error in the log. The module's roles and attributes are applied anyway, its status stays RECONCILED. The start is never refused.

Result: Only the operations that require this level refuse, until the step is there

When: Keycloak cannot be asked, or the identity provider cannot say which levels its login reaches.

Every required level above basic counts as not reachable and is in the report with the reason. CIAS never assumes that a level will be reachable.

Result: Reported as above

Why the module is not rejected: the defect is not in the declaration. The module truthfully says what it needs. What is missing is a step in the sign-in sequence. If CIAS rejected the module, all its roles would be missing and every one of its operations would be locked, including those that require no level at all.

Fixing without a restart: the operator adds the step to the browser flow, with “Condition – Level of Authentication” and the level’s number (mfa 2, phishing-resistant 3), and requests a reconciliation (POST /cias/admin/roles/reconcile). The next run reads the flow again, and the entry is gone.

The report

Request
POST /cias/admin/roles/reconcile
Authorization: Bearer <token of a platform administrator>
Response
{
  "applied": true,
  "modules": [
    { "module": "cias", "client": "cias-backend", "status": "RECONCILED",
      "provisioned": [], "defined": [], "updated": [],
      "deprecated": [], "reinstated": [], … },
    { "module": "cdms", "client": "cdms-backend", "status": "RECONCILED",
      "provisioned": ["cdms-backend/order-export"],
      "defined": ["cdms-backend/order-export"],
      "deprecated": ["cdms-backend/order-archive"], … }
  ],
  "attributes": [],
  "refusals": [],
  "unreachableLevels": [
    "cdms requires the authentication level 'mfa', which the login cannot reach: its flow has no step for it"
  ]
}
StatusMeaning
RECONCILEDread, created in Keycloak, catalog written
UNPROVISIONEDcreating in Keycloak failed, catalog unchanged
UNREADABLEmodule could not be queried, nothing changed
REJECTEDdeclaration not acceptable, none of it applied
REFUSEDkey collision on the client, nothing written on this client
SKIPPEDthe whole run wrote nothing, the reason is in refusals

The report always shows roles as client/key, because the key alone no longer says which role is meant.

unreachableLevels has one entry per module and level, see Unreachable sign-in levels. A report with such an entry does not count as complete, even if every module is RECONCILED.

Pitfalls

Next

Search