-
Notifications
You must be signed in to change notification settings - Fork 0
feat(groom): isolated netns sandbox — drop --share-net, broker over a bind-mounted unix socket (BE-4421) #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattmillerai
wants to merge
2
commits into
matt/be-4302-groom-sandbox
Choose a base branch
from
matt/be-4421-groom-sandbox-netns
base: matt/be-4302-groom-sandbox
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // jail-shim.mjs — an in-jail TCP→UDS forwarder for the groom agent sandbox | ||
| // (BE-4421, phase 2). | ||
| // | ||
| // node jail-shim.mjs <port> <socket-path> | ||
| // | ||
| // The sandbox (agent-sandbox.sh) runs the agent in an ISOLATED network namespace | ||
| // with only loopback up and no egress; the key-broker (broker.mjs) is reachable | ||
| // only as a unix-domain socket bind-mounted into the jail at /run/broker.sock. | ||
| // Agent tooling that speaks HTTP to a host:port (e.g. an Anthropic base URL) can't | ||
| // dial a unix socket, so this shim listens on jail-local loopback and forwards | ||
| // every connection to the socket. It runs INSIDE the jail as part of the | ||
| // sandboxed command (background it, then exec the agent); an agent that kills it | ||
| // only breaks its own API access. | ||
|
|
||
| import net from 'node:net'; | ||
|
|
||
| const port = Number(process.argv[2]); | ||
| const sockPath = process.argv[3]; | ||
| if (!Number.isInteger(port) || port <= 0 || port > 65535 || !sockPath) { | ||
| console.error('jail-shim: usage: node jail-shim.mjs <port> <socket-path>'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const server = net.createServer((c) => { | ||
| const u = net.connect(sockPath); | ||
| c.pipe(u); | ||
| u.pipe(c); | ||
| c.on('error', () => u.destroy()); | ||
| u.on('error', () => c.destroy()); | ||
| }); | ||
|
|
||
| // The shim is backgrounded inside the jail while the caller captures the command's | ||
| // stdout as the agent's JSON output; a listen failure surfacing as an uncaught | ||
| // 'error' would kill the shim with a raw stack trace, so handle it and exit clean. | ||
| server.on('error', (e) => { | ||
| console.error(`jail-shim: listen failed on 127.0.0.1:${port}: ${e.message}`); | ||
| process.exit(1); | ||
| }); | ||
|
|
||
| server.listen(port, '127.0.0.1', () => { | ||
|
mattmillerai marked this conversation as resolved.
|
||
| // stderr, NOT stdout: the shim runs backgrounded alongside the agent whose stdout | ||
| // the caller captures as JSON — a banner on stdout would corrupt that capture. | ||
| console.error(`shim listening on 127.0.0.1:${port} -> ${sockPath}`); | ||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.