Add agentjail implementation: sandbox, proxy, relay, CLI, tests and CI/CD#1
Add agentjail implementation: sandbox, proxy, relay, CLI, tests and CI/CD#1
Conversation
|
@copilot Did you add and commit and push to code? |
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> Agent-Logs-Url: https://github.com/kitproj/agentjail/sessions/0d0544bb-2185-4e3e-a698-8187bd9241db
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> Agent-Logs-Url: https://github.com/kitproj/agentjail/sessions/0d0544bb-2185-4e3e-a698-8187bd9241db
Yes – the full implementation has been committed and pushed in commit Here's what was added:
All security-blocking tests pass; internet-dependent tests skip gracefully in this restricted environment. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
sock_path = '/tmp/agentjail-test2-4445/proxy.sock' s = socket.socket(socket.AF_UNIX) def pipe(src, dst):` (dns block)
|
…multiFlag, add README Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> Agent-Logs-Url: https://github.com/kitproj/agentjail/sessions/19f1c869-524d-452a-b2e4-4929211a24f3
README added in Regarding why there are many files: the original repo only had
|
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> Agent-Logs-Url: https://github.com/kitproj/agentjail/sessions/bb70831b-1563-4980-a8e1-03f62b06048d
alexec
left a comment
There was a problem hiding this comment.
Look at https://github.intuit.com/kitproj/jira-cli for how to set-up GitHub Actions to verify the code changes and release. Add the correct files (you might wish to just to copy their files and change the names).
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> Agent-Logs-Url: https://github.com/kitproj/agentjail/sessions/f7c87fc3-b834-4700-a46a-488d628e8977
Yes — all code was committed and pushed in the earlier commits on this branch. The latest commit is
Added in
|
Implements the complete
agentjailpackage from scratch. The repository previously contained only aREADME.md.Architecture
Network isolation is achieved through a layered approach:
Filtering HTTP proxy (
pkg/agentjail/tinyproxy.go) — A Go HTTP/HTTPS proxy (CONNECT + plain HTTP) that listens on a Unix socket on the host filesystem. Enforces a domain allowlist (nil = allow all public destinations) and unconditionally blocks private/link-local IP ranges (RFC 1918,169.254.0.0/16, loopback, ULA, link-local IPv6).TCP→Unix relay (
pkg/agentjail/relay.go) — Usessocatto bridge127.0.0.1:3128inside the sandbox to the proxy's Unix socket. Unix sockets are accessible across network namespaces via the shared filesystem bind-mount.socatis used to avoid any dependency on an external language runtime (Python, Node, JVM, etc.). The relay usesexec.CommandContextso the socat process is automatically killed when the context is cancelled.Sandbox (
pkg/agentjail/sandbox.go) — Runs the command viasudo bwrap --unshare-net --unshare-pid. Sets upiptables(IPv4 allows only TCP to loopback port 3128) andip6tables(drops everything). Executes the command asnobodyto prevent privilege escalation viasudo.Public API (
pkg/agentjail/run.go) —Run(ctx, allow, command)orchestrates the proxy, relay, and sandbox.CLI (
cmd/agentjail/main.go+cmd/agentjail/flags.go) — Command-line wrapper with--allow PATTERNflags. ThemultiFlaghelper type lives in its ownflags.gofile.Test files
cmd/agentjail/security_test.gocmd/agentjail/curl_test.gocmd/agentjail/agent_test.gocmd/agentjail/escape_test.gosudo -n truemust fail inside the sandboxpkg/agentjail/network_jail_test.goCI/CD
.github/workflows/go.ymlgo buildandgo teston every push and pull request tomain.github/workflows/release.ymlgo vet+go test, builds Linux amd64/arm64/386 binaries (agentjail is Linux-only due to bwrap/iptables), generateschecksums.txt, and publishes a GitHub Release viasoftprops/action-gh-releaseNotable implementation details
socatstarts the listening TCP port synchronously before accepting connections, so only a short fixed delay is needed before entering the sandbox.sudoPAM helpers briefly hold the write-end ofgo test's stdout pipe after the main process exits. Fixed by capturing subprocess output to abytes.BufferwithWaitDelay = 3s, then falling back toProcessState.ExitCode()whenErrWaitDelayis returned for a successful exit.bufio.Readerreuse: A single reader is created per proxy connection so that data buffered while parsing the HTTP request is not lost when switching to raw tunnel copying after aCONNECTresponse.--unshare-pid: Private PID namespace ensures all sandbox processes are reaped when bwrap exits.Requirements
bwrap(bubblewrap),socat,sudo, andiptables/ip6tablesmust be available on the host. On Debian/Ubuntu:sudo apt-get install bubblewrap socat.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.