feat: audit log for sensitive operations#425
Merged
Merged
Conversation
new audit_log table (migration) + store append/list helpers, and an audit module that records sensitive ops under a threadlocal actor (api-token / join-token / local / unauthenticated; defaults to local for CLI processes). recording is best-effort — a storage failure is logged, never propagated. backup validator now expects audit_log too.
dispatch() tags each request with the caller's actor; secret set/delete/ list, policy add/delete, app apply/rollback, agent register/drain, and the backup/restore/secret-rotate CLI ops record audit entries. GET /v1/audit?limit=N returns recent entries (api-token gated like other /v1 routes).
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.
adds an append-only audit log so operators can see who did what: secret
changes, app apply/rollback, agent join/drain, policy changes, and
backup/restore. first half of the audit-log item in next-steps.md.
summary
audit_logtable (via migration) + storeappendAuditEntry/listAuditEntrieshelpers, newest-first with a limit.src/state/audit.zigrecords ops under a threadlocal actor so concurrentAPI requests never clobber each other's identity. the actor is coarse today
(no RBAC yet):
api-token/join-token/local(CLI) /unauthenticated.the
actorcolumn is free-text so a named-token identity drops in later.recording is best-effort — a storage failure is logged, never propagated, so
auditing can't break the operation it records.
dispatch()tags each request with the caller's actor from the existing authflags; CLI processes default to
local.register/drain, backup/restore/secret-rotate).
GET /v1/audit?limit=N(default 50, max 500) returns recent entries, gated bythe api token like other
/v1routes.audit entries are local to the node that performed the op (the control-plane
leader is the authoritative record). cluster-wide aggregation and
retention/rotation are follow-ups.
tested
YOQ_SKIP_SLOW_TESTS=1 zig build test— 2175 passed, 2 skipped, 0 failed.recordwrites under the set actor; actor defaults to local and resets;/v1/auditroute dispatch + method-not-allowed; backup validator accepts thenew table (count 20).
zig fmt --checkclean.follow-up
yoq auditCLI to read the log from the terminal (next PR); that PR will alsocover the HTTP round-trip end to end.