feat(engine): emit transaction-phase records into auditd (Phase 5, PR 2/2)#113
Merged
Conversation
Phase 5, PR 2 of 2 — completes Phase 5. The transaction coordinator now emits an AUDIT_USER (type 1005) record into the local auditd at each transaction-phase boundary, so a SIEM ingesting auditd sees Kensa's transaction lifecycle without additional plumbing — the observability the FedRAMP reviewer flagged as non-negotiable. The engine runs on the controller, so events land in the controller (operator) host's auditd. - internal/agent/auditnl: Emitter (holds one netlink socket; EmitPhase sends an AUDIT_USER record via SendNoWait — no ACK wait, fully non-blocking; swallows all errors). NewEmitter NEVER errors: a failed socket open (no CAP_AUDIT_WRITE) yields a silent no-op emitter. formatPhaseMessage renders the auditd-style key=value body. - internal/engine: PhaseEmitter interface (defined HERE so the engine core does not import the netlink/go-libaudit stack — auditnl.Emitter satisfies it structurally), no-op default, WithAuditEmitter option, and emit calls at each boundary in Run / finalize / errored: started → capture → apply → validate → committed|rolled_back|partially_applied, and "errored" on the error path. - pkg/kensa: wires engine.WithAuditEmitter(auditnl.NewEmitter()) into the production engine, so emission is on by default wherever privilege allows. - spec engine-audit-emission (Tier 1, 4 ACs); engine emit-sequence tests (committed + rolled-back orders, no-op-default safety) + auditnl emit tests (message format, no-op/zero-value safety). No new dependency (go-libaudit landed with PR 5a). STRICTLY best-effort and non-blocking by construction: SendNoWait, all-errors-swallowed, no-op default. An audit-log failure can NEVER fail or delay a transaction. Failure-mode analysis: 1. What could this do wrong in production? Touching the atomicity-critical coordinator risks affecting transaction outcomes. Mitigated by construction: the only engine change is added emitter.EmitPhase(...) calls whose implementation cannot block (SendNoWait) or error (return value ignored; no-op default). A unit test asserts an engine with NO emitter wired commits identically; the emit calls sit AFTER each phase's existing publishPhaseCompleted, never gating phase logic. 2. Captured-state sufficiency: N/A — this is observability emission, not a capturable handler; no capture/rollback path is touched. 3. Edge case not safe for / gated: emission needs CAP_AUDIT_WRITE (root); a non-privileged operator host silently emits nothing (no-op emitter) — acceptable, audit logging is inherently privileged. The emitted records land in the controller's auditd (where the engine runs), not the target's — documented in the spec. LIVE validation that records reach auditd needs root + a real audit subsystem (CI is non-root → only the no-op path runs); the engine change carries the standard atomicity two-human review (CONTRIBUTING) as the founder's gate. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
comment-lint forbids planning labels in new Go comments; restate the emitter/option comments without the phase number. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 5, PR 2 of 2 — completes Phase 5. The transaction coordinator now emits an
AUDIT_USER(type 1005) record into the local auditd at each transaction-phase boundary, so a SIEM ingesting auditd sees Kensa's transaction lifecycle without additional plumbing — the observability the FedRAMP reviewer flagged. The engine runs on the controller, so events land in the controller (operator) host's auditd.Best-effort by construction — can never affect a transaction
auditnl.Emittersends viaSendNoWait(no ACK wait → non-blocking) and swallows all errors.NewEmitternever errors: a failed socket open (noCAP_AUDIT_WRITE) → silent no-op emitter.What
internal/agent/auditnl:Emitter(one socket;EmitPhaseviaSendNoWait),NewEmitter(no-op on open failure),formatPhaseMessage.internal/engine:PhaseEmitterinterface defined here (so the core doesn't import the netlink/go-libaudit stack —auditnl.Emittersatisfies it structurally), no-op default,WithAuditEmitteroption, and emit calls inRun/finalize/errored:started → capture → apply → validate → committed|rolled_back|partially_applied, anderroredon the error path.pkg/kensa: wiresWithAuditEmitter(auditnl.NewEmitter())so emission is on by default where privilege allows.engine-audit-emission(Tier 1, 4 ACs) + engine emit-sequence tests (committed + rolled-back orders, no-op-default safety) + auditnl emit tests. No new dependency (go-libaudit landed with feat(handlers): audit_rule_set loads rules via AUDIT netlink (Phase 5, PR 1/2) #112).Verification
go test ./...green;go build ./...clean;golangci-lint0;comment-lintclean;specter syncall pass;go mod tidyclean.Failure-mode analysis
emitter.EmitPhase(...)calls that cannot block (SendNoWait) or error (return ignored; no-op default), sitting AFTER each phase's existingpublishPhaseCompleted— never gating phase logic. A test asserts an engine with no emitter commits identically.CAP_AUDIT_WRITE(root); a non-privileged host emits nothing (no-op). Records land in the controller's auditd (where the engine runs), not the target's — documented.🤖 Generated with Claude Code