Skip to content

Implementation plan / Session plan / Handover RC-1-S17

Handover RC-1-S17 Build: Runtime decision services (part 2 of 2)

Card: RC-1-S17. Issue: cema-care/his#31. Branch: session/RC-1-S17. Slice: RC-1. Decision record: ADR-HIS-065.

What was built and where

MOD-ESS-002 in services/ess-runtime-decision/mod-ess-002. It is the policy decision service of FR-ESS-AUZ-001 and serves all five operations of policy-decision.v1 (IF-ESS-003) at their contract paths: - decide, decideBatch (up to 500, one decision each) and decideSearchFilter (clauses for the caller's query); - readDecision (the stored decision with its request and trace); - listPolicyVersions.

It publishes PolicyUpdated (EVT-ESS-003) on his.ess.policy.v1 through the outbox, with aggregate Policy = policyId, enterprise-scoped.

  • The engine is Open Policy Agent (technology stack row 11). It runs as a sidecar and the unit calls its REST API (ADR-HIS-065 point 1).
  • The image is openpolicyagent/opa:1.22.3-static, pinned by digest.
  • The evaluator policy/his_authz.rego is code.
  • A policy version is data: resource types and actions, rules, emergency access roles.
  • The unit loads both into OPA and loads them again after an OPA restart.
  • An OPA that does not answer within 200 ms is an outage, answered as 503.
  • The decision (parts 6.1 to 6.8):
  • Subject attributes come from MOD-ESS-001's api, read at decision time (part 6.2, DEC-ESS-008): state, organizational unit and locations, the roles in force at the request's facility (privileged ones only at aal2), and a service identity's scopes.
  • Before the rules, the unit checks the session (state, revocation, maximum lifetime), a service identity's environment and display limits, and the transaction-level segregation of duties on attributes.earlierActors.
  • Then the rules:
    • deny by default;
    • an explicit deny prevails;
    • a missing attribute is a missing-attribute trace step;
    • a Deny of a patient's clinical record becomes deny-override-available for the Break-the-Glass permitted roles of CFG-ESS-006 (physicians, nurses and midwives, pharmacists, allied health professionals; not students or supervised practitioners);
    • obligations, with step-up where a rule needs a second factor the session lacks (CFG-ESS-001).
  • The cache lifetime is bounded by CFG-ESS-009 (60 s) and is 0 for a Deny.
  • Every decision is stored, immutable (mod_ess_002.decision; update and delete are refused).
  • Every Deny, and the Permits of rules marked auditPermit, is audited as ess.auz.decision in the same transaction. The subject is the actor, the calling service the one acting for them, and the request's purpose and facility are carried.
  • The last use of the assignments a Permit relied on goes to MOD-ESS-001 in batches.
  • Policy versions (parts 6.9, 11; DE-ESS-004):
  • ConfigurationChanged of ess.authorization-policy and ess.privacy-label-taxonomy is consumed in order per item. The content is read with readConfigurationVersion, and its hash is checked against the event.
  • A version applies from its effective time. A decision uses the version in force at its own time.
  • The activation job makes it Active, makes the one before it Superseded, and publishes PolicyUpdated in the same transaction. A rollback reactivates the version it names.
  • A version number is never reused with other content.
  • The starter content is not approved. It is installed, once, only where a deployment sets his.authz.seed-enabled (off by default, ignored in production), under its own identifier enterprise-access-starter, so it never takes a version number of the governed policy. It decides only while no governed version is in force. Without it, and without a governed version, every decision is 503 (ADR-HIS-065 point 3; review round 1).
  • The starter content for enterprise-access version 1 (policy/enterprise-access.v1.json), to be taken through the configuration lifecycle:
  • 87 rules over 53 resource types, for the RC-1 units that exist: MOD-ESS-001, MOD-ESS-002 itself, ess-reference, ess-governance, ess-coordination, ess-audit, adm-identity, the gateways' ise.ApiOperation and network isolation;
  • the clinical record rules of D03-CLI 9.2, for the AC-01 and AC-02 example;
  • facility scoping as architecture 7.5 sets it, in the evaluator's facility-scope step:
    • a facility-owned resource type (marked facilityOwned, now adm.Encounter and adm.Registration) is seen only from its own facility, and needs owningFacility for actions on an existing record. Absent, the request is denied;
    • the longitudinal clinical record is enterprise-scoped: clinical access crosses facilities under a care relationship and purpose of use, with Break-the-Glass otherwise;
    • a clinical record view names the facility of its entry (owningFacility, the provenance of 7.5). Absent, it is denied (clinical-record-provenance);
    • across facilities both legal entities are required, and across different legal entities the record is not shown (clinical-record-other-legal-entity). A missing legal entity is a Deny. Neither rule is overridable;
  • every rule names its source;
  • with its test pack (policy/enterprise-access.v1.test-pack.json, 35 cases over every dimension AC-03 names, and facility).
  • Only registered service identities ask (part 13): active, in this environment, with the scope ess.policy-decision:decide. A refused service identity is recorded by MOD-ESS-001 as misuse. The unit's own modules ask in process (LocalPolicyDecisionClient), so MOD-ESS-001's enforcement point now decides on the real policy.
  • The unit's kit (ADR-HIS-065 point 7):
  • PolicyRequest sends patientRef, encounterRef, and no nulls (contract point 1);
  • PolicyEnforcer sends the subject's subjectAssurance and subjectSession from its token;
  • an outage cache for Tier 1 clinical read paths (OutageDecisionCache, PolicyCheck.tier1ClinicalRead(), his.policy.outage-cache), with its invalidation on PolicyUpdated and IdentityChanged;
  • the test fixtures' FakePolicyDecisionPoint is @Primary, because this unit now has a decision client of its own.
  • Migration V1__policy_decision.sql (schema mod_ess_002).
  • No external dependency was added. The lockfiles are unchanged after ./gradlew dependencies --write-locks. mod-ess-002 depends on mod-ess-001 through its api package only (the module boundary test).

ADR-HIS-065 and its row in the decision record index (64 records). ADR-HIS-059, 060 and 064 are on main (RC-1-S18, RC-1-S14), and 057 is taken by the open pull request of RC-1-S09, so this record is 065. The open pull request of RC-2-S01 also names a record 065; whichever merges second moves to the next free number.

Checks and their result

The integration environment ran as HIS_SESSION=RC-1-S17 (his-rc-1-s17), light profile. OPA and the contract tools ran in their pinned images through the tests' own Docker calls.

Check Command Result
Build and every test of the unit ./gradlew build in services/ess-runtime-decision passed: 196 tests. MOD-ESS-002 70; MOD-ESS-001 89, with its contract test; kit 31; app 5; MOD-ESS-003 1. 4 skipped on the light profile: the 3 Keycloak adapter tests and the Kafka adapter test, as before
Provider contract test ./gradlew :mod-ess-002:test --tests '*PolicyDecisionContractTest' passed. his-contract verify contracts/ess for decide, decideBatch, decideSearchFilter (3 cases each), readDecision and listPolicyVersions (2 each), 13 cases. The PolicyUpdated events published (6) pass his-contract validate-event
Policy test pack (AC-03) ./gradlew :mod-ess-002:test --tests '*PolicyTestPackTest' passed: 35 cases and the coverage check
Evaluator syntax opa check --strict his_authz.rego (in the pinned image) no error
Dependency scan and SBOM platform/delivery-pipeline/bin/dependency-scan services/ess-runtime-decision 0 blocking (6 medium)
Image scan platform/delivery-pipeline/bin/image-scan services/ess-runtime-decision 0 blocking (15 low, 116 medium)
Static analysis platform/delivery-pipeline/bin/static-analysis services/ess-runtime-decision no blocking finding
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

policy-decision.v1 is enterprise-scoped (x-his-facility: enterprise), so verify has no facility cases. The facility is a decision attribute: - a role scoped to RSU-01 does not count at RSU-02 (subjectStateDecides, TP-18); - a facility-owned record of another facility is denied, and one without its owning facility is denied (facilityOwnedRecords, TP-27 to TP-29); - the clinical record crosses facilities under a care relationship, offers Break-the-Glass otherwise, and is withheld across legal entities (clinicalRecordAcrossFacilities, pr2DenyPrevails, TP-19, TP-25, TP-26).

Requirements and test scenarios

Tests are in services/ess-runtime-decision/mod-ess-002/src/test/java/care/cema/his/ess/mod002/ unless named otherwise. Each class carries @Tag with its requirement and scenario, and every display name starts with them.

Requirement, criterion Test
FR-ESS-AUZ-001 AC-01 nurse assigned on her unit and shift, chart for treatment: Permit PolicyDecisionTest.ac01NurseAssignedPermit; on MOD-ESS-001's own records app/…/DecisionWithIdentityTest.decidesOnTheIdentityRecords; TP-05, TP-07
AC-02 same nurse, patient on another unit, no assignment: Deny with emergency override available; the trace shows the missing relationship PolicyDecisionTest.ac02OtherUnitOverride; DecisionWithIdentityTest; TP-06
AC-03 policy test pack (role, specialty, unit, assignment, shift, network or device posture, action) against the active version PolicyTestPackTest.packCoversTheDimensions, everyCase (TP-01 to TP-35)
AC-04 no applicable policy: Deny PolicyDecisionTest.ac04NoPolicy; TP-21
AC-05 a control the user is not authorized for: the service denies the call PolicyDecisionTest.ac05ServiceEnforces (this unit's own enforcement point refuses readDecision to a clerk, and audits it)
AC-06 an auditor retrieves any decision by identifier: policy version and trace PolicyDecisionTest.ac06AuditorReadsDecision
PR-AUZ-001-1 ac04NoPolicy (trace no-applicable-policy)
PR-AUZ-001-2 deny prevails pr2DenyPrevails (legal entity, segregation-of-duties rule 2); TP-22, TP-26, TP-28, TP-30 to TP-32
PR-AUZ-001-3 a required attribute missing: the owning facility of a facility-owned record facilityOwnedRecords; TP-29
Architecture 7.5 facility scoping clinicalRecordAcrossFacilities, legalEntityRequiredAcrossFacilities, facilityOwnedRecords; TP-18, TP-19, TP-25 to TP-32
Part 3, part 11: no unapproved content decides by default or in production PolicyWithoutStarterTest, PolicyStarterInProductionTest, PolicyVersionTest.starterVersion
PR-AUZ-001-3 missing attribute pr3MissingAttribute
PR-AUZ-001-4 override for the CFG-ESS-006 roles only ac02OtherUnitOverride, pr3MissingAttribute (a clerk gets a plain Deny); TP-33 (student) and TP-34 (laboratory staff) get a plain Deny; TP-35 (pharmacist) is offered the override
PR-AUZ-001-5 drop cached decisions on events PolicyVersionTest.activationAtEffectiveTime (PolicyUpdated); service-kit/…/kitcheck/OutageDecisionCacheTest.invalidation (PolicyUpdated, IdentityChanged); the service itself reads MOD-ESS-001 at every decision (subjectStateDecides, DecisionWithIdentityTest.suspensionActsAtOnce)
Part 6.2 subject attributes, part 13 registered services only subjectStateDecides, serviceSubjects, onlyRegisteredServices; DecisionWithIdentityTest.suspensionActsAtOnce
Part 6.5 obligations obligations (step-up, redact); TP-10 to TP-13
Part 6.7 set of resources, search filter batchAndFilter
Part 6.9 effective time, cache bound; part 11 lifecycle PolicyVersionTest (6 tests), cacheLifetime
Part 10 malformed request, unknown action malformed, ac04NoPolicy
Part 10 decision service unavailable DecisionOutageTest.engineOutage
Part 12 every Deny audited, with decision and policy version; trace access audited denialsAudited, ac05ServiceEnforces, ac06AuditorReadsDecision
IF-ESS-003, EVT-ESS-003 contract/PolicyDecisionContractTest

Scenarios: - TEST-ESS-005 is PolicyDecisionTest, PolicyTestPackTest, PolicyVersionTest and DecisionWithIdentityTest. - TEST-ESS-041 is DecisionOutageTest (the service answers 503 when its engine is gone, and decisions resume after) and kitcheck/OutageDecisionCacheTest. In that test a Tier 1 clinical read uses a cached Permit and the use is audited. It is never used for restricted content, another path, another patient, another encounter, or past CFG-ESS-025.

All pass.

Non-functional targets designed for: - NFR-ESS-007 Security: - deny by default and on every failure; - only registered service identities ask; - privileged roles only at aal2; - decisions immutable; - traces readable by reviewers only, and audited; - no patient data in the answer beyond the decision. - NFR-ESS-011 Interoperability: every operation passes his-contract verify, and PolicyUpdated passes validate-event. - NFR-ESS-015 Time integrity: - a decision uses the policy version in force at the service's time, to the millisecond; - the effective time and the superseded version's end time are kept. - NFR-ESS-016 Localization: messages are the specification's wording ("Access could not be confirmed."). - NFR-ESS-017 Observability: - metrics his.authz.decisions{outcome}, his.authz.decision.latency and his.authz.unregistered{resourceType,source}; - logs with correlation; - traces from the kit.

Done differently from the specification or contract, and why

  • An unknown action or resource type is a Deny, not an error (part 10 says "Error; Deny"). Contract point 2 keeps 400 for a malformed request. AC-04 asks for Deny where no policy applies. The kit treats an error as an outage (503), which would misreport an unregistered action. So the answer is a 200 Deny whose trace says registry. It is reported through the log and the metric his.authz.unregistered, for the calling domain's support (follow-up: an alert rule).
  • The subject's assurance and session come from the enforcement point (ADR-HIS-065 point 5).
  • Part 6.2 has the service obtain authentication assurance from MOD-ESS-001. That module does not hold a session's acr, and IF-ESS-003 has no field for it.
  • The kit sends attributes.subjectAssurance and attributes.subjectSession from the subject's validated token.
  • If they are absent, the assurance is aal1. A privileged role then does not count, which refuses more, never less.
  • Care-team assignment, the patient's unit, shift, referral and specialties are supplied by the caller (part 6.3, DEC-ESS-008). No owning domain publishes them in RC-1. Reading them from D03 where a policy needs an authoritative value is a follow-up.
  • Consent and labels are not evaluated (part 6.4). MOD-ESS-003 and FR-ESS-AUZ-003 are not in this slice, and no starter rule references consent. Treatment reads rest on legal obligation and vital interest (DEC-ESS-009), not on consent.
  • No emergency access session exists (FR-ESS-AUZ-002 is not in RC-1). A deny always prevails, and emergencySessionId is never set. TEST-ESS-041's "emergency access available" during an outage is part of that later slice. RC-1 offers the cached Permit.
  • "Listed Permits" are audited only for rules marked auditPermit (readDecision). The SEC-019 list is not among this card's reads, so the policy owner marks further rules in a later version.
  • The service holds no decision cache. It reads MOD-ESS-001 at every decision, so an identity change acts at the next decision. PR-AUZ-001-5 applies to callers' caches: the kit's outage cache drops on PolicyUpdated and IdentityChanged, and on ConsentChanged once that event exists.
  • The contract was not changed.

Changed after review round 1

The review of pull request #121 asked for three changes. All three are settled from the specification, so no question went to the issue: 1. Clinical access across facilities. The blanket facility-boundary deny denied a care-team clinician the record of another facility, with no override. Architecture 7.5 makes the longitudinal clinical record enterprise-scoped: clinical access crosses facilities under a care relationship and purpose of use, with Break-the-Glass as everywhere else. Only across different legal entities is it withheld until a legal basis is recorded. The rule is gone; the clinical rules do not compare facilities; clinical-record-other-legal-entity withholds across legal entities. TP-19 now expects Permit; TP-25 and TP-26 are added. 2. A missing owning facility skipped the check. Facility scoping now applies to the resource types the content marks facilityOwned (architecture 7.5's facility-owned data). For their record actions, an absent owningFacility is a missing required attribute and the request is denied (part 6.6, PR-AUZ-001-3). TP-27 to TP-29 and facilityOwnedRecords cover it. 3. The unapproved starter installed itself as Active everywhere. his.authz.seed-enabled is now off by default and ignored in production. Where a non-production deployment turns it on, the starter is installed as enterprise-access-starter, so it never takes a version number of the governed policy. It is audited as the unapproved starter, and decides only while no governed version is in force. Without it, nothing decides until an approved version is active (503). PolicyWithoutStarterTest and PolicyStarterInProductionTest cover it.

ADR-HIS-065 points 2 and 3, its consequences and the unit README say the same.

Changed after review round 2

The cross-legal-entity deny did not apply when its legal-entity attributes were missing, so a record could be shown across legal entities (architecture 7.5, PR-AUZ-001-3). Settled from the specification, as follows: - a clinical record view now needs the facility of its entry (owningFacility): clinical entries carry it as provenance under 7.5. Absent, the request is denied (clinical-record-provenance); - within one facility no legal entity is needed; - across facilities both legal entities are required: a missing one, or different ones, is a Deny (clinical-record-other-legal-entity, ifMissing: "true"); - neither rule is overridable; - TP-30 to TP-32 and PolicyDecisionTest.legalEntityRequiredAcrossFacilities cover it, and TP-19 and TP-25 now name both legal entities.

Deriving the legal entities from the facility register stays a follow-up. Until then a caller that reads across facilities must send both, or it is denied.

Changed after review round 3

  • Break-the-Glass roles. The starter content offered emergency override to every role with clinical access, after D03-CLI 9.2's "any clinical role". CFG-ESS-006, the setting of who may invoke Break-the-Glass, names licensed clinical staff with direct patient-care duties: physicians, nurses and midwives, pharmacists, allied health professionals. It excludes students and supervised practitioners and administrative, finance or IT roles (FR-ESS-AUZ-002 part 16, GAP-ESS-004). The specific setting governs, so no question went to the issue. emergencyAccess.roles is now those four roles. TP-33 (student) and TP-34 (laboratory staff) get a plain Deny, and TP-35 (pharmacist) is offered the override.
  • Outage cache key. It now includes the encounter (kitcheck/OutageDecisionCacheTest.notForRestrictedOrOtherPaths).
  • Recorded, not changed (non-blocking points of the review):
  • Search filter clauses always limit to the request's facility, including for the enterprise-scoped cli.ClinicalRecord, where single decisions cross facilities. Version 1 has no permit rule for query on the clinical record, so no such clause is produced today. When a domain adds one, its filter must express the care relationship and the legal entity instead of the facility (follow-up for the D03 sessions and the policy owner).
  • Restricted content in the outage cache is recognised only by a caller-supplied accessLevel: restricted. Telling it from the record's labels is FR-ESS-AUZ-003's label model (follow-up for that slice).

Questions for a person

None blocks this session. Where the specification names no rule, the starter policy has none, so the action is denied. Each question is listed under "Needs a person" in the pull request.

# Question Owner What the policy does now
Q1 D01-ADM 9.2: who may amend an adm.Patient (the "Registration supervisor" has no role in the starter catalogue)? Who administers adm.MatchingBenchmark (no 9.2 row)? May a triage nurse or emergency clinician create a provisional person without an emergency department assignment attribute, which adm-identity does not send? Owner of D01-ADM, registration governance No rule: denied
Q2 FR-ESS-TRM: what licence terms decide ess.trm.licensed-content.read? Owner of D10-ESS (terminology), licence owner No rule: answered not-available
Q3 Domain 2 operational roles (SRE, service desk, integration operations analyst) have no role in the catalogue. Who reads service state and alerts, works dead letters and replays, and lifts a network isolation? Owner of D02-ISE, Security and Privacy Office No rule for ise.ServiceState, ise.Alert, the event backbone types and lift
Q4 The roles ess.workflow-administrator, identity-steward-lead and ebp.unit-supervisor-on-duty named by RC-1-S15 are not in the catalogue: are they new roles or existing ones? Owner of D10-ESS Workflow administration (retry, replay-confirm, skip, compensate) has no rule; tasks follow eligibleRoles and supervisorRoles

Follow-ups outside the card

  • Service template (services/_template): take this unit's kit changes, ADR-HIS-065 point 7:
  • PolicyRequest field names and no nulls;
  • the session attributes;
  • OutageDecisionCache;
  • FakePolicyDecisionPoint @Primary.

Units made from the older template send patient, which this service also reads. But their privileged users are denied until they send subjectAssurance (ess-governance already does). - Every calling unit, and RC-1-S26: - register a service identity in MOD-ESS-001 with the scope ess.policy-decision:decide in its environment; - send the attributes its rules read (owningFacility for facility-owned records, careTeam, earlierActors); - a domain registering a facility-owned resource type marks it facilityOwned with its recordActions in the next policy version; - units that send flat earlier-actor ids (authorId, requesterId) keep their local checks. - The legal entity of a facility: the decision service takes owningLegalEntity and requestLegalEntity from the caller. It should read them from the facility register (FR-ESS-MDM-002, MOD-ESS-005) once a policy needs an authoritative value. Until then a caller reading a clinical record of another facility must send both, or it is denied; the D03 clinical record sessions need them. - RC-1-S26 (integrate), the harness (FN-S07) and the deployment topology unit: - set HIS_AUTHZ_SEED_ENABLED=true in the end-to-end stack, until the configuration service holds the governed policy; - add ess-runtime-decision with an OPA beside it and HIS_AUTHZ_OPA_URL. The harness runs units with java -jar and has no way to start a sidecar yet; - then set "policy": "none" with HIS_POLICY_URL; - the deployment's pod manifest runs OPA from the pinned image, on 127.0.0.1:8181, with no bundle. - Governance unit (services/ess-governance): - register the item types ess.authorization-policy (key enterprise-access) and ess.privacy-label-taxonomy; - import enterprise-access.v1.json as version 1 (identical content is accepted); - carry each version's test pack as its test evidence; - grant this unit's service identity ess.cfg.version.read. - Role catalogue (MOD-ESS-001, item type ess.role): - the roles of Q1, Q3 and Q4; - align the permission sets with the policy's rules, which name the exact action codes. - FR-ESS-AUZ-002 slice: emergency access sessions (the PR-AUZ-001-2 exception, emergencySessionId, the elevated-audit and session-marker obligations), and emergency access during an outage. - FR-ESS-AUZ-003 and MOD-ESS-003: label and consent evaluation; ConsentChanged in the kit's outage cache. - D03 (clinical record): - an authoritative care-team API, read where a policy needs it; - mark Tier 1 clinical read paths with tier1ClinicalRead(), and turn on his.policy.outage-cache. - Gateways (RC-1-S12): - register the service identity ise-gateways with the decision scope; - consume PolicyUpdated and IdentityChanged. - ess-reference: /v1/entity-versions?entityKind=practitioner asks ess.mdm.read on ess.Practitioner as internal and without redact (Reads.java:72), so the Permit carries redact and that call is refused. It should declare redact. - ess-coordination: the skip requester is not sent when the approval task is completed, so a requester-is-not-approver rule cannot be written. - Observability (RC-1-S10): an alert rule on his.authz.unregistered and on decision latency (NFR-ESS-001, ASM-ESS-005). - Decision store: partitioning by month and retention for the audit retention period, once volumes are known (NFR-ESS-005). - Integration environment (FN-S02, platform/dev-environment): a startup race failed this unit's pipeline job once (pull request #121, run 45722725094, attempt 1): - the PostgreSQL health check (pg_isready over the Unix socket, compose.yaml) also passes against the temporary server that the image runs during its first initialisation; - his-env start then ran psql (his-env, the database setup) while that server was shutting down, and failed with "the database system is shutting down"; - checking over TCP (pg_isready -h 127.0.0.1, which the temporary server does not listen on), or retrying the setup, would remove it.

A rerun passed. Nothing in this unit causes it. - Design system (RC-1-S21): none from this session.