ADR-041: Kali Capture Sidecar Ownership Boundary¶
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 moved red-side behavioural capture out of the SIEM and into per-run artifacts. The current Kali-side writers still run in the Kali container:
containers/kali/scripts/aptl-wrap-shell.shcreates per-session directories and runsscript(1)plustcpdump.containers/kali/entrypoint.shstartsauditdand process accounting against/var/log/aptl/captures/_auditand_proc-acct.mcp/aptl-mcp-common/src/captures.tsharvests the named volume withdocker cpinto.aptl/runs/<run_id>/kali-side/<session_id>/.
The workload user is kali and intentionally has passwordless sudo for
legitimate red-team tooling. Unix ownership inside the workload is not a sufficient integrity boundary. A sudo su - workload can remove or truncate files in that writable mount. A root-owned daemon or separate capture user in the same writable mount namespace does not alone meet issue #305.
Decision¶
Use a dedicated capture sidecar service, aptl-kali-capture, as the
Kali-side capture writer. The sidecar is part of the kali profile, shares
ONLY the Kali container's network namespace (so tcpdump sees Kali's traffic
and the abstract socket is mutually reachable), and mounts the kali_captures
volume read-write. It does not share Kali's PID namespace. Otherwise, a root workload could reach sidecar mounts through /proc/<sidecar-pid>/root. The original audit and accounting sources did not need PID sharing.
The Kali workload container does not mount kali_captures at all, not even
read-only. Read-only mounts prevent writes but still expose sibling-session transcripts and pcaps to sudo-capable readers. That would fail issue #305's cross-session disclosure criterion. The selected boundary keeps the capture sink outside the workload mount namespace. This denies direct read, listing, and modification through workload paths. The kali user, including after
sudo su -, therefore has no filesystem path to any capture evidence,
neither its own session's nor any other's.
The host-side harvest runs docker cp against the sidecar
(aptl-kali-capture), not the workload container, since the sidecar is where
the volume is mounted. This is wired through the existing capture-container
configuration path (capture_container_name in the MCP lab config; see
resolveCaptureContainer), so no second harvester is introduced.
Update (2026-10-30, #1242): the harvest targets only a declared capture sidecar. It never falls back to the workload container. Lab start supplies the workspace-scoped sidecar name in
LILRAE_MCP_CAPTURE_CONTAINER. If that name is not set or not valid, the harvest recordsaptl.capture-harvest.container-unresolvedand runs nodocker cp.
The Kali ForceCommand wrapper remains the single SSH session ingress point, but it stops writing capture files directly. Its responsibility becomes:
- validate/fallback
APTL_RUN_IDandAPTL_SESSION_IDwith the canonical OBS-003 identifier contract; - open a local Unix-domain control connection to the capture sidecar;
- notify the sidecar of session start and session exit;
- continue the shell session if the sidecar is unavailable, logging a narrow warning rather than rejecting SSH login.
The sidecar owns all paths below /var/log/aptl/captures:
- per-session PTY transcript/timing artifacts;
- per-session pcap rotation;
_audit/audit.log;_proc-acct/pacct.
The sidecar also owns auditd and accton startup. Move
AUDIT_CONTROL, AUDIT_WRITE, and SYS_PACCT capability requirements from
the Kali workload service to the sidecar wherever Docker permits. Kali keeps tooling capabilities such as NET_RAW and NET_ADMIN. It must not keep capabilities used only to manage capture subsystems.
Update (2026-10-12, #1328): the shipped sidecar runs neither auditd nor process accounting. It does not own
_audit/audit.logor_proc-acct/pacct, does not startauditdoraccton, and is granted none ofAUDIT_CONTROL,AUDIT_WRITE, orSYS_PACCT(see thekali-captureservice indocker-compose.capture.yml). The harvest no longer copies the global_audit/_proc-acctdirectories (#1242, recorded in ADR-042).The
_auditand_proc-acctentries above describe the 2026-06-20 design. Their auditd, accton, and capability assignments are not current. This correction applies to every auditd or process-accounting claim in this record.It includes ownership, harvest sources, test expectations, and witness-integrity claims.
Update (2026-10-28, #1495): the sidecar is granted
AUDIT_WRITEagain, for a reason the 2026-06-20 design did not cover; it still runs no auditd. Debian sshd writes a kernel audit login record when it allocates an outer-session PTY. Refusal of that write drops the connection. Without the capability, every participant session that requested a PTY failed to open, while sessions without one worked.AUDIT_CONTROLandSYS_PACCTstay withdrawn, and the 2026-10-12 update still holds for the audit and accounting writers.Update (2026-10-29, #1407): the sidecar is granted
KILL. At lab stop,broker.py quiesceruns as root and sends SIGTERM to each open broker session. Those sessions run as uidkali, so the kernel refuses the signal without the capability. A participant session that stayed open until lab stop then made quiesce fail, and the run lost its required transcript. The capability applies only to processes in the sidecar's own PID namespace.
RPC Contract¶
The sidecar RPC is a small local control protocol, not a file API.
- Transport: Unix-domain socket only. Prefer an abstract socket or read-only socket-path mount. A root workload must not be able to replace or unlink the endpoint.
- Authentication/authority: use kernel peer credentials and a per-session control connection. Do not use an env-var token, argv token, shared secret, or file token that the Kali workload can read after sudo.
- Messages: bounded JSON frames with a version, event type, run id, session id, timestamp, and minimal process metadata. If the chosen PTY recorder needs byte frames from the wrapper, those frames are append-only data events on the same session connection.
- Path derivation: the sidecar derives all filesystem paths from validated run/session ids and fixed capture-root constants. RPC messages must never carry absolute output paths, relative path fragments, shell commands, chmod modes, delete requests, truncate requests, or arbitrary tcpdump arguments.
- Lifecycle: start is idempotent for a session; exit/EOF finalizes the per-session capture. A stop/finalize frame is accepted only from the same registered peer connection or registered peer pid. Other Kali processes, including sudo-root shells, may at most cause an observable denial-of-service; they must not gain a write/delete primitive over capture files.
script(1) is not magic by itself in a sidecar. The implementation must make
the sidecar the owner of the PTY transcript data path. Running script(1) in
the sidecar is acceptable only if it actually owns the wrapped PTY/session
recording. Otherwise, the sidecar should write script-compatible
typescript/timing artifacts from a wrapper-to-sidecar byte stream. Do not leave
script(1) writing in the Kali container and call the result protected.
Security Layers¶
- Auth surface: no host-published port and no remote API. The only new control surface is local to the Kali network namespace (the abstract socket). It accepts only the bounded capture-control contract above and never exposes command execution or filesystem mutation operations.
- Secret handling: the RPC carries correlation ids and capture metadata, not secrets. Captured PTY, pcap, audit, and pacct content may contain secret-shaped target data by design; treat these files as raw evidence with restrictive modes. Do not log transcript bytes, pcap payloads, command lines with credentials, or raw audit records from the sidecar on failures.
- Identifier validation: reuse the canonical OBS-003 id rule already
mirrored by
src/aptl/core/runstore.py,mcp/aptl-mcp-common/src/runs.ts, MCP ingress session checks, and the Bash wrapper:^[A-Za-z0-9_][A-Za-z0-9._-]*$and no... Do not add a looser sidecar-only schema. - Config shape: the sidecar is part of the existing Compose
kaliprofile, not a new durableaptl.jsonfeature flag. Necessary runtime settings belong in parsed sidecar environment variables with safe defaults. Examples include socket name, capture root, enabled classes, and pcap rotation limits. AddAptlConfigfields only for durable first-party user configuration. - OS and mount exposure: the capture volume is mounted read-write only in
the sidecar and is not mounted in the Kali workload at all. The barrier
is the absence of the sink from Kali's mount namespace, not
0700 root:root,chattr, setuid helpers, a non-sudo capture user, or anromount (all of which asudo-capable agent reads through or around). - Process argv: do not pass secrets, full command lines, or user-controlled tcpdump expressions through shell strings. Prefer argv arrays and fixed recorder arguments such as the existing pcap rotation policy.
- Error envelopes: writer unavailability is best-effort: wrapper logs and
continues; MCP close handlers preserve the existing
harvest_warningbehavior; startup/readiness surfaces may report degraded capture state using the existing health/readiness pattern. Do not introduce a new exception hierarchy or make capture startup a hard precondition for opening a shell. - Persistence and harvest: keep the host-side run layout owned by
LocalRunStoreandmcp/aptl-mcp-common/src/runs.ts. Keepmcp/aptl-mcp-common/src/captures.tsas the harvest/chmod boundary and preserve its no-PATH Docker binary resolution. Harvest runs against the sidecar (aptl-kali-capture), resolved through the existing container-name configuration path: acapture_container_namefield on the MCP lab config thatresolveCaptureContainerreturns in preference to the workloadcontainer_name. No second harvester is introduced;docker cpreads the same volume from whichever container mounts it. Update (2026-10-30, #1242):resolveCaptureContainerreturns onlycapture_container_name. The workloadcontainer_nameis not a harvest target, and the MCP lab config no longer has that field.
Maintainability¶
Implementations must build on the existing incumbents:
containers/kali/scripts/aptl-wrap-shell.sh: the single ForceCommand entry point and the existing Bash id fallback contract.containers/kali/audit/aptl.rules: the canonical audit rule set. Copy or mount this into the sidecar; do not duplicate rule text. Update (2026-10-12, #1328): the shipped sidecar runs no auditd, so its image neither copies nor mounts this rule set.mcp/aptl-mcp-common/src/ssh.ts:APTL_SESSION_ID,APTL_RUN_ID, bound run id, remote-close await, and best-effort PTY tee semantics.mcp/aptl-mcp-common/src/tools/handlers.ts: close-session and close-all harvest warning envelopes.mcp/aptl-mcp-common/src/captures.ts: docker-copy harvest, global_audit/_proc-acctcollection, destination chmod repair, and fail-loud missing-source behavior. Update (2026-10-12, #1328): since #1242 the harvest collects no global_audit/_proc-acctdirectories.src/aptl/core/runstore.pyandmcp/aptl-mcp-common/src/runs.ts: per-run directory and id contracts.- ADR-033 non-contamination: do not reintroduce Wazuh, rsyslog, SIEM dispatch, or a blue-visible red telemetry feed from Kali.
- ADR-028, ADR-029, ADR-030, ADR-031, and ADR-037 for generated state, secret handling, degraded readiness, lifecycle envelopes, and Docker/Compose boundary discipline.
Static and live tests should pin the boundary, not just the happy path:
- Compose consistency:
kali_capturesis absent from Kali and writable only inaptl-kali-capture. The original implementation paragraph below described PID and network sharing. The later correction above withdraws PID-sharing and audit/accounting claims. The sidecar has no host publications orhostnameoverride. - OBS-003 live tests:
sudo su -cannot directly access the absent capture mount. The recordedsudo rm -rf /var/log/aptl/captures/*attempt did not remove sidecar evidence. The original audit and accounting expectations are superseded above. Separate sessions cannot read each other's retained files through that mount. - RPC unit tests: invalid ids, path-bearing messages, delete/truncate frames, spoofed stop/finalize attempts, and writer-unavailable paths.
- Existing MCP tests: harvest remains best-effort and surfaces warnings rather than breaking command/session results.
Extensibility¶
The extensibility seam is the sidecar-owned capture writer contract:
- socket endpoint;
- capture root;
- enabled capture classes;
- pcap rotation limits;
- future session-scoped capture subdirectories under
<state>/runs/<run_id>/kali-side/<session_id>/.
Add the next capture source by extending the sidecar writer and adding a new
subdirectory under the existing per-session or _global layout. Do not change
the run archive root, duplicate the harvester, or add another MCP session id
concept.
PTY transcript authenticity (residual)¶
Superseded by ADR-042: Sidecar-Owned PTY Master for Kali Transcript Authenticity (2026-06-20). ADR-042 moves PTY-master ownership into the sidecar so the Kali-side typescript is tamper-resistant against the workload's own session. The residual recorded below documents why issue #305 shipped without that property; ADR-042 is the design that closes it.
The sink is unreadable and unwritable through the Kali mount namespace. The original paragraph also claimed kernel-source witnesses for pcap, auditd, and accounting. The later audit/accounting withdrawal limits those claims. It does not make the Kali-side PTY typescript tamper-proof for the workload's own session.
Update (2026-10-12, #1328): auditd and process accounting are no longer among these witnesses, because the shipped sidecar produces neither (see the update at the end of the Decision).
The reason is fundamental: a shell transcript is generated by the shell, which runs in the Kali container. A sudo-capable workload can forge its own workload-fed transcript. It can emit fake output, invoke the client, or write its wrapper FIFO and descriptors. Connection ownership prevents cross-session append. Single-use IDs prevent reopening finalized sessions. Neither control authenticates a workload-fed in-flight transcript.
The MCP-side PTY tee supplies an independent record through createPtyTeeWriter in mcp/aptl-mcp-common/src/runs.ts. That process sits outside the containers and their workload mount namespaces. The
Kali-side typescript is a convenience secondary to it.
Authenticating the Kali-side transcript requires the sidecar to own the PTY master. Moving the SSH or PTY boundary was separate work, later defined by ADR-042. It would be its own ADR if pursued.
Consequences¶
Positive¶
- The capture sink is outside the Kali workload's write authority, including sudo-root inside the Kali container.
- The red workload remains operational when the writer is degraded.
- The architecture preserves ADR-033 non-contamination by keeping observation outside the blue defensive stack.
- MCP-side PTY tee, tool-call JSONL, OCSF JSONL, and Kali-side artifacts keep the same correlation keys and host-side run layout.
Negative¶
- The lab gains another container in the
kaliprofile. - Session capture now has an RPC lifecycle that must be tested for ordering, spoofing, and unavailable-writer behavior.
- PTY transcript capture needs deliberate design; sharing the network
namespace alone does not make sidecar
script(1)observe a shell. This older RPC path accepts workload-supplied transcript bytes and cannot prevent self-forgery. The MCP-side tee remains independent. ADR-042 supersedes the workload-fed PTY design; later updates withdraw audit/accounting witnesses. Update (2026-10-12, #1328): the shipped sidecar produces no auditd or process-accounting stream (see the update at the end of the Decision).
Risks¶
- A sudo-root Kali workload can still attempt denial-of-service against the session, wrapper, network namespace, or capture sidecar. This ADR prevents read, delete, alter, and truncate of capture evidence from Kali; it does not make the workload incapable of noisy self-sabotage.
- Docker/runtime differences around auditd, process accounting, and Unix socket mounts can degrade capture on some hosts. That degradation must be visible through the existing readiness/logging surfaces.
- If implementation mounts the volume in Kali at all (even read-only), the
design fails the cross-session read-isolation acceptance criterion regardless
of daemon code quality:
roblocks writes, not a sudo-rootcat.
Non-Goals¶
- Do not remove Kali passwordless sudo or reduce legitimate red-team tooling.
- Do not redesign MCP command execution, session queues, OCSF schemas, redaction helpers, runstore layout, or export/archive semantics.
- Do not make capture writer availability a hard gate for SSH login.
- Do not add a database, broker, remote service, or SIEM transport for the capture path.
- Do not solve complete anti-evasion or anti-DoS against a sudo-capable workload in this issue.
Anti-Patterns¶
- Treating root-owned files, setuid helpers, ACLs, or a dedicated capture user
inside the same writable Kali container as tamper-resistant against
sudo su -. - Mounting
kali_capturesinto Kali at all (read-write or read-only) for wrapper or harvest compatibility. A read-only mount still exposes every session's evidence to a sudo-rootcat. - Letting the wrapper create, chmod, truncate, rotate, or delete files under
/var/log/aptl/captures. - Adding a second id regex, second run directory layout, second harvester, or second capture-warning envelope.
- Accepting arbitrary paths, shell commands, tcpdump filters, delete requests, or chmod/chown requests over the sidecar RPC.
- Authenticating the RPC with a token in environment variables, argv, a file in Kali, or any material readable by the workload after sudo.
- Reintroducing any red-to-SIEM pipe as a shortcut for durable capture.