Expand description
Audit trail — optional local log of every intercepted command.
Records are JSON Lines (one JSON object per line). Each record contains
the AuditEvent fields written by the caller, plus metadata collected
automatically at write time (AuditMeta: user, host, cwd, git repo and
branch, schema version) and optional caller-provided details
(AuditExtra: policy sources, effective challenge, deny reason).
Writes are safe under concurrency: each record is serialized into one
buffer and written with a single write() on an O_APPEND descriptor,
under an exclusive flock on Unix, so lines from parallel writers never
interleave. The file is created with mode 0600. When the log grows past
DEFAULT_MAX_AUDIT_BYTES it is rotated: audit.log becomes
audit.log.1, .1 becomes .2, … and only the newest
DEFAULT_MAX_AUDIT_FILES generations are kept (configurable with the
audit_max_files setting of the log’s configuration directory, see
max_files_for). audit show reads
every generation.
A stored command is capped at MAX_STORED_COMMAND_BYTES; longer
commands are truncated and the record carries command_bytes and the
command_sha256 of the full command, so a few huge commands can never
flush the history.
Secrets are redacted before a command is stored (see redact_secrets):
mysql -pSECRET, --password=…, PGPASSWORD=… and other
*_PASSWORD / *_TOKEN / *_SECRET / *_KEY assignments, user:pass@
in URLs, Authorization: headers, curl -u user:pass and well-known
token formats (AWS AKIA…, GitHub ghp_…, Slack xox…-) become ***.
A redacted record carries command_redacted: true, and its
command_sha256 is computed over the original command, so a known
command can still be matched against the log without storing the secret.
Identity: user is the account name of the real uid (from the password
database, falling back to $USER), uid is the numeric uid, and
env_user records $USER when it differs from user.
Older records (without the newer fields) are still readable through
AuditEntry.
Modules§
- deny_
reason - The values of
AuditExtra::deny_reason.
Structs§
- Audit
Entry - Read model for one audit record. Every field is optional so records written by older versions (or by hand) still load.
- Audit
Event - A single audit log entry, as written by the interception paths.
- Audit
Extra - Optional details a caller can attach with
log_event_with. - Audit
Filter - Filters for
audit show. - Audit
Meta - Metadata collected automatically by
log_eventfor every record. - Audit
Read - Parsed audit records plus the number of lines that could not be parsed.
Enums§
- Audit
Outcome - The outcome of a challenge interaction.
Constants§
- AUDIT_
SCHEMA_ VERSION - Version of the on-disk record format written by this build.
- DEFAULT_
MAX_ AUDIT_ BYTES - Size after which
audit.logis rotated toaudit.log.1(10 MiB). - DEFAULT_
MAX_ AUDIT_ FILES - Rotated generations kept by default (
audit.log.1…audit.log.5). - MAX_
AUDIT_ FILES_ LIMIT - Largest accepted
audit_max_files. - MAX_
STORED_ COMMAND_ BYTES - Longest command stored verbatim in a record (8 KiB). Longer commands are truncated (at a character boundary) and hashed.
- OUTCOME_
VALUES - The outcome names accepted by
AuditOutcome::parse(for help texts).
Functions§
- clear_
log - Clear the audit log (and every rotated generation).
- collapse_
events - Collapse records that share an
event_id(the pre-challengeCancelledrecord followed by the final outcome), keeping the last one. - collect_
meta - Collect the automatic metadata for a record.
- collect_
meta_ for collect_metaforcommand.- current_
uid - Real uid of this process (Unix).
- filter_
entries - Apply a filter.
- format_
table - Render records as a human-readable table.
- git_
info - Find the git repository root and current branch for
dirby reading.git/HEADdirectly (no subprocess). - log_
event - Append an audit event to the log file as a JSON line.
- log_
event_ with - Append an audit event plus caller-provided details as one JSON line.
- log_
files - Every existing log generation, oldest first (
audit.log.N…audit.log.1, thenaudit.log). Generations beyond the configured limit that are still on disk are included too. - max_
files - The number of rotated generations kept for an
audit_max_filessetting (clamped likemax_files_for). - max_
files_ for - How many rotated generations are kept for the log at
audit_path. - now_
timestamp - Get the current timestamp in ISO 8601 format.
- parse_
since - Parse a
--sincevalue into a comparable UTC timestamp. - read_
entries - Read every log generation (see
log_files), oldest first. - read_
log - Read and return all audit log lines.
- redact_
secrets - Replace secrets in a command line with
***before it is stored. - sha256_
hex - Lowercase hex SHA-256 of
data(small self-contained implementation so the audit log needs no extra dependency). - unescape_
invisible - Undo
crate::context::escape_invisible.