Skip to content

Implementation plan / Session plan / Handover RC-1-S28-F16

Handover RC-1-S28-F16 Fix: ess-runtime-decision's sign-in, account, role and policy audit events carry the fields of their category

Card: RC-1-S28-F16. Issue: cema-care/his#222. Branch: session/RC-1-S28-F16. Slice: RC-1. This is a round 1 fix of the gate session RC-1-S28, for the gate line "Criterion 6 (ACC-005): IF-ESS-008; criterion 4: FR-ESS-AUD-001". The work belongs to RC-1-S16 (MOD-ESS-001) and RC-1-S17 (MOD-ESS-002), both in services/ess-runtime-decision. It comes after RC-1-S28-F6. Decision record: ADR-HIS-105. ADR-HIS-101 and 103 are taken by open pull requests and 104 by RC-3-S08 on main, so this record is 105.

The failure

After the gate run, the audit service had quarantined 33 events of ess-runtime-decision as schema-invalid (audit-quarantine.csv):

Type Category (D10-ESS 9.5) Events Missing
ess.iam.sign-in Authentication and session 20 /actorHuman (the account), /authenticationMethod, /locationDevice (device or workstation)
ess.iam.role Administration and configuration 6 /resourceRef/version, /beforeAfter
ess.iam.account Administration and configuration 6 /resourceRef/version, /beforeAfter
ess.auz.policy Administration and configuration 1 /resourceRef/version, /beforeAfter

The issue's comment names two of the three sign-in fields. The quarantine file has a third, /locationDevice, which is fixed too.

There were two causes: - The unit's kit sent change metadata as details, which the intake schema leaves open and the audit service does not keep. It also had no field for the item version. - Sign-ins are read from Keycloak's events with no person in the context. So the events named only this unit as the actor, and neither the method nor where the sign-in came from.

What was changed and where

All in services/ess-runtime-decision:

  • Kit (service-kit/.../kit/audit). AuditRecord gets four fields, with their builder methods:
  • resourceVersion, sent as resourceRef.version;
  • beforeAfter (changed field names, before, after), sent as beforeAfter;
  • account, the account an authentication and session event is about;
  • fields, the top-level category fields (authenticationMethod, locationDevice, approver).

AuditEmitter sends them, as RC-1-S06 did in services/ess-reference's kit. It names account as actorHuman only when no person is in the context, and then names no actorService. details is sent as before. - Test fixtures: kittest.AuditCategoryRules, the audit service's category check for the two categories, with its pointers. - MOD-ESS-001: - support.Audit gets two methods. change gives the item version, the values before and after, the changed fields and the approver. authentication gives the account, the method and the device or workstation. - ess.iam.sign-in: - auth.SignIns: the account; password-otp at aal2, otherwise password; the network address Keycloak saw, as the workstation and as networkAddress (ADR-HIS-105 point 2, by the ruling on #222); - a name no account has: a keyed one-way digest of the name typed, from the new auth.SignOnNameDigest, never the name itself (ADR-HIS-105 point 3, by the ruling on #222). Its key is the new setting his.identity.sign-on-name-digest-key, from the secrets store; - auth.QuickFactor (badge path): badge-pin and the managed device; - ports.IdentityProvider.SignInEvent gets networkAddress, which KeycloakIdentityProvider reads from the event's ipAddress. The 8-argument constructor stays. - ess.iam.account: create, change, manual override, state change and scheduled suspension in account.Accounts; SIP end in account.PractitionerChanges; quarantined source event in feed.SourceEvents. - ess.iam.role: - assignment request, position mapping, routing, approve, reject, revoke, suspend, expire and reinstate in role.Assignments. An approval names its approver; - campaign open and close, item routing, decisions and default actions in recert.Campaigns. A decision names its reviewer as approver. - MOD-ESS-002 policy.PolicyVersions: ess.auz.policy (starter installed, approved, activated, rolled back) names the policy version. Its before and after are the version in force, its state and effective time, and the content by its hash. - README.md: the support row of MOD-ESS-001.

No dependency was added and no lockfile changed. No contract changed: every field is in AuditEventSubmission.v1. No migration: the versions were already kept.

The test that fails before and passes after

mod-ess-001/.../AuditCategoryTest (new, 5 tests) and mod-ess-002/.../PolicyVersionTest.policyChangesAuditedWithVersionAndValues (new) cause the events and check each one with AuditCategoryRules. They also check the values.

Case On main After
Sign-ins from the identity provider (failure, aal2, aal1): account, method, the network address as workstation, no service as actor failed: ["/actorHuman", "/authenticationMethod", "/locationDevice"] passes
A failed sign-in with a name no account has, and a password typed as a name: a digest of the name typed, never the name, the same for repeats failed, the same passes
Badge path sign-in and closure: account, badge-pin, device failed, the same passes
Account create, change, suspension: version, before and after, changed fields failed: ["/resourceRef/version", "/beforeAfter"] passes
Role assignment request, approval, campaign, recertification decision: version, before and after, approver failed, the same passes
Policy starter, approval, activation: version, before and after, content hash failed, the same passes

"On main" ran the new tests on origin/main's code in a scratch worktree, with the sign-in event built without its network address: 6 tests, 6 failed, with the gate's pointers.

AccountLifecycleTest.manualOverride read the before and after values from details. It now reads them from beforeAfter, where they now are and where the audit service keeps them. What it checks is unchanged.

Review round 1: two older tests made independent of the host's load. The pipeline's first build of this pull request failed on two tests this change does not touch. Both failed on a time limit at a load where requests answered late: - service-kit HttpPolicyDecisionClientTest.permit failed because its client allowed 300 ms, and the first, cold request took longer. It failed the same way on this host at a load average of 24. The client now has 2 s, and the late reply of failsClosed waits twice that, so the timeout case is still tested. - app DecisionWithIdentityTest: one decision of each test came back as the outage refusal, which has no outcome, because OPA answered later than the 200 ms decision budget. The test now sets his.authz.opa-timeout to 2 s. It checks what is decided, and mod-ess-002 PolicyEngineWarmUpTest keeps checking the budget.

Only the tests changed. The 200 ms budget and every other production default stay as they were. After the fix the whole unit was built again (./gradlew cleanTest build --continue --no-build-cache) at a load average of 30 to 40: - service-kit 31, mod-ess-001 94, mod-ess-003 39 and app 7 passed with no failure; - mod-ess-002 failed 59 of 101 tests, all on the outage refusal (503) of a late OPA.

That module passed the first pipeline run. It fails the same way on origin/main at the same load: 4 failures at a load of 14, against 3 for this branch at 9.

Review round 2: MOD-ESS-002's tests made independent of the host's load. The pipeline then failed in mod-ess-002 itself (DecisionOutageTest, PolicyDecisionTest): late OPA answers were refused as outages. The pull request cannot merge on a failing pipeline, so the follow-up is done here. OpaInitializer, which every Spring test of the module uses, now sets his.authz.opa-timeout to 2 s, as DecisionWithIdentityTest does. Two tests keep checking what the 200 ms budget does: - engine.PolicyEngineWarmUpTest holds the budget with its own client; - DecisionOutageTest pauses OPA, so every call there times out whatever the budget.

Again, only the tests changed.

Checks and their results

The integration environment ran as HIS_SESSION=RC-1-S28-F16 (his-rc-1-s28-f16): light profile for the unit, full for the scenario. Other sessions ran on the same host throughout.

Check Command Result
New tests ./gradlew :mod-ess-001:test --tests '*AuditCategoryTest' :mod-ess-002:test --tests '*PolicyVersionTest' 12 tests, all passed (6 failed on main, above)
Build and every test of the unit, the gate's command ./gradlew cleanTest build --continue --no-build-cache in services/ess-runtime-decision Passed: service-kit 31 (1 skipped), mod-ess-001 94 (3 skipped, the Keycloak adapter tests of the full profile), mod-ess-002 101, mod-ess-003 39, app 7
Static analysis platform/delivery-pipeline/bin/static-analysis services/ess-runtime-decision No blocking finding
Dependency scan and SBOM platform/delivery-pipeline/bin/dependency-scan services/ess-runtime-decision 0 blocking (6 medium, as before: no dependency changed)
Secret scan platform/delivery-pipeline/bin/secret-scan code origin/main HEAD, and docs No secret; no exception file added
Documentation check_links.py; mkdocs build 0 broken links; the site builds (one warning, in RC-1-S12's handover, was there before)
Slice scenario, run 1 (20261129T220257Z-a0f0) HIS_SESSION=RC-1-S28-F16 e2e/harness/scenario run e2e/scenarios/RC-1, full profile, after CI=true pnpm install --frozen-lockfile in contracts/common, ess, adm and ise 9 of 15 passed. Load average 14 to 21
Slice scenario, run 2 (20261129T222551Z-71f5), from his-env reset the same 11 of 15 passed. Load average 24 to 32
The gate line's check: the audit quarantine after each run psql on ess_audit: mod_ess_006.quarantine_entry by source, reason and type, and audit_event of ess-runtime-decision by type None of the four types is quarantined. Accepted and stored, run 1 and run 2: ess.iam.sign-in 12 and 13, ess.iam.account 6 and 6, ess.iam.role 6 and 6, ess.auz.policy 1 and 1

The scenario's failures. None of them comes from this change, and none involves an audit event of this unit. The records stay in the run folders, which git ignores. - RC-1-E2E-006, 009 and 014 failed in both runs, and 010 and 011 in run 1. Each met "Authorization service unavailable" (503) or the screen's "Access cannot be checked right now": - the decision engine (OPA) did not answer within its 200 ms budget at that load: ess-runtime-decision's log has 308 "policy engine unavailable" warnings in run 2; - RC-1-S28-F6 saw the same with RC-1-E2E-003 and 006 at a load average of 13. - RC-1-E2E-010 and 011 in run 1 then failed in registerAndOpen, reading the prompts of a duplicate check that had answered an error (RC-1-S28-F6's follow-up for the scenario). Both passed in run 2. - RC-1-E2E-015 failed in both runs on ess-governance's own audit events. They lack the version and before and after values, which is fix RC-1-S28-F12. It also met a 503 in run 2.

The change touches only what the audit events carry, not the decision path. So the scenario has not regressed from this change. It still needs a run on a quiet host to pass in full. That run is the next gate session's (RC-1-S28-G2), as the card says.

Requirements and test scenarios of the card

Requirement, scenario Test
FR-ESS-AUD-001 part 7, the category fields of D10-ESS 9.5: authentication and session AuditCategoryTest.signInFromTheIdentityProvider, signInOfAnUnknownName, badgePath (tags FR-ESS-AUD-001, FR-ESS-IAM-002, TEST-ESS-002)
FR-ESS-AUD-001 part 7, administration and configuration; FR-ESS-IAM-001 part 12 (before and after values) AuditCategoryTest.accountChanges (TEST-ESS-001); AccountLifecycleTest.manualOverride
FR-ESS-AUD-001 part 7, administration and configuration; FR-ESS-IAM-004 part 12 AuditCategoryTest.roleChanges (TEST-ESS-004)
FR-ESS-AUD-001 part 7, administration and configuration; FR-ESS-AUZ-001 (policy version change) PolicyVersionTest.policyChangesAuditedWithVersionAndValues (TEST-ESS-005)
IF-ESS-008, the audit intake (gate criterion 6, ACC-005) The quarantine after the slice scenario, above

What the gate line now shows. The line is "Criterion 6 (ACC-005): IF-ESS-008; criterion 4: FR-ESS-AUD-001". - This unit's share of it is repaired for ess.iam.account, ess.iam.role and ess.auz.policy. After two runs of the slice scenario, the audit service holds all of this unit's events of those types and quarantines none of them. At the gate, 33 events were quarantined. - ess.iam.sign-in is repaired too. Review round 3 removed two readings of the specification and asked about them on #222. The ruling there brought the network address back as the workstation, so a known account's sign-in is recorded exactly as in the two scenario runs, where all of them were accepted. A failed sign-in with an unknown name now names the digest of the name typed in place of the name. The scenario has no such sign-in, so AuditCategoryTest.signInOfAnUnknownName covers it. The scenario was not run again for this, because its sign-ins carry the same fields as before. - This unit still has one other type in the quarantine: ess.iam.service-identity-misuse (6 in run 1, 4 in run 2). It is the Security category and lacks affectedComponent. It is outside this card and was not in the gate's quarantine (follow-up below). Its access-check-unavailable events (2 in run 2) are an unregistered type, which is fix RC-1-S28-F14 (#220). - The line stays failed until the other emitters' fixes land: RC-1-S28-F12 (ess-governance), F14, F17 (ess-reference), F18 (adm-patient-administration) and F19 (ess-coordination). adm-identity, the gateways and the event backbone still have rows too. The next gate session, RC-1-S28-G2, records the line again.

Done differently from the specification or contract

Nothing differs from the specification. The specification leaves three points open: - The method comes from the assurance (ADR-HIS-105 point 2). It is password-otp at aal2, otherwise password. - The workstation of a sign-in at Keycloak is its network address, by the ruling on #222 for the Security and Privacy Office. Review round 3 asked for this to be ruled on rather than decided in the code. - A failed sign-in with a name no account has names a keyed digest of the name typed, also by the ruling on #222. It is the one value in actorHuman that is not a DE-ESS-001 account_id. The contract's field is a string, and its description names the account. The prefix unknown-account:hmac-sha256: keeps the digest apart from account identifiers. The contract text could say so in its next revision (follow-up).

Questions and follow-ups

  • Answered on #222: the workstation is the network address, and an unknown name is recorded as a digest. Both are implemented in this pull request.
  • Each deployment must set his.identity.sign-on-name-digest-key in the secrets store (deployment topology and secrets units). Without it, a random key of the run is used, and digests compare only until the unit restarts.
  • AuditEventSubmission.v1 describes actorHuman as an account_id. For the ESS contract session: add that an authentication failure with no account carries the unknown-account:hmac-sha256: digest. The change is backward compatible: the schema is unchanged and only the description changes.
  • The other types of the two categories in this unit are outside this card. They still use the old Audit.record, so the audit service will quarantine them once they occur. The gate run had none.
  • Authentication and session: ess.iam.block, session, factor, second-person. Events from Keycloak or the badge path can take Audit.authentication as the sign-ins now do. Those that come through the API (unblock, factor reset, session revocation, second-person, PIN set) need the caller's workstation or device. identity.v1 does not carry it yet, so that is a contract change for the ESS contract session (a workstation or device header, or a body field).
  • Administration and configuration: ess.iam.service-identity, ess.auz.app-grant, and ess.cfg.item of MOD-ESS-003. Each can take Audit.change (or the kit's resourceVersion and beforeAfter) with its record's version.
  • The owner of the unit should do these as one fix, with a test like AuditCategoryTest for each type.
  • ess.iam.service-identity-misuse (Security category) lacks affectedComponent, so it is quarantined (ServiceIdentities.misuse). The kit's fields now carries it, for example the decision service or the board the identity asked for. This is for the unit's owner, with the types above.
  • Approver of a policy version. The approval is ess-governance's, and ConfigurationChanged does not name who approved. So ess.auz.policy.approved names the configuration item, not the approver. If the event gains the approver, this unit can name it.
  • The service template (services/_template) should get the kit's fields too: resourceVersion, beforeAfter, account and fields. Every unit now adds them one at a time.