Appearance
ADR-2512: Security and Compliance Take Time From IClock
- Status: Accepted
- Date: 2026-09-30
- Authors: @fderuiter, Claude Code
- Deciders: @fderuiter
- Requirements: PRD-SYS-001 (audit entries carry a trustworthy timestamp), kernel spec K-TIME-3
1. Context & Problem Statement
K-TIME-3 says clinical code takes time from an injected clock, never from DateTime.UtcNow. After the audit interceptor moved to IClock (#4784), packages/security and packages/compliance were the last packages that read the wall clock:
ReplayCachechecked request timestamps againstDateTimeOffset.UtcNow.AuditDigestEnginestamped digest records withDateTime.UtcNow, andAuditLogRecord.Timestampdefaulted to it.GxPSigner,Pkcs7SignerandRtmGeneratorServicedated signatures, certificates and the RTM from the wall clock, andComplianceAuditLogRecord.Timestampdefaulted to it.
A default of "now" on a record also hides a writer that forgot to supply the time.
2. Decision Drivers & Constraints
- One clock: audit, replay and signing times come from the same
IClockthe rest of the service uses. - Enforced, not reviewed: the packages opt into the
BannedSymbols.txtban so a regression fails the build. - No breaking change for callers: hosts and the CLI keep working without new wiring.
3. Options Considered
Option 1: Required IClock on every entry point
- Cons:
- ❌ Every caller of the signing helpers and the replay cache changes, including CLI commands with no container.
Option 2: Optional IClock defaulting to SystemClock.Instance, and the ban (Selected)
- Overview:
ReplayCache,AuditDigestEngine,GxPSigner.SignGxpMarkdown,Pkcs7Signer.GenerateSigningCredentialsandRtmGeneratorService.GenerateRtmtake an optionalIClock.AddCadenceSecuritypasses the registered clock.AuditLogRecord.Timestampisrequired;ComplianceAuditLogRecord.Timestamphas no default.- Both projects reference
Cadence.Kernel.Abstractionsand are covered by globalBannedApiAnalyzers.
- Pros:
- ✅ Tests can fix the time with
FakeClock; hosts use their registered clock. - ✅ The analyzer keeps the wall clock out of both packages.
- ✅ Tests can fix the time with
- Cons:
- ❌ A caller that passes no clock still gets the system clock, through
SystemClockrather than a direct read.
- ❌ A caller that passes no clock still gets the system clock, through
4. Decision Outcome
- Chosen Option: Option 2.
- Justification: It removes the last wall-clock reads from
packages/and lets the ban guard them, without touching callers that have no container.
5. Consequences & Trade-offs
- Positive Impact:
- Replay windows, audit digests, signatures and the RTM date are testable with a fixed clock.
grepfor wall-clock reads inapps/andpackages/finds none.
- Negative Impact / Technical Debt:
- Code that builds an
AuditLogRecordmust now setTimestamp.
- Code that builds an
6. Implementation & Verification
- Affected code:
packages/security/src/Authentication/ReplayCache.cspackages/security/src/Audit/AuditDigestEngine.cs,AuditLogRecord.cspackages/compliance/src/GxPSigner.cs,Pkcs7Signer.cs,RtmGeneratorService.cs,ComplianceAuditLogRecord.cs
- Verification:
tests/Cadence.UnitTests/Packages/SecurityAndComplianceClockTests.cschecks each entry point against aFakeClock; the build fails on a wall-clock read in either package.