Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The audit trail

Every IHE transaction the gateway makes or receives is audited as its profile requires, to an ATNA Audit Record Repository over ITI-20 Record Audit Event. Two configurations decide where the records go:

  • [xcpd] audit and [xcpd.audit_repository] for the XCPD localizer’s ITI-55 exchanges, which XCPD audits as a DICOM audit message over syslog (The audit repository);
  • [audit] for the PIXm, PDQm, mCSD and PMIR transactions, which each profile audits as a FHIR AuditEvent built on the IHE Basic Audit Log Patterns (BALP), and for the access records (The access log), which every build writes whatever its bindings. BALP has the gateway send it over the ATX: FHIR Feed Option of ITI-20: a FHIR create at the repository’s FHIR base (the RESTful ATNA supplement, ITI TF-2 §3.20.4.2).

What each transaction records

TransactionWhenRecordPatient namedSection
ITI-55 Cross Gateway Patient Discoveryeach discovery the XCPD localizer makesthe Initiating Gateway’s DICOM audit message, over sysloginside the base64 query parameters[xcpd]
ITI-83 Mobile Patient Identifier Cross-reference Queryeach query the PIXm resolver or localizer asks a PIX ManagerPIXm Query Consumer audit (BALP Patient Query): the request as sent, base64; for method = "post", its request line, media type and Parameters bodythe source identifier, system and value[audit]
ITI-78 Mobile Patient Demographics Queryeach search the [pdqm] step sends the PDQm SupplierPDQm Query Consumer audit (BALP Query): the request as sent, base64inside the base64 request; a demographics search identifies no patient on its own[audit]
ITI-119 Patient Demographics Matcheach match the [pdqm] step sends under transaction = "iti-119"PDQm Match Consumer audit (BALP Query): the request as sent, base64the identifier on the input Patient, system and value[audit]
ITI-90 Find Matching Care Serviceseach search of the mCSD directory the registry is read from, one per resource typemCSD Care Services Query audit (BALP Query): the first request of the search, base64none[audit]
ITI-91 Request Care Services Updateseach history of a registry refresh, one per resource typemCSD Care Services Updates audit: the first request, base64none[audit]
ITI-93 Mobile Patient Identity Feedeach message the Patient Identity Registry sends to the feed routePMIR Feed audit, the Registry as the source and the gateway’s callback as the destination: the MessageHeaderone entity per Patient Master Identity the message names, by its Patient/<id> reference or an identifier[audit]
ITI-94 Subscribe to Patient Updateseach subscription create, read and delete the identity feed makesPMIR Subscription Create, Read and Delete audits (BALP Create, Read, Delete): the Subscription and, for a create, its criterianone: a subscription names an identifier system at most[audit]
The search of the Registry’s subscriptions by callbackbefore each createBALP Query: the request as sent, base64; ITI-94 defines no searchnone[audit]

Every record names the gateway as source.observer and as its own agent, by source_id (the hostname by default), at the network address hostname gives, and names the other party by its FHIR base URL without its userinfo or query.

The caller each record names

A transaction the gateway makes for a client’s request is made on behalf of the caller it verified (Client authentication). PIXm asks that its audit record be augmented with the agent details of the caller’s OAuth token, following BALP (PIXm §2:3.83.5.2.1), so each such record names the caller as BALP maps the token (BALP §3:5.7.5.4):

RecordWhere the caller is named
ITI-83, ITI-78 and ITI-119 (AuditEvent)the agent:user of the BALP pattern: type IRCP, who.identifier.system the token’s iss, who.identifier.value its sub, requestor true, purposeOfUse every purpose of use the token declares, which purposeOfEvent repeats (Where the purposes of use are found); and an Application agent (DICOM 110150) with the token’s client_id as who.identifier.value
ITI-55 (DICOM audit message)the Human Requestor ActiveParticipant (ITI TF-2 §3.55.5.1.1): UserID the token’s sub, UserName written aud<sub@iss> (IUA ITI TF-2 §3.72.5.1), UserIsRequestor true, and the gateway’s own participant UserIsRequestor false. The DICOM schema has no element for the client or the purpose of use, so the message names neither

A transaction the gateway makes on its own behalf names no caller: the admission check’s ITI-83 queries, every ITI-90 search and ITI-91 history of a registry read or refresh, every ITI-94 subscription exchange and the search before it, and every ITI-93 message the Registry sends. Their AuditEvent has no agent:user and no Application agent, as BALP’s examples of an event no user caused have none, and an ITI-55 message of its own names the gateway as the requestor.

The caller’s identity goes to the Audit Record Repository alone. Both log destinations, [audit] destination = "log" and [xcpd] audit = "log", record on_behalf as caller or gateway, and never the caller’s sub, client_id or issuer; no metric label carries them. Each node is told of the caller by the signed conveyance alone (Onward credentials), never by an audit record.

Where the purposes of use are found

An AuditEvent carries every purpose of use the caller’s token declares in two places, emergency purposes such as BTG among them:

ElementWhat it holds
agent.purposeOfUse of the agent:userevery purpose of use the token declares, in the token’s order, where BALP 1.1.4 places a purpose of use it knows to be the agent’s
purposeOfEventthe same codings, each once, in the order the agents first name them

An Audit Record Repository that keeps its records in the DICOM audit message form reads the second. The RESTful ATNA supplement (Rev. 3.6) maps purposeOfEvent to the EventIdentification PurposeOfUse and gives agent.purposeOfUse no DICOM counterpart (Tables 3.20.4.2.2.1-1 and 3.81.4.2.2.1-1), and ITI TF-2 §3.20.7.1.2 asks that a purpose of use be encoded in EventIdentification. BALP binds both elements to the HL7 v3 PurposeOfUse value set, so writing both keeps the record’s pattern. A record of a transaction the gateway makes on its own behalf names no caller and carries neither.

The address a request came from

The access log records the address each request came from, so it says from where a caller reached patient data. The gateway takes that address from the connection, so behind a reverse proxy it is the proxy’s, 127.0.0.1 for a proxy on the same host. The client’s address reaches the gateway only in the Forwarded or X-Forwarded-For header the proxy writes, and any client can write those headers too, so the gateway reads them only from a proxy listed in server.trusted_proxies (RFC 7239 §8.1). With the proxy listed, a request is named by the client the proxy names; with none listed, the default, every request is named by its peer, and a forwarded header changes nothing (Behind a reverse proxy).

The access log

Every access to patient data the gateway intermediates is recorded as a BALP AuditEvent, which goes where the [audit] records go, through the same spool. What a record names, how it is classified and kept, how it is read and how [access_log] is configured are on The access log.

[audit]

[audit]
destination = "repository"             # "log" or "off" under development, or without a registry

[audit.repository]
hostname = "gateway.example.org"       # the gateway's network address in each record
spool_dir = "/var/lib/ferrofed/audit-feed-spool"
# source_id = "gateway.example.org"    # source.observer, the hostname by default
# enterprise_site = "2.999.40"         # source.site
# spool_max_size = "64MiB"
# spool_max_events = 100000
# spool_write_timeout = "10s"          # storing one record in the spool, within the request's own time

[audit.repository.endpoint]
url = "https://arr.example.org/fhir"   # the repository's FHIR base
# timeout = "5s"                       # each delivery
# retry.max_backoff = "1min"           # the longest wait between two delivery rounds

[audit.repository.endpoint.tls]        # when the repository asks for a client certificate
client_identity_file = "/run/secrets/atna-client.pem"
trust_roots_file = "/etc/ferrofed/atna-roots.pem"      # optional

[audit.repository.endpoint] is ferrohealth-smart’s outbound table, the one every FerroHEALTH product reaches a service through: url, timeout, connect_timeout, the retry table (max_attempts, initial_backoff, max_backoff), tls and credentials (HTTP Basic or a client credentials grant under credentials.oauth). One delivery is one round of the retry table’s tries, and a failed round waits retry.max_backoff before the next.

  • destination has no default outside profile = "development" once a registry is configured, or [pixm], [pdqm] or [pmir] is set, since every access to patient data is recorded: config check, serve and a reload refuse the configuration without it, naming audit.destination. Every build records accesses here, with either binding or none. off is refused outside development; under development an unset destination records nothing.
  • log writes each record as a structured event at the ferrofed::audit log target: the profile, the subtypes, the action, the outcome, the other party, and how many patient, query and resource entities the record holds. It never writes a patient identifier, a patient reference, the caller or the request, which may name one. An access record written there names no one, so outside development a gateway with a registry refuses log: config check, serve and a reload name audit.destination and ask for repository (Regulation (EU) 2025/327 Annex II 3.2). log stays accepted under development, and outside it for a gateway with no registry, whose PIXm, PDQm or PMIR records it writes.
  • repository posts a record to [url]/AuditEvent as FHIR JSON, and several records waiting together to [url] as one FHIR batch Bundle, each judged by its entry of the batch-response (ITI TF-2 §3.20.4.4 and §3.20.4.5). The url is https outside development; under development plain http is accepted and named on the banner, and without spool_dir the spool is held in memory, which a restart loses.
  • A change to [audit] takes a restart, as [xcpd.audit_repository] does: one forwarder drains each spool.

The spool and the failure policy

The FHIR Feed records follow the policy of the ITI-55 audit trail. Every record is written to the spool first, flushed to disk, and delivered from there in order, so it counts as recorded once it is on disk. One writer appends the records that arrive together to the spool’s active segment file and flushes them to the disk once. A spool directory a release before 0.0.21 wrote holds one .msg file per record, which this release refuses at start, naming the file: let the older release deliver them, or move them out, before you upgrade. While the repository is down, or answers 5xx, 408 or 429, the transactions go on and the records wait in the spool. One delivery is one round of the [audit.repository.endpoint] retry table’s tries, and a failed round waits retry.max_backoff before the gateway tries again. A record the repository refuses with any other 4xx would be refused again, so it is moved to the spool’s quarantine subdirectory, logged with its sequence number and status and never its content, and the drain goes on; a spooled file that is no FHIR AuditEvent is quarantined the same way. A quarantined record stays counted under the spool’s bounds until you remove it.

On SIGTERM, once the bindings have stopped, the gateway stops every audit trail within gateway.bindings_drain_timeout. Each forwarder finishes the record it is writing, ends an ITI-20 syslog connection with a TLS close_notify (RFC 5425 §4.4) and returns, so the frames it wrote last reach the repository; a socket dropped with the repository’s session tickets unread would be reset and could lose them. A forwarder also closes a connection the repository ended before it opens a new one. A record not yet written stays in the spool for the next start. A trail that does not stop in time is logged.

Only a record the gateway can neither deliver nor store is an audit failure: a full spool (spool_max_events or spool_max_size), one that cannot be written, or one that does not store the record in time (A slow disk). The transaction then fails closed, and its answer is never used:

TransactionWhen its record cannot be stored
An access to patient datathe answer is withheld: 503 access-unrecorded with none of the data (The access log)
ITI-83the member’s resolution is unavailable: no member is asked, and the query fails 424 under all-or-nothing completeness
ITI-90, ITI-91the directory read fails as a directory that did not answer: the boot is refused, or a refresh keeps the registry in place
ITI-93the message is answered 503 and nothing is applied, so the Registry sends it again
ITI-94the exchange fails, and GET {base}/operator/dependencies reports the Registry failing with the fault audit-failed

A slow disk

Storing a record flushes it to the device twice, once for the file and once for its directory, and the transaction waits for that before it uses its answer. A disk that is slow or has stalled could hold the transaction without limit, so the wait is bounded, on both spools:

  • by spool_write_timeout, in [audit.repository] ("10s" by default) and in [xcpd.audit_repository] ("2s" by default), the longest one record may take to be stored, the wait for the write before it included;
  • for the record of an access, by what is left of the request’s own time: server.request_timeout less the one-second combining margin, so the gateway answers 503 access-unrecorded before the server’s own timeout does;
  • and, for an ITI-83 query, an ITI-78 search or ITI-119 match of the [pdqm] step, or an ITI-55 discovery, by the time the transaction was given: what is left of the patient query’s budget, of the step’s timeout_ms, or of the localization’s time. Whichever bound comes first applies.

On a loaded host a durable write waits for the journal to commit other writers’ data as well (ext4 in its default data=ordered mode), so one record can take seconds. The access log’s ten-second bound and the request’s own time leave room for that, and the record still fails closed past them (#1812). A record that spool_write_timeout cuts off is an audit failure, as a full spool is, with the outcomes in the table above, and an ITI-55 discovery fails closed under every on_failure policy (The audit repository). A record still being stored when its transaction’s time runs out fails a transaction that succeeded the same way: an ITI-55 discovery or a [pdqm] exchange then fails closed under every on_failure policy, never widened to ask-all. The gateway gives the localizer and the [pdqm] step a deadline a tenth of their time short of its own, so a record cut off at that deadline reaches it as the audit failure it is, before the gateway stops waiting. A transaction that failed already, such as a PIX Manager or a responding gateway that did not answer, reports its own failure instead, which the late record would only hide. Either way the query never waits on the disk past its budget.

The write that missed its bound is not abandoned. It runs on until the disk answers. Once it stores the record, the record is delivered like any other, and the gateway logs a warning with the record’s sequence number; a write that fails in the end is logged as an error. Neither log line carries the record. The spool’s depth counts the record only once the write has stored it. A transaction that failed this way may therefore still appear in the repository, as the transaction it was: the gateway made or received it, and ITI-20 has every stored record sent (ITI TF-2 §3.20.4.1.1).

One write runs at a time. While a write is stalled, every record behind it waits for its turn and its transaction is answered at its own bound, so a stalled disk holds one thread of the gateway, never one per transaction. A record still waiting when its transaction stopped waiting stays queued: it is written once the writes ahead of it end, and delivered like any other, in the order the records were queued. A queued record holds its place under spool_max_events and spool_max_size as a stored one does, so a stalled disk holds no more records in memory than the spool could hold on disk. A record past either bound is refused at once, without waiting: its transaction fails as with any full spool, the refusal is logged with its count and never the record, and ferrofed_audit_refused_total counts it (Metrics). The mCSD directory reads and the PMIR subscription exchanges run outside any patient query, so spool_write_timeout alone bounds their records.

The spool holds records that name patients. The gateway creates the directory readable by its own user alone (0700) and every file 0600, and refuses to start when the directory gives its group or other users any access. Put it on an encrypted volume. A spool belongs to one repository configuration: the FHIR Feed spool and the ITI-55 syslog spool are two directories.

GET {base}/operator/dependencies reports the FHIR Feed repository as audit_feed: up, degraded while the gateway retries a failed delivery, while records wait in the spool and while any sits in quarantine, and unknown before the first record. The audit metrics of Metrics count every spool, the FHIR Feed’s included.