Repository navigation
feat(audit): record every request outcome to stderr, JSONL and syslog (#65) - #76
Conversation
…reply Found in a live manual run of #76: - The JSONL file stored request strings raw. JSON leaves bidi overrides and C1 controls unescaped, so `cat`/`tail` on the file could reorder or restyle the terminal. File fields now get the same \u{...} escapes as the stderr and syslog lines. - A missing or malformed `time` was reported as rejected:stale_time. The reason is now rejected:time, covering every freshness failure. - Rejections, ping, stop and busy replied before writing their record, so a client could see the reply before the log line existed (two tests raced on it). Every path now records first, then replies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
Review: PR #76 — feat(audit): record every request outcome to stderr, JSONL and syslog (#65)Summary. The PR does what it says: every connection outcome now funnels through one Findings1. High — the approval decision is only recorded after the command has finished running ( 2. Medium — 3. Medium — 4. Medium — 5. Low — after the first file-write failure the file sink is dead for the daemon's lifetime, silently ( 6. Low — Minor notes
|
…#65) The daemon logged prompted requests and unattended runs only, mostly behind -v and without timestamps. Replayed ids, stale or malformed `time`, validation failures, denials and timeouts left no trace (threat-model B1, Repudiation). New src/audit.rs: each connection outcome yields one record (RFC 3339 time, peer UID, id, session, host, outcome, and the command for validated requests). Sinks: stderr (always), an append-only 0600 JSONL file at $XDG_STATE_HOME/sudo-proxy/audit.jsonl (default on; --audit-log PATH, --no-audit-log), and syslog LOG_AUTHPRIV (default on; --no-syslog). Env values, `reason` and raw invalid request bytes are never recorded. The daemon refuses to start if the audit file cannot be opened. Closes #65. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
…reply Found in a live manual run of #76: - The JSONL file stored request strings raw. JSON leaves bidi overrides and C1 controls unescaped, so `cat`/`tail` on the file could reorder or restyle the terminal. File fields now get the same \u{...} escapes as the stderr and syslog lines. - A missing or malformed `time` was reported as rejected:stale_time. The reason is now rejected:time, covering every freshness failure. - Rejections, ping, stop and busy replied before writing their record, so a client could see the reply before the log line existed (two tests raced on it). Every path now records first, then replies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
68b763b to
4c18561
Compare
Closes #65 (threat-model B1, "Repudiation").
Problem
The daemon logged prompted requests and unattended runs, mostly only with
-v, without timestamps, and to stderr only. Replayed ids, stale or malformedtime, validation failures (control/bidi characters, disallowed env, invalid plan), human denials and prompt timeouts left no record.Change
New
src/audit.rs. Every connection outcome produces exactly one record:time,outcome,peer_uid,id,session,host,privileged,command(only for requests that passed validation),detail(the error sent to the client),statusandexit_codes(for requests that ran).approved,approved_session,unattended,pkexec,denied,timeout,ping,stop,prompt_error,rejected:<reason>(peer_uid,peer_cred,busy,handshake_timeout,read_error,invalid_json,invalid_request,forward_agent,time,env,duplicate_id,invalid_plan).-v.$XDG_STATE_HOME/sudo-proxy/audit.jsonl, else~/.local/state/.... Mode 0600 in a 0700 dir,O_APPEND, onewrite_allper line.--audit-log PATH/--no-audit-log.LOG_AUTHPRIVvialibc(no new crate), constant"%s"format.--no-syslog.\u{…}, so the file is safe tocat/tail -f.reason, raw bytes of an invalid request.Eventhas no field for them.In
src/server.rs, every early return goes through onerejecthelper that writes the response and the record. The old unconditional[id] [unattended]line and the peer-UID line are folded into the audit line.Residual
The file belongs to the daemon's UID, which is also the requester's UID, so it is append-only by convention only. The syslog copy is the record the requester cannot alter. Documented in
docs/threat-model.mdanddocs/usage.md.Tests
tests/audit.rs(11 cases): one per outcome, plus checks that a secret in env,reasonor malformed JSON never reaches the file, one-record-per-line with a newline-bearing field, and file/dir modes.tests/concurrency.rs: the busy test also checks 3rejected:busyand 4deniedrecords.tests/pty_e2e.rs: the real binary writes the default file underHOME.cargo clippy --all-targetsis clean, both builds compile (default and--no-default-features), andcargo testpasses.Manual end-to-end check (
docs/testing.md) done against a live daemon: approve, deny (privileged), prompt timeout, replayed id, stale and missingtime, bidisession,LD_PRELOADenv, and malformed JSON were each recorded correctly in the file and injournalctl -t sudo-proxy. The rejections were logged while a prompt was pending, the secret value never appeared, and the file was mode 0600. That run found the three issues fixed in the second commit: raw bidi characters in the file, thestale_timename for a missingtime, and reply-before-record ordering.🤖 Generated with Claude Code