Skip to content

feat(logging): redact session secrets where the log is written, not where it is collected - #283

Merged
artempartos merged 3 commits into
developfrom
artempartos/redact-at-write
Sep 17, 2026
Merged

artempartos merged 3 commits into
developfrom
artempartos/redact-at-write

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Why

Step 1 of removing the size cap on log collection (#282 put a 4 MB tail in as the stopgap).

The cap is not there because of storage. It is there because redaction forces the bytes through us: Sessions::SecretRedactor runs in the worker, so every log has to be copied out of the container, through the k8s API server, into a Ruby string, before it can be cleaned. That chain is what the 120-second cleanup budget and the 4 MB tail are both about. Clean at the point of writing and the whole chain — and with it the cap — stops being necessary.

There is a second reason to do this regardless of the cap. tmux pipe-pane feeds two sinks:

tmux pipe-pane -t agent "tee -a /tmp/terminal_output.log > /proc/1/fd/1"

/proc/1/fd/1 is the container's stdout, and therefore the cluster's log stack. Nothing has ever scrubbed that one — the collector-side pass only cleans the copy it pulls out. get_config_item's own warning to the agent ("visible to … the cluster's log stack if it is printed") describes exactly this hole.

What this changes

The filters (docker/base/logger/):

  • aixle_redact.py / aixle-redact.js — one list loader per language, because two processes append to http.log: the mitmproxy addon and the HTTP/2 logger. Both clean the entry before serialization rather than the serialized line, so a value carrying a quote is matched in its own form instead of in JSON's escaping of it. Longest-first, matching SecretRedactor.
  • redact-stream.py — the pane filter, in front of the existing tee. Two properties a whole-file pass never had to think about: it withholds only the smallest tail that could still begin a secret (almost always nothing, so the live terminal does not lag), and it catches a secret split across two writes. entrypoint.sh degrades to the bare tee if the filter cannot start — a pipeline whose first stage dies captures nothing, and a session with no terminal output is one the no-output watchdog reaps half an hour later.

The list (Sessions::SecretRegistry): derived from config_item_accesses, so it holds exactly the values this session has already been handed — which is what makes writing it into the container safe. It tells the container nothing the container did not ask for. Root-owned so the agent cannot quietly empty it, world-readable because the pane filter runs as the agent's user while the proxy runs as root, one base64 line per value so a secret containing newlines stays on one line.

The ordering rule (get_config_item): the list is armed before the value is returned, and a secret is not returned if arming failed — one that reaches a log ahead of its entry is one no later pass can take back out of bytes already written. A plain variable is not worth refusing over.

Sessions::SecretRedactor stays exactly as it is, on the collection path and on the live tail. Two passes, and the outer one is now the belt rather than the braces.

What this does not do

  • Nothing about collection changes yet. The 4 MB tail from fix(sessions): capture the evidence a failed run leaves behind #282 is still there. Removing it is step 2: with the bytes already clean, the container can curl --upload-file straight to a presigned S3 PUT (Api::V1::AssetsController#presign already signs those; read_tool_result already hands the agent presigned URLs) and the app records only the key. collect_usage then moves out of cleanup into a job that streams from S3.
  • Requires an agent image rebuild. Everything under docker/base/logger/ ships via COPY base/logger/ /opt/mitm/ in each agent Dockerfile; until the images are republished the filters are not present and the Ruby half is a list nobody reads.
  • A value the TUI redraws in pieces is not matched. Escape sequences interleave, so it is not contiguous in the stream. That is equally true of the collector-side pass, and neither is the place to fix it — an agent that prints a secret has already lost it to anyone watching the session.

Verification

test/services/internal_tools, test/services/sessions, test/services/container_strategies, test/services/context_builders and the config-items integration test: 663 runs, 2320 assertions, 0 failures, 0 errors. rubocop clean on the changed Ruby, brakeman clean on the tree (0 warnings). Full check_all is CI's — this worktree is outside the compose mount.

The container scripts have no test harness in this repo, so they were exercised directly against a real list file:

check result
secret split across two writes Bearer <redacted:session-secret> — not leaked
secret containing newlines redacted whole
clean text, live flush emitted immediately, nothing withheld
redact_obj over a nested entry (body / headers / array) no occurrence survives json.dumps
JS redact over the same entry no occurrence survives JSON.stringify
JS list loader multi-line value loaded intact, ordered longest-first

Ruby-side coverage: the list is published for secrets and not for variables, rewritten whole so a republish heals a container that missed a write, one line per value however many newlines it holds, written as root with mode 0644, success for a session with no container (no log is being written), failure when the container cannot take it — and, in the tool, that a secret is refused when arming fails while a variable still returns.

🤖 Generated with Claude Code

artempartos and others added 3 commits September 18, 2026 00:31
…re written

A value an agent reads through get_config_item travels to the model in a request
body, so it lands verbatim in /var/log/mitm/http.log, and in the agent pane if the
agent echoes it. The pane is piped to two sinks at once — the file the collector
uploads and /proc/1/fd/1, which is the container's stdout and so the cluster's log
stack. Nothing scrubbed that second one at all; the collector-side pass could only
ever clean the copy it pulled out.

Add the filters that clean at the point of writing instead: a shared list loader in
both languages that write http.log (the mitmproxy addon and the HTTP/2 logger, which
append to the same file), and a streaming filter in front of the pane's tee. The
stream filter holds back only the smallest tail that could begin a secret, so the
live terminal does not lag, and it degrades to the bare tee rather than risking a
pane that captures nothing.

The list they read is written in the next commit; until then they are a no-op.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…a secret

get_config_item is the only channel by which a session receives a credential, so it
is also the only place that knows a value is about to become loggable. It now
publishes the session's secrets into the container before it answers, derived from
config_item_accesses so the list holds exactly what this session has been handed and
nothing else — which is what makes writing it into the container safe.

A secret is not returned if arming failed: one that reaches a log ahead of its entry
is one no later pass can take back out of bytes already written. A plain variable is
not worth refusing over, since nothing is being hidden.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
docker/base/logger carries an importable module now, so running its filters
locally leaves a __pycache__ behind.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit 1642c72 into develop Sep 17, 2026
7 checks passed
aixle-com Bot pushed a commit that referenced this pull request Nov 24, 2026
…nge (#273) (#872)

* refactor(sessions): one lifecycle service for every session state change

Add Sessions::Lifecycle as the only code that fires TerminalSession events,
four machine events for the moves finalize_session wrote past the machine,
and route every caller (admission service, strategies, cleanup, suspension,
runners) through it. Effects stay in the model callbacks (change 4, #283).

Signed-off-by: Alex <[email protected]>

* test(sessions): assert a nil error message with assert_nil

Signed-off-by: Alex <[email protected]>

* fix(sessions): finalize makes no move for suspended and restored sessions

Signed-off-by: Alex <[email protected]>

---------

Signed-off-by: Alex <[email protected]>
Co-authored-by: Alex <[email protected]>
aixle-com Bot pushed a commit that referenced this pull request Nov 24, 2026
…ect state writes (#283) (#874)

* Sessions: lifecycle effects in Sessions::Lifecycle.transition!, hard guard on direct state writes (#283)

Signed-off-by: Alex <[email protected]>

* Sessions: move effect tests onto Lifecycle.transition!, fix test setup for the state guard

Signed-off-by: Alex <[email protected]>

* Sessions: fire the effect tests' events through transition!

Signed-off-by: Alex <[email protected]>

* Sessions: use model predicates in lifecycle effects

Signed-off-by: Alex <[email protected]>

---------

Signed-off-by: Alex <[email protected]>
Co-authored-by: Alex <[email protected]>
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.

1 participant