Skip to content

Show which command in the sandbox opened each connection - #12

Merged
Kernel-Hunter merged 8 commits into
mainfrom
log-process
Oct 30, 2026
Merged

Kernel-Hunter merged 8 commits into
mainfrom
log-process

Conversation

@Kernel-Hunter

Copy link
Copy Markdown
Owner

Someone on Product Hunt asked whether the network log shows which command inside the sandbox made each request. It didn't. Now it does.

A small bash script runs in the sandbox next to the agent. When a new connection to the proxy appears in /proc/net/tcp, it finds the process that owns the socket, walks up to the agent (8 levels at most) and reports the source port, pid and command lines to the proxy over its own token-authenticated connection. The proxy matches reports to connections by source port and time and adds pid, command and parents to network.jsonl. The fields are optional, so old logs still load.

  • mudroom network log shows the programs behind each host. --all adds [pid] command, and the new --json prints the full entries.
  • The app's Network tab gets a Command column, with the parent chain in a tooltip.
  • Apple backend: the watcher runs as root with only CAP_SYS_PTRACE and CAP_DAC_READ_SEARCH. Its inheritable and ambient sets are cleared, it starts under env -i from /, and it runs every program by absolute path. The agent's own setpriv still drops everything. The token reaches the VM through --env, not argv.
  • Docker/Podman: the watcher is started with docker exec as the container user. The forwarder sends a PROXY protocol line so the proxy sees the client's source port.
  • Refused requests wait up to 0.5 s for their report, but only while a watcher is connected. Reports are rate limited and the per-entry command text is capped at about 1 KB.

This is informational. The allowlist never depends on it. A process can rename itself, and on Docker the agent can stop the watcher. The README covers these limits.

Measured on a real locked session: about 0.2% of one core at idle, 50 of 50 connections attributed (git, python, node, blocked requests). Connections shorter than about 30 ms can show as "unknown".

Tests: 306 (23 new for parsing, matching, old logs, labels, the PROXY line and the proxy's report handling). The bash watcher itself is covered by end-to-end runs on the Apple VM and Docker, since it needs Linux /proc.

A watcher script runs in the VM next to the agent. It polls TCP's
ActiveOpens counter, finds new connections to the proxy in
/proc/net/tcp(6), resolves each socket to a pid through /proc/*/fd, and
reports source port, pid and the command lines up to the agent over its
own proxy connection, which starts with a per-session token. The proxy
matches reports by source port and arrival time and adds pid, command
and parents to network.jsonl. Refusals wait up to 0.5 s for the report.

Apple backend: the firewall script starts it as root with only
CAP_SYS_PTRACE and CAP_DAC_READ_SEARCH. Docker and Podman: started with
exec once the container runs; the forwarder sends a PROXY line so the
client's source port reaches the proxy.
The per-host view lists the programs that connected; --all adds the pid and command line, cut to fit. --json prints the entries with the full command lines.
A Command column in the connection list, with the parent processes in its tooltip, and the programs under each host.
…bounded reports

- The firewall script starts the watcher from /, with env -i and a fixed
  PATH, setpriv, env and bash by absolute path, and setpriv clearing the
  inheritable and ambient sets as well as the bounding set. A
  here-document passes the token, so no root shell waits beside it.
- The token reaches the VM with `--env NAME` instead of argv and is unset
  before the agent starts. The watcher sets its own PATH, works from /
  and runs find by absolute path.
- The proxy holds refusals and log lines for a report only while a
  watcher is connected; processWatch is recorded once one has connected.
- Reports wake only the waiters for their port, are rate limited per
  watcher connection, and the arrival list is compacted.
- Command lines are capped at about 1 KB per entry, cleaned of invisible
  format characters, and cleaned again when the log is read.
- The Docker forwarder turns off Nagle, so the PROXY line isn't delayed.
@Kernel-Hunter
Kernel-Hunter merged commit cc7dc40 into main Oct 30, 2026
10 checks passed
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