Skip to content

Architecture / Decision records / ADR-HIS-129

ADR-HIS-129 Document service: content under object lock behind a hand-written S3 channel, retrievals bound to the subject, resolution obligations it can honour, and disposal only after a configured retention period

Status Accepted
Decided 2026-12-02 by session RC-5-S05
Record Drafted 2026-12-02; awaiting approval by the Enterprise Architecture Board
Where the rule lives services/ess-coordination/mod-ess-009/ (storage/S3ObjectStore, documents/DocumentService, documents/ResolutionService, documents/Intake, intake/ContentInspector, ports/SearchFilters, Mod009Module, migration V1__documents.sql); services/ess-coordination/service-kit/.../policy/ (PolicyRequest, PolicyCheck, PolicyEnforcer)

Context

FR-ESS-DOC-001 asks the document service to store document content immutably with its hash, to index it, to resolve a reference only after a policy decision, and to give content only by a short-lived retrieval bound to the requesting subject. Contract session RC-5-S01 wrote document-reference.v1 (IF-ESS-011) and DocumentRegistered (EVT-ESS-013). ADR-HIS-125 point 5 fixed the content channel: a pre-signed upload address on the Domain 2 object storage (RustFS with object lock, technology stack row 25), a retrieval of at most 5 minutes, and a content address pinned to the object version of at most 60 seconds.

The questions left to this session (RC-5-S05): - how the unit talks to the object storage; - how content is kept immutable, and how it is removed at disposal; - which obligations of a Permit the service can honour on a whole document; - to whom a retrieval is bound when a service resolves on behalf of a user; - when a disposal is allowed, given that the retention schedule belongs to Domain 6; - what the unit does while no malware scanner exists.

Options considered

  1. The AWS SDK for Java for S3. Complete, but a large dependency tree (Netty or the Apache client, the SDK core) for five calls, each of which must pass the dependency rules of the technology stack and the pipeline's scans.
  2. MinIO's Java client. Smaller, but it brings OkHttp and Kotlin's standard library, and it ties the unit to a client of a product it does not run.
  3. A hand-written S3 client on the JDK HttpClient, signing with signature version 4 (chosen). Five operations: pre-signed PUT and GET, HEAD, copy with object lock and delete with the governance bypass, plus bucket creation for test environments. No new dependency. It is tested against the pinned RustFS image.
  4. Object lock in COMPLIANCE mode. Nobody can delete before the lock ends, not even Domain 6's disposition. That would break part 6.7, which requires disposal when the retention period has ended.

Decision

  1. A hand-written S3 channel (option 3). S3ObjectStore signs with signature version 4 on the JDK HttpClient, path-style. Pre-signed addresses use UNSIGNED-PAYLOAD and the host of storage.public-endpoint. Any failure, or an unreachable store, is StorageUnavailable and answers 503. Nothing is registered on a guess.
  2. Content is copied under GOVERNANCE object lock and pinned to its object version.
  3. The checks fix the upload's object version first. The inspection, the malware scan and the hash read that version, and the copy names it as its source. Content put to the still-valid upload address after the checks is never what is stored.
  4. At registration, that version is copied to documents/<documentId>/<versionId> with lock mode GOVERNANCE until storage.lock-period (30 years). The object version the copy returns is recorded, and every content address is pinned to it.
  5. The upload object is then removed.
  6. Only disposeDocument, called by Domain 6's service, deletes the locked content, with x-amz-bypass-governance-retention. The index row is kept as a tombstone, with storage removed.
  7. The real type is checked by content, never by name.
  8. Magic bytes decide the format. A PDF is refused if it is encrypted. PDF/A needs pdfaid:part 2 or more. A FHIR document must be a Bundle of type document. A CDA document must have a ClinicalDocument root in urn:hl7-org:v3, and is refused if it has a document type declaration. It is read without external entities.
  9. The limits are the type's, which may narrow those of CFG-ESS-024 but never widen them.
  10. DICOM is never uploaded: it is a reference to the imaging archive.
  11. The malware scanner is a port, unconfigured by default.
  12. With no scanner, every registration of content answers 503: nothing unscanned is stored.
  13. malware-scanner: eicar-stub stands in for the integration environment. It finds the EICAR test string.
  14. Domain 2 has no scanning contract yet, so this is a follow-up for it.
  15. Malware found is audited as ess.doc.security, the upload is removed, and the caller gets 400.
  16. A disposal needs the retention period to have ended, and no legal hold (PR-DOC-001-4).
  17. Domain 6 owns the schedule. This unit holds the period of each retention class it is configured with (his.document.retention-periods.<class>), counted from the latest version's creation time.
  18. A class with no configured period is treated as not ended, so its disposal is refused. A missing setting can never dispose of a record early.
  19. The disposal is claimed before any content is removed. Under the document's row lock, the hold, the retention and the If-Match are checked, and the start of the disposal is recorded and committed. Only then is content deleted, and a last transaction writes the tombstone.
  20. From the claim on, the document takes no legal hold, new version, entered-in-error mark or resolution: each takes or reads the same row and refuses with "a disposal is in progress". A hold therefore either comes first, and the disposal is refused, or is refused itself. It never lands on a document whose content is being removed.
  21. A disposal that fails part-way answers 503 and keeps its claim. A retry with the same dispositionRef completes it; another disposition is refused.
  22. Resolution honours only the obligations it can carry out on a whole document.
  23. These are accompany-labels, elevated-audit and session-marker. They are returned to the caller, and the audit is recorded.
  24. A Permit that carries redact, mask or step-up is treated as a Deny. The document service cannot redact a PDF, and serving it unredacted would breach the obligation. This is audited as ess.doc.resolve-denied.
  25. A retrieval is bound to the subject of the token that resolved it.
  26. When a service resolves on behalf of a user (onBehalfOf), the user is sent to the policy decision point, and recorded on the retrieval and in the audit. The retrieval stays bound to the service that holds it.
  27. To support this, the kit's PolicyRequest now sends subject.onBehalfOf, patientRef and encounterRef as policy-decision.v1 names them, and leaves out empty fields.
  28. Search is filtered by the policy decision point's search filter (/v1/decisions/search-filter).
  29. The clauses are OR'd, and the conditions within a clause are AND'd. They are applied to each document's facility, labels, record category and patient.
  30. No clause means nothing is permitted, and an outage answers 503, never everything.
  31. The filter and the paging are applied in the database, so a page reads only its own rows. The values are bound as parameters. A condition on an attribute other than these four, or with an unknown operator, matches nothing, so a filter the unit does not understand never widens what is listed.
  32. Patient merge moves the index; unmerge moves back only what was registered under the restored person. registeredPatient keeps the identifier a document was registered under. Documents registered under the survivor after the merge stay with it; Domain 1 attributes them (attributionPending).
  33. An external location's format comes from the type, except dicomweb-wado-rs, which is DICOM. The contract's ExternalLocation has no format field; adding an optional one is a contract follow-up.

Consequences

  • The unit adds no dependency for storage. The S3 client is about 250 lines, tested against RustFS (S3ObjectStoreTest). A later need, such as multipart uploads beyond 5 GB, would have to be added by hand. The current limits are 500 MB for MP4 and 25 MB otherwise.
  • Until Domain 2 offers object storage and a scanner in each environment, the document service answers 503 for content. Deployment session RC-5-S16 configures the storage, the scanner and the retention periods.
  • Domain 6 must give this unit a period for each retention class it disposes of. Until it does, disposal is refused (point 5).
  • A unit that resolves on behalf of a user holds the retrieval itself and passes content on under its own obligations.