CodamAIDocs
Topicdone

The write order

When revoking, Keycloak first; when granting, CIAS first. Why exactly this way round, and what happens if something fails in between.

Variants
Revoke accessGrant accessFailure between the stepsonly in CIAS

What this is about

Many changes to a person must be written in two places: in the CIAS record and in the account in Keycloak. The two writes cannot be put into one shared transaction. If something fails between the two, one place has the new state and the other has the old one.

You cannot prevent this, but you can decide which half-finished state remains. CIAS always picks the safe one.

The two directions

sequenceDiagram
    participant A as Admin
    participant C as CIAS
    participant K as Keycloak
    Note over A,K: Revoke access (suspend, close)
    A->>C: suspend
    C->>K: 1. disable account
    C->>C: 2. save status SUSPENDED
    C-->>A: 200
    Note over A,K: Grant access (reactivate)
    A->>C: reactivate
    C->>C: 1. save status ACTIVE
    C->>K: 2. enable account
    C-->>A: 200

What remains after a failure

Failure between the steps

When: Suspend or close

  1. 1
    CIAS→Keycloak
    disables the account
  2. 2
    CIAS
    saves the new status
    fails: record still shows the old status

Result: The person can no longer sign in, even though the record still shows the old status. Safe. Repeat the call, then the record is correct too.

When: Reactivate

  1. 1
    CIAS
    saves ACTIVE
  2. 2
    CIAS→Keycloak
    enables the account
    fails: account stays disabled

Result: The record says ACTIVE, but the person cannot sign in yet. Safe. Repeat the call.

When: Keycloak does not respond, or responds with a server error.

CIAS aborts and responds with 503 cias.iam.unavailable. When revoking, nothing has been written yet. When granting, the new status is already in the record.

Result: Try again later.

When: Rename, change home tenant, replace CIAS attributes

These changes only affect the record in CIAS and write nothing to Keycloak. There is no second place, so there is no half-finished state.

The table

OperationOrderRemains after a failure in between
suspend, closeKeycloak, then CIASaccount disabled, record still old
reactivate, activateCIAS, then Keycloakrecord ACTIVE, account still disabled
rename, move, CIAS attributesonly CIAS–

Repeating is always safe

You can simply repeat each of these calls. Disabling an account that is already disabled changes nothing. Activating an active person does not either. This is why the repair after a failure is always the same: the same call once more.

There is no background job for users that reconciles record and account on its own. A difference shows up at the next operation on this person.

Next

Sources in the code and the knowledge base
  • CIAS/cias-user – UserService (activate, suspend, close, rename, moveToTenant, replaceAttributes)
  • CIAS/cias-user – UserServiceTest (recordWriteFails, providerUnreachable)
  • CIAS/cias-iam-keycloak – KeycloakAdminApi (error mapping)
  • CIAS/cias-user/docs/adr – ADR-017; CIAS/cias-authorization/docs/adr – ADR-034 §5
Search