Repository navigation
Show which command in the sandbox opened each connection - #12
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 addspid,commandandparentstonetwork.jsonl. The fields are optional, so old logs still load.mudroom network logshows the programs behind each host.--alladds[pid] command, and the new--jsonprints the full entries.CAP_SYS_PTRACEandCAP_DAC_READ_SEARCH. Its inheritable and ambient sets are cleared, it starts underenv -ifrom/, and it runs every program by absolute path. The agent's ownsetprivstill drops everything. The token reaches the VM through--env, not argv.docker execas the container user. The forwarder sends a PROXY protocol line so the proxy sees the client's source port.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.