ADR-042: Sidecar-Owned PTY Master for Kali Transcript Authenticity¶
Status¶
accepted
Date¶
2026-06-20
Reader boundary¶
This Explanation records design reasons and constraints. Dated examples, versions, estimates, and measurements describe their stated revision. They do not establish current interface support or installed qualification. The capture explanation describes maintained use. The record's status and amendments still determine its decision scope.
Context¶
ADR-033 made the MCP-side PTY tee the authoritative record of red-side
keystrokes and output, and moved red-side evidence out of the blue SIEM.
ADR-041, from issue #305, moved Kali-side capture writes into the
aptl-kali-capture sidecar so the Kali workload cannot read, list, delete, or
modify captured evidence. That sidecar boundary protects the capture volume and
the genuinely Kali-side witnesses the workload does not feed directly: pcap,
auditd, and process accounting.
ADR-041 deliberately left one residual. The earlier wrapper used script(1) and a FIFO. aptl-capture-client forwarded those workload-origin bytes to the sidecar for storage. Connection ownership blocks cross-session append, and single-use IDs block reopening. The active workload can still forge bytes before they enter its FIFO or client path.
ADR-041's "PTY transcript authenticity (residual)" section deferred closing this gap to a future ADR that moves PTY-master ownership into the sidecar. This ADR is that follow-up and supersedes that residual.
Issue #516 requires detection of self-forgery or omission by a sudo-capable workload. Interactive tools must keep PTY behavior, exit status, and environment delivery.
Decision¶
The Kali-side PTY transcript must be produced from a PTY master that is owned
outside the Kali workload authority. The aptl-kali-capture sidecar, or a
sidecar-fronted PTY broker with equivalent isolation, owns:
- the PTY master;
- the raw input and output recording stream;
- transcript/timing/integrity metadata writes under
kali_captures; - the session lifecycle event that finalizes the transcript.
The Kali workload may receive only the PTY slave attached as the shell's controlling terminal. The sidecar records slave output at its owned PTY master. The workload must not hold a writable transcript or recording handle. A workload-fed FIFO cannot supply authenticated transcript input.
The user-facing execution model remains the existing MCP SSH session model.
mcp/aptl-mcp-common/src/ssh.ts continues to own PersistentSession, command
queueing, raw/normal mode semantics, delimiter handling, remote-close
awaiting, APTL_SESSION_ID / APTL_RUN_ID / APTL_TRACE_ID propagation, and
the MCP-side createPtyTeeWriter cross-check. Implementation may relocate SSH or add an SSH-compatible PTY proxy. The PTY-master allocator and recorder must remain outside the Kali workload container.
script(1) remains acceptable only as an output compatibility format or as a
tool running in the sidecar-owned PTY path. Running script(1) in the Kali
workload, then forwarding its log to the sidecar, does not satisfy this ADR.
The sidecar-produced transcript should preserve the existing
pty/typescript and pty/timing artifact contract where practical. Detection metadata belongs beside the session artifacts under sidecar ownership. Examples include sequence, byte count, direction, close reason, and running hash. Do not move this into a new run
archive root or a second harvest path.
Attacker Model¶
The attacker is the normal Kali workload user with passwordless sudo inside the Kali workload container. The threat model permits root in the workload. That actor can inspect descriptors, write the PTY slave, stop its shell, emit escapes, and attempt denial of service.
The attacker must not be able to:
- access the
kali_capturesvolume from the Kali workload mount namespace; - access sidecar process file descriptors through a shared PID namespace;
- write transcript bytes through any path other than the actual PTY slave;
- truncate, replace, or append to sidecar-owned transcript artifacts;
- finalize another connection's session or reopen a finalized session ID;
- hide transcript gaps without a sidecar-visible close, error, or integrity anomaly.
This ADR does not claim that terminal output is truthful. A shell can always print misleading text. The claim covers bytes observed at the sidecar-owned PTY master and sidecar lifecycle metadata. It does not authenticate a workload-supplied log.
Security Layers¶
- MCP auth and input surface: keep the existing MCP JSON Schema tool
definitions and handler assertions as the ingress boundary for
session_idand command arguments. Do not add sidecar-specific MCP session ID shapes or tool envelopes. - SSH/session boundary: keep
PersistentSessionas the command lifecycle owner. The sidecar endpoint/proxy must preserve normal mode delimiters, raw mode behavior, background sessions, window/signal behavior, remote-close semantics, and exit-code propagation visible tossh.ts. - Correlation environment: preserve
APTL_SESSION_ID,APTL_RUN_ID, andAPTL_TRACE_IDfromaptlShellEnv. The sidecar or proxy may validate and forward those values, but must not invent a second correlation vocabulary. - Identifier validation: reuse the canonical OBS-003 ID rule already
mirrored in
src/aptl/core/runstore.py,mcp/aptl-mcp-common/src/runs.ts, MCP handler checks, and ADR-041 sidecar code:^[A-Za-z0-9_][A-Za-z0-9._-]*$and no... - Config shape: keep durable user config out of
aptl.jsonunlessAptlConfiggets a real field and consumer per ADR-025. Sidecar runtime settings need parsed environment variables and safe defaults. These include socket, launch adapter, capture root, enabled classes, and rotation limits. - Secret handling: ADR-029 remains canonical. Raw transcripts, pcaps, audit, and accounting evidence can contain intentional target secrets. Diagnostics, MCP results, and telemetry must exclude raw evidence and credentials.
- OS and mount exposure:
kali_capturesstays mounted read-write only in the sidecar and not mounted in Kali, even read-only. Do not share the sidecar PID namespace with Kali. A network-reachable sidecar must not mount the Docker socket merely to launch shells. Such host-equivalent authority needs an explicit later ADR. - Process argv: do not pass secrets, command lines, transcript bytes, or user-controlled tcpdump expressions through shell strings or process argv. Use fixed recorder arguments and structured APIs.
- Persistence and harvest: keep
LocalRunStore,mcp/aptl-mcp-common/src/runs.ts, andmcp/aptl-mcp-common/src/captures.tsas the run-layout and harvest boundaries. Harvest still targets the configuredcapture_container_nameand preserves chmod repair and fail-loud missing-source behavior. Update (2026-10-11, #1242): the sidecar runs no auditd or process accounting, so the harvest no longer copies global_audit/_proc-acctdirectories. A failed harvest writes a namedcapture-harvest-failure.jsonrecord into the session's kali-side evidence. - Error envelopes and observability: preserve existing
SSHError, MCP JSON result envelopes,harvest_warning, stderr logging style, and degraded readiness patterns. Do not introduce a second exception hierarchy or make capture startup a new hard precondition for SSH login unless the user-facing behavior is explicitly redesigned.
Maintainability¶
Implementations must build on the existing incumbents rather than parallel systems:
mcp/aptl-mcp-common/src/ssh.ts:PersistentSession,SSHConnectionManager,SessionMode, command queueing, close semantics, andaptlShellEnv.mcp/aptl-mcp-common/src/runs.tsandsrc/aptl/core/runstore.py: run/session path construction and ID validation.mcp/aptl-mcp-common/src/captures.tsandmcp/aptl-mcp-common/src/tools/handlers.ts: best-effort harvest andharvest_warningprojection.- ADR-041 sidecar writer boundary: capture volume ownership, no Kali mount, no PID sharing, bounded local control surface, and sidecar ownership of pcap/auditd/pacct.
- ADR-033 non-contamination: no Wazuh agent, rsyslog path, SIEM forwarding, or blue-visible red telemetry feed from Kali.
- ADR-025, ADR-028, ADR-029, ADR-030, ADR-031, and ADR-037 for config schema, generated state, secret handling, readiness classification, contract envelopes, and Docker/Compose boundary discipline.
Keep the evidence concepts separate:
- MCP-side PTY tee: external, authoritative cross-check outside every container.
- Kali-side PTY transcript: sidecar-owned raw terminal stream and lifecycle metadata.
- Kernel witnesses: sidecar-produced pcap, auditd, and process accounting.
Do not collapse these into one "session transcript" schema or treat one layer's presence as proof that another layer is authentic.
Extensibility¶
The seam belongs at the sidecar's session-launch adapter and recorder configuration, not in MCP tool arguments. An extension can attach the owned PTY slave through another launch mechanism. Another SSH-controlled workload can reuse the same ownership pattern. That should require adding or swapping a sidecar-internal adapter, not editing the run archive layout, creating another session ID vocabulary, or duplicating MCP session management.
Parameterize only the parts that are real variation points:
- PTY launch adapter;
- socket or local endpoint name;
- capture root;
- enabled capture classes;
- pcap rotation limits;
- transcript metadata format version.
Verification Guardrails¶
Tests should prove the ownership boundary, not only artifact creation:
- static Compose tests: Kali has no
kali_capturesmount, and the sidecar owns that volume. PID namespaces remain separate. Capture-only capabilities and control listeners remain outside workload exposure. - MCP/common tests:
capture_container_nameremains the harvest target; close-session and close-all warnings keep the existing envelopes; invalid IDs fail at ingress. - sidecar unit tests: invalid IDs, path-bearing frames, delete/truncate/chmod requests, duplicate/finalized session IDs, spoofed finalize attempts, dropped connections, and transcript integrity metadata.
- live OBS-003 tests: a root Kali shell cannot directly read, modify, or feed its sidecar transcript. Wrapper or shell termination must produce visible lifecycle or integrity evidence. PTY behavior, raw tools, non-echoed input, environment delivery, and exit status remain required.
Changes under mcp/aptl-mcp-common still require rebuilding and testing every
dependent MCP package per the repo plan rules.
Non-Goals¶
- Do not remove Kali passwordless sudo or reduce legitimate red-team tooling.
- Do not redesign MCP commands, session queues, raw/normal mode semantics, OCSF schemas, redaction helpers, runstore layout, exports, or collectors.
- Do not replace the MCP-side PTY tee; keep it as the independent tamper-resistant cross-check.
- Do not make the sidecar transcript a blue-SIEM signal.
- Do not solve complete anti-evasion or anti-DoS against a sudo-capable workload.
- Do not add a database, queue, remote service, or generic command-execution broker for this issue.
Anti-Patterns¶
- Treating workload-fed
script(1)output, wrapper FIFOs, oraptl-capture-clientbyte frames as authentic Kali-side transcript input. - Moving
script(1)into a helper process while the Kali workload still owns the PTY master or transcript feed. - Mounting
kali_capturesinto Kali, even read-only. - Sharing the sidecar PID namespace with Kali.
- Adding a second ID regex, session DTO, transcript schema, harvester, or error envelope.
- Passing transcript bytes, secrets, commands, tcpdump filters, file paths, or chmod/delete requests through the sidecar control protocol.
- Authenticating sidecar control with tokens in env vars, argv, files, or other material readable by the Kali workload after sudo.
- Bypassing
PersistentSessionwith a bespoke MCP-side SSH client to make the PTY proxy easier. - Mounting the Docker socket into the capture sidecar without a separate accepted design for that host-root exposure.
Related¶
- Issue #516
- Supersedes the "PTY transcript authenticity (residual)" section of ADR-041: Kali Capture Sidecar Ownership Boundary
- ADR-033: Red-Side Behavioural Capture and Non-Contamination Boundary
- ADR-029: Control-Plane Secret Handling in Run Data and Local State
- ADR-037: Docker Compose Backend Cohesion
Session finalization at MCP shutdown (#1541)¶
The common SSH manager stops accepting new sessions and waits for pending session creation before shutdown. It tracks one-shot exec channels as well as persistent shells. All harvest triggers share one result per run and session; remote-close failures remain visible to the shutdown owner.
The MCP server starts this shutdown when stdin closes, or when it receives
SIGTERM or SIGINT. A closed stdin is the first shutdown signal of the MCP
stdio transport. The server starts at that signal because the MCP client can
send SIGKILL soon after SIGTERM.
The trusted host invokes broker.py stop-session --run-id ... --session-id ...
through the configured capture container. The broker validates the run against
its active authority and signals only that session's registration. It records
forced-teardown without injecting an agent exit command or quiescing other
MCP servers. Normal agent closes retain their existing shell exit semantics.
metadata.json is the commit marker of a session. Before the host copies a
session, it invokes broker.py await-session with the same arguments. This
action sends no signal.
It waits until the broker releases the session
registration, then requires metadata.json. The host copies the session one
time, after this check passes. It does not poll with repeated copies.
When the check fails, the host writes the harvest-failure record and copies no frames.
A finalization, harvest, or SSH teardown failure makes MCP shutdown exit non-zero. The MCP client can stop the server before this work completes. Lab stop does not use this copy: broker quiescence and export supply the full-run transcript. This decision adds no workload-accessible control endpoint or capture-volume mount.