Skip to content

Keep audit and diagnostic logs off stdout (#895) - #908

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/895
Oct 15, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/895

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Root cause

Two separate streams shared the terminal with the human output:

  1. Audit trail. All five audit-logger call sites (launch single/array/MPI, cancel, extend, capacity-block) used audit.NewLogger(os.Stderr, ...). Each security-sensitive step wrote a JSON record, with the AWS account ID as user_id, between the progress lines.
  2. Go log diagnostics. Nothing in the spawn CLI redirected the standard logger, so log.Printf calls in library code (for example pkg/aws pricing: pricing: m8a.4xlarge in us-west-2 = ...) went to stderr with timestamps. spored status builds a query agent that logs its initialization (Agent initialized ... (account: ...)) and runs an idle check (Not idle: CPU usage could not be measured ...). spawn status then passed spored's stderr straight through.

Fix

  • Audit: a new newAuditLogger in cmd/logsink.go appends records to ~/.spawn/audit.log (mode 0600, opened on first write). --verbose also copies them to stderr. If the file can't be opened, records go to stderr exactly once instead of being dropped.
  • Go log: cobra.OnInitialize(configureDiagnosticLog) sends the standard logger to ~/.spawn/spawn.log, and --verbose also copies it to stderr. I used OnInitialize rather than root's PersistentPreRunE because spawn app ... has its own PersistentPreRunE and would skip root's.
  • Warnings stay visible. Some actionable warnings were also emitted through log.Printf and would otherwise have been hidden: no on-demand price / cost limit can't be enforced, unverified plugin source / --insecure, untagged reaper bucket, DCV QUIC rule, snapshot tag propagation, cost pricer config. These now print to stderr directly. spawn burst's progress lines do too.
  • spored status: agent log lines are discarded by default. A new --verbose flag sends them to stderr.
  • spawn status: relaySporedStderr drops Go-log-timestamped lines coming from older sporeds unless --verbose is set. Any other spored stderr, such as errors, is always passed through.
  • -o json stdout is unchanged and stays pure JSON. No public-surface change: pkg/aws gained no exported symbols and lost none.

Tests

  • cmd/logsink_test.go:
    • The audit trail stays off stderr, and audit.log holds complete records with the account ID.
    • --verbose copies records to stderr.
    • If the file can't be opened, records reach stderr exactly once.
    • A run that logs nothing creates no files.
    • A probe subcommand run through rootCmd checks that the OnInitialize wiring keeps log.Printf off stderr.
    • A source scan fails if any cmd file calls audit.NewLogger directly.
    • relaySporedStderr and emitStatus are checked against the exact lines from the issue.
  • cmd/spored/status_logs_test.go runs the real spored status cobra command, with the agent work behind a seam, in table, JSON and --verbose modes.
  • TestStatusJSONStdoutIsPureJSON (spawn status -o json ignores -o json entirely: prints the human table plus spored log lines on stdout (0.100.4) #540) now uses verbose mode for its "diagnostics are not silently dropped" assertion. That is the only mode in which they are still relayed.
  • I watched every gate fail against a revert that compiles: audit to os.Stderr, OnInitialize removed, relay passing everything through verbatim, a direct audit.NewLogger call site, spored sink always stderr, duplicate fallback, eager file open, diagnostic sink straight to stderr.
  • make check passes except TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker. It needs a Docker daemon and fails the same way on unmodified main. Nested modules are clean, docs-gen has been regenerated, and the CHANGELOG has an entry under [Unreleased].

Caveats

  • With an older spored on the instance, spawn status --verbose still shows its diagnostics. With a new spored they are no longer emitted during status, so spawn status --verbose shows nothing extra; run spored status --verbose on the instance to see them. spawn doesn't forward --verbose, because an older spored would reject the unknown flag.
  • SPAWN_LOG doesn't exist and I didn't add it; --verbose was already the global flag.

Fixes #895

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

spawn's audit logger wrote one JSON record per operation (with the AWS
account ID as user_id) straight to stderr, and Go log diagnostics from
library code (pricing, etc.) went to stderr with timestamps, so both
interleaved with launch progress output. spored status likewise printed
the query agent's init and idle-check log lines.

- Audit trail: appended to ~/.spawn/audit.log (0600, opened lazily),
  copied to stderr under --verbose; falls back to stderr if the file
  cannot be opened so no record is lost.
- Go log: routed to ~/.spawn/spawn.log via cobra.OnInitialize, copied
  to stderr under --verbose.
- Actionable warnings previously sent through log.Printf (no price,
  unverified plugin, untagged bucket, ...) now print to stderr directly
  so they stay visible; burst progress lines likewise.
- spored status: agent log lines discarded unless --verbose; spawn
  status filters Go-log lines relayed from older spored unless --verbose.
- Gates for each path, each watched failing against a compiling revert.
…erbose

By default spored's log lines (which carry the account ID) now stay off both
streams; with --verbose they are relayed to stderr and still never reach
stdout, so #540's guarantee holds where it applies.
@scttfrdmn
scttfrdmn merged commit b6da656 into main Oct 15, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/895 branch October 15, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Human-readable output is interleaved with raw JSON log lines and Go log timestamps (launch, status)

1 participant