Files
ScadaBridge/docs/plans/sql/AddAuditLogHashChain.sql
T
Joseph Doherty b418408c0f docs(audit): record the removal of the hash chain and the two-login hardening
Component-AuditLog (Security & Tamper-Evidence now a removal note, archive format v2, config),
Component-CLI, Component-ManagementService, HighLevelReqs AL-11/AL-12, docs/components/CLI, the CLI
README, alog.md §11.4/§15 and CLAUDE.md. New production script docs/plans/sql/RemoveAuditLogHashChain.sql
(idempotent, from migration 64); AddAuditLogHashChain.sql marked superseded. Historical plans,
deployment records and deploy-prep packs are left as written.

Claude-Session: https://claude.ai/code/session_01GT67AFKC45MBz1wPZnVbX8
2026-11-15 17:38:22 -05:00

73 lines
3.3 KiB
Transact-SQL

-- SUPERSEDED 2026-11-15: the hash chain was removed at IT security's request; RemoveAuditLogHashChain.sql drops
-- everything this script creates. Kept as the record of what was applied to DEV/QA on 2026-11-13.
-- AddAuditLogHashChain (2026-11-09, ScadaBridge#41). AuditLog hash-chain tamper evidence:
-- ChainSeq/RowHash on dbo.AuditLog, AuditLogChainHead + AuditLogChainTombstone, two partition-aligned
-- filtered indexes, the scadabridge_audit_chainer role. Apply to the central configuration database
-- with both central nodes stopped (old binaries cannot switch out a partition once the columns exist).
-- The two filtered indexes reference ChainSeq, which this same batch adds; SQL Server compiles a batch
-- before running it, so they are wrapped in EXEC to defer compilation (else Msg 207, ScadaBridge#126).
BEGIN TRANSACTION;
ALTER TABLE [AuditLog] ADD [ChainSeq] bigint NULL;
ALTER TABLE [AuditLog] ADD [RowHash] binary(32) NULL;
CREATE TABLE [AuditLogChainHead] (
[ChainMonth] date NOT NULL,
[LastSeq] bigint NOT NULL,
[LastHash] binary(32) NOT NULL,
[PurgedThroughSeq] bigint NULL,
[PurgedThroughHash] binary(32) NULL,
[UpdatedAtUtc] datetime2 NOT NULL,
CONSTRAINT [PK_AuditLogChainHead] PRIMARY KEY ([ChainMonth])
);
CREATE TABLE [AuditLogChainTombstone] (
[ChainMonth] date NOT NULL,
[ChainSeq] bigint NOT NULL,
[RowHash] binary(32) NOT NULL,
[EventId] uniqueidentifier NOT NULL,
[PurgedAtUtc] datetime2 NOT NULL,
CONSTRAINT [PK_AuditLogChainTombstone] PRIMARY KEY ([ChainMonth], [ChainSeq])
);
EXEC(N'CREATE NONCLUSTERED INDEX IX_AuditLog_Unchained
ON dbo.AuditLog (OccurredAtUtc, EventId)
WHERE ChainSeq IS NULL
ON ps_AuditLog_Month(OccurredAtUtc);');
EXEC(N'CREATE NONCLUSTERED INDEX IX_AuditLog_ChainSeq
ON dbo.AuditLog (ChainSeq)
WHERE ChainSeq IS NOT NULL
ON ps_AuditLog_Month(OccurredAtUtc);');
IF DATABASE_PRINCIPAL_ID('scadabridge_audit_chainer') IS NULL
EXEC sp_executesql N'CREATE ROLE scadabridge_audit_chainer';
-- The chaining job reads unchained rows and writes ONLY the two link columns.
GRANT SELECT ON dbo.AuditLog TO scadabridge_audit_chainer;
GRANT UPDATE (ChainSeq, RowHash) ON dbo.AuditLog TO scadabridge_audit_chainer;
GRANT SELECT, INSERT, UPDATE ON dbo.AuditLogChainHead TO scadabridge_audit_chainer;
GRANT SELECT ON dbo.AuditLogChainTombstone TO scadabridge_audit_chainer;
IF DATABASE_PRINCIPAL_ID('scadabridge_audit_purger') IS NULL
EXEC sp_executesql N'CREATE ROLE scadabridge_audit_purger';
-- The per-channel purge writes a tombstone per chained row it removes; the partition
-- switch moves the month's head to its checkpoint anchor and drops its tombstones.
GRANT SELECT, UPDATE ON dbo.AuditLogChainHead TO scadabridge_audit_purger;
GRANT SELECT, INSERT, DELETE ON dbo.AuditLogChainTombstone TO scadabridge_audit_purger;
IF DATABASE_PRINCIPAL_ID('scadabridge_audit_writer') IS NULL
EXEC sp_executesql N'CREATE ROLE scadabridge_audit_writer';
-- The ingest principal must never be able to forge chain state.
DENY INSERT, UPDATE, DELETE ON dbo.AuditLogChainHead TO scadabridge_audit_writer;
DENY INSERT, UPDATE, DELETE ON dbo.AuditLogChainTombstone TO scadabridge_audit_writer;
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20261109211317_AddAuditLogHashChain', N'10.0.13');
COMMIT;
GO