feat(audit)!: remove the AuditLog hash chain, head export and two-login maintenance hardening
Owner decision 2026-11-15, at IT security's request, pending a family-wide general solution. Removed: the chaining service, hasher, verifier, chain head/tombstone entities and store, the #139 chain-start cutoff, AuditLog:HashChain (incl. ChainBacklog and HeadExport with its File/Syslog sinks and export service), the audit-chain-head-export health check, the VerifyAuditChain / VerifyAuditChainHeads management commands and the `audit verify-chain` / `audit verify-heads` CLI commands, and the two-login plumbing (AuditLog:MaintenanceConnectionString, AuditMaintenanceContext, the keyed audit-maintenance repository/archive). Purge, archive, retention, partition roll-forward and backfill-source-node all run on the runtime connection again, as before #107. Parquet archive (#42) kept, chain-free: format v2 (ten stored columns, no tombstone file, manifest without chain state), the switch guard is the row count only (51003 gone), verify = data-file size, SHA-256 and row count, and superseded-stale cleanup proves coverage by EventId. Format-v1 archives still list, verify and are cleaned up (their tombstone file too). Migration RemoveAuditLogHashChain drops the chain indexes, the scadabridge_audit_chainer role (members first), both chain tables, ChainSeq/RowHash and the purger's AuditMaintenanceGrants grants; writer/purger roles stay. Down restores them. Every chain-column reference is EXEC-deferred for the idempotent script (#126); FlipAuditLogClusteredKey's two chain index statements get the same deferral, behaviour unchanged, so re-running the idempotent script on a migrated database works. The partition-switch staging table adds the chain columns only when the live table has them, so the new binary purges either schema. Deploy gate: old binaries map the chain columns, so the migration ships with the new binaries, both centrals stopped. A leftover AuditLog:HashChain section or MaintenanceConnectionString (DEV/QA still carry AuditLog__HashChain__Enabled=true) is ignored with one startup warning (RetiredAuditSettingsWarning). Claude-Session: https://claude.ai/code/session_01GT67AFKC45MBz1wPZnVbX8
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// One row per chain partition (UTC calendar month) of the AuditLog hash chain
|
||||
/// (ScadaBridge#41): where the chain currently ends, plus the checkpoint anchor a
|
||||
/// monthly partition purge leaves behind.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The head is what lets verification detect <b>tail truncation</b> — deleting the last
|
||||
/// rows of a month leaves a chain that is internally consistent but shorter than the
|
||||
/// head says. It is written by the chaining job (<see cref="LastSeq"/>/<see cref="LastHash"/>)
|
||||
/// and by the partition-switch purge (<see cref="PurgedThroughSeq"/>/<see cref="PurgedThroughHash"/>).
|
||||
/// </remarks>
|
||||
public sealed class AuditLogChainHead
|
||||
{
|
||||
/// <summary>First day of the chain's month (UTC). Primary key.</summary>
|
||||
public DateTime ChainMonth { get; set; }
|
||||
|
||||
/// <summary>Sequence number of the last row linked into the chain.</summary>
|
||||
public long LastSeq { get; set; }
|
||||
|
||||
/// <summary>RowHash of the last row linked into the chain (32 bytes).</summary>
|
||||
public byte[] LastHash { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Checkpoint anchor: the last sequence number removed by a monthly partition-switch
|
||||
/// purge. Verification resumes at <c>PurgedThroughSeq + 1</c> with
|
||||
/// <see cref="PurgedThroughHash"/> as the previous link. Null when never purged.
|
||||
/// </summary>
|
||||
public long? PurgedThroughSeq { get; set; }
|
||||
|
||||
/// <summary>RowHash at <see cref="PurgedThroughSeq"/>; null when never purged.</summary>
|
||||
public byte[]? PurgedThroughHash { get; set; }
|
||||
|
||||
/// <summary>UTC time the head last moved.</summary>
|
||||
public DateTime UpdatedAtUtc { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The link a sanctioned per-channel retention DELETE removed from the middle of a chain
|
||||
/// (ScadaBridge#41). Written in the SAME statement batch as the DELETE (via
|
||||
/// <c>OUTPUT … INTO</c>) so the purge can never remove a chained row without leaving its
|
||||
/// hash behind; verification bridges the gap with it.
|
||||
/// </summary>
|
||||
public sealed class AuditLogChainTombstone
|
||||
{
|
||||
/// <summary>First day of the chain's month (UTC). Part of the primary key.</summary>
|
||||
public DateTime ChainMonth { get; set; }
|
||||
|
||||
/// <summary>Sequence number of the purged row. Part of the primary key.</summary>
|
||||
public long ChainSeq { get; set; }
|
||||
|
||||
/// <summary>RowHash of the purged row (32 bytes).</summary>
|
||||
public byte[] RowHash { get; set; } = [];
|
||||
|
||||
/// <summary>The purged row's EventId, kept for the operator's benefit.</summary>
|
||||
public Guid EventId { get; set; }
|
||||
|
||||
/// <summary>UTC time of the purge.</summary>
|
||||
public DateTime PurgedAtUtc { get; set; }
|
||||
}
|
||||
@@ -138,19 +138,4 @@ public sealed record AuditLogRow
|
||||
: null;
|
||||
}
|
||||
private readonly DateTime? _ingestedAtUtc;
|
||||
|
||||
// ── Hash-chain link (audit roadmap T1, ScadaBridge#41) ────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Position of this row in its month's hash chain (1-based, gap-free per UTC calendar
|
||||
/// month of <see cref="OccurredAtUtc"/>); null until the chaining job reaches the row.
|
||||
/// Written ONLY by the chaining job — never by the ingest/writer path.
|
||||
/// </summary>
|
||||
public long? ChainSeq { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// <c>SHA-256(prev.RowHash || canonical(row))</c> — 32 bytes; null until chained. See
|
||||
/// <c>AuditChainHasher</c> for the canonical serialisation.
|
||||
/// </summary>
|
||||
public byte[]? RowHash { get; init; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user