feat(audit): off-box chain-head export, verify-heads, maintenance login (ScadaBridge#107)
Item 1 (owner decision: no signing). AuditLog:HashChain:HeadExport (default
off): both centrals periodically read every month's chain head (LastSeq,
LastHash, purge anchor, chained rows, tombstones; one snapshot under the
chain lock SHARED) and append the changed heads to a sink the DB login cannot
write - File (append-only JSONL per node per day, local or UNC) or Syslog
(RFC 5424 over UDP / TCP octet counting). `audit verify-heads --path` reads
those records back (file or syslog-collector lines) and the new
VerifyAuditChainHeads command checks each against the database: Matches /
Extended / Purged, or Mismatch / Regressed / MissingHead / MissingLink /
CountMismatch (exit 3). AuditChainHeadStoreTests forges a chain with the
production hasher: verify-chain says Intact, verify-heads says Mismatch.
Item 3. AuditLog:MaintenanceConnectionString (${secret:}-capable, unset =
today's single login) runs the chain job, chain verify / head export, the
partition switch-out + archive and the per-channel purge on
AuditMaintenanceContext (keyed audit-maintenance repository/archive, purge
actor prefers them). AuditMaintenanceLoginTests runs the hardened setup on
SQL Server: writer (datareader/datawriter/audit_writer) ingests and is
refused chaining and deleting; the chainer+purger login does the full cycle.
Two-login grants documented in Component-AuditLog.md.
Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using ZB.MOM.WW.Configuration;
|
||||
using ZB.MOM.WW.ScadaBridge.AuditLog.Central.HeadExport;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.AuditLog.Central;
|
||||
|
||||
@@ -33,6 +34,12 @@ public sealed class AuditLogHashChainOptions
|
||||
|
||||
/// <summary>Upper bound on batches per tick so a backlog yields between ticks (default 100).</summary>
|
||||
public int MaxBatchesPerTick { get; set; } = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Off-box export of the per-month chain heads (<c>AuditLog:HashChain:HeadExport</c>,
|
||||
/// ScadaBridge#107 item 1) — the chain's external anchor. Default off.
|
||||
/// </summary>
|
||||
public AuditChainHeadExportOptions HeadExport { get; set; } = new();
|
||||
}
|
||||
|
||||
/// <summary>Validates <see cref="AuditLogHashChainOptions"/> at host startup.</summary>
|
||||
@@ -47,5 +54,33 @@ public sealed class AuditLogHashChainOptionsValidator : OptionsValidatorBase<Aud
|
||||
$"AuditLog:HashChain:{nameof(AuditLogHashChainOptions.BatchSize)} ({options.BatchSize}) must be between 1 and 10000.");
|
||||
builder.RequireThat(options.MaxBatchesPerTick > 0,
|
||||
$"AuditLog:HashChain:{nameof(AuditLogHashChainOptions.MaxBatchesPerTick)} ({options.MaxBatchesPerTick}) must be > 0.");
|
||||
|
||||
var export = options.HeadExport ?? new AuditChainHeadExportOptions();
|
||||
if (!export.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const string section = "AuditLog:HashChain:HeadExport";
|
||||
builder.RequireThat(export.IntervalMinutes > 0,
|
||||
$"{section}:IntervalMinutes ({export.IntervalMinutes}) must be > 0.");
|
||||
if (export.Sink == AuditChainHeadSinkKind.File)
|
||||
{
|
||||
var dir = export.File?.Directory;
|
||||
builder.RequireThat(!string.IsNullOrWhiteSpace(dir) && Path.IsPathFullyQualified(dir),
|
||||
$"{section}:File:Directory ('{dir}') must be an absolute path (local or UNC) when Sink=File.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var syslog = export.Syslog ?? new AuditChainHeadSyslogSinkOptions();
|
||||
builder.RequireThat(!string.IsNullOrWhiteSpace(syslog.Host),
|
||||
$"{section}:Syslog:Host is required when Sink=Syslog.");
|
||||
builder.RequireThat(syslog.Port is > 0 and <= 65535,
|
||||
$"{section}:Syslog:Port ({syslog.Port}) must be between 1 and 65535.");
|
||||
builder.RequireThat(syslog.Facility is >= 0 and <= 23,
|
||||
$"{section}:Syslog:Facility ({syslog.Facility}) must be between 0 and 23.");
|
||||
builder.RequireThat(syslog.TimeoutSeconds > 0,
|
||||
$"{section}:Syslog:TimeoutSeconds ({syslog.TimeoutSeconds}) must be > 0.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user