Appearance
ADR-2257: Attributable Audit Actors and Named Service Accounts
- Status: Accepted
- Date: 2026-09-29
- Authors: @fderuiter
- Deciders: @fderuiter
1. Context & Problem Statement
Some writes were attributed to nobody, and some were not audited at all (#4767):
HttpCurrentAuditContextAccessorreturned"system"whenever a request had nosubclaim, so any write from outside a request was stamped"system". That included the eConsent consumer's GxP interceptor entries.Cadence.Security.Audit.GxPAuditInterceptordefaulted its user to"system".- 21 entity properties in payments, imaging and interop defaulted
CreatedByorReaderIdto"system". - Deleting subject demographics and applying the eTMF compliance webhook wrote no semantic audit entry.
21 CFR 11.10(e) and ALCOA+ require every change to be attributable to the person or process that made it.
2. Decision Drivers & Constraints
- Attribution (PRD-SYS-053): every audit entry must name a real actor.
- Fail closed: a write with no resolvable actor must fail, not fall back to a placeholder.
- Background work is legitimate: consumers and jobs have no caller, but they act on the system's behalf and must say so explicitly.
3. Options Considered
- Keep a default actor and label it better (for example
"unknown"). Rejected: still records changes against nobody. - Fail on a missing actor and let background work declare a named service account. Chosen.
- Give every consumer its own DI container or bus. Rejected: heavy, and MassTransit cannot override one shared registration per consumer type.
4. Decision Outcome
- No anonymous fallback.
ICurrentAuditContextAccessor.UserIdreturns the authenticated caller'ssub, or throwsAuditActorUnresolvedException. The security package's interceptor throws for the same reason. Authenticated HTTP callers never hit this, because the gateway scheme rejects unauthenticated requests with 401 first; anything else surfaces as a 500. - Named service accounts. Background work declares a
ServiceAccountwhose id must start withsvc:, throughIAuditActorScope.RunAsat the start of its scope. The eConsent consumer runs assvc:econsent-consumer, replacing the legacysystem-pubsub. One scopedAmbientAuditContextAccessorimplements both interfaces, so the EF interceptor sees the declared account. - Actor resolved only when needed.
Cadence.Database.GxPAuditInterceptorresolves the actor only when the save contains an audited change, so saves with nothing to audit (outbox bookkeeping) need no actor. - Every execution write is audited. Subject demographics deletion writes
DELETE_DEMOGRAPHICS, and the eTMF webhook writesETMF_COMPLIANCE_UPDATE, each in the same save as the change. - No default actors in entities.
CreatedByandReaderIdin payments, imaging and interop arerequired, so the compiler forces every construction to name one.AuditAttributionSentinelTestsfails the build on any new actor-named member or local that defaults to a"system…"literal.
5. Consequences & Trade-offs
- Positive: every audit entry names a person or a named service account, and a missing actor is a visible failure.
- Negative: new background work must declare a service account before writing, or its saves fail. Tests that seed data outside a request use a
svc:test-seederscope. - The legacy golden-master expectation for SCN-009-A changes from
system-pubsubtosvc:econsent-consumer. - Long term, kernel rule K-PROV-1 (every write has a provenance activity with an actor) supersedes this mechanism.
6. Implementation & Verification
apps/execution:AmbientAuditContextAccessor,ServiceAccount/ServiceAccounts,IAuditActorScope; the consumer callsRunAs; the two new semantic audit entries.packages/databaseandpackages/security: interceptors with no"system"default.- Tests:
CurrentAuditContextAccessorTests,ExecutionAuditAttributionTests(every mutating route over HTTP is audited against the signed caller),GxPAuditTrailGenerationTests(a save with no actor fails),AuditAttributionSentinelTests, and the golden-master SCN-009-A assertion. PRD-SYS-053.