You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 11fd7ef
Browse filesBrowse the repository at this point in the historyBrowse files
fix(sandbox): enforce network namespace and proxy policy in SSH sessions (!17)
Closes#24
## Problem
SSH sessions into the sandbox were **not entering the network namespace** or receiving proxy environment variables. This meant every command run via SSH (the only user-facing path) had unrestricted internet access, completely bypassing OPA network policy enforcement.
The root cause: the SSH server was started **before** the network namespace and proxy were created in `lib.rs`, so it never received the netns fd or proxy URL.
Additionally, **gRPC inference from within the sandbox did not work at all** — even after fixing the netns, multiple issues prevented the Python SDK from reaching the navigator server through the CONNECT proxy.
## Changes
### Sandbox binary
**Core fix — reorder startup + thread netns through SSH:**
- `lib.rs`: Move netns + proxy creation before SSH server start. Compute `ssh_netns_fd` and `ssh_proxy_url`, pass them to `run_ssh_server()`.
- `ssh.rs`: Thread `netns_fd` and `proxy_url` through the full SSH call chain into `spawn_pty_shell()`. Set proxy env vars on the shell command. Call `setns(fd, CLONE_NEWNET)` in `install_pre_exec()`.
**Proxy — control plane allowlist + IPv6 socket lookup:**
- `proxy.rs`: Connections to the navigator endpoint (derived from `NAVIGATOR_ENDPOINT`) are always allowed without OPA evaluation, logged with `engine=control_plane`. This is infrastructure the sandbox needs to function, not a user-configurable policy.
- `procfs.rs`: Extended `parse_proc_net_tcp` to also check `/proc/<pid>/net/tcp6`. gRPC C-core uses `AF_INET6` sockets even for IPv4 connections, so its TCP entries were invisible to the proxy's identity resolver. Also fixed port parsing to use `rsplit_once(':')` for correct IPv6 address handling.
**Proxy env vars — lowercase variants for gRPC C-core:**
- `process.rs` + `ssh.rs`: Added lowercase `http_proxy`, `https_proxy`, `grpc_proxy` alongside uppercase. gRPC C-core (libgrpc) checks lowercase first and was ignoring the uppercase-only vars.
### Server
- `sandbox/mod.rs`: Added `CAP_SYS_PTRACE` to sandbox pod security context. Required for the proxy (root) to read `/proc/<pid>/fd/` of sandbox-user processes for binary identity resolution.
### Python SDK
- `inference.py`: Strip `http://`/`https://` scheme from endpoint before passing to `grpc.insecure_channel()`, which expects `host:port`. Default `endpoint` and `sandbox_id` from `NAVIGATOR_ENDPOINT` / `NAVIGATOR_SANDBOX_ID` env vars so `Inference()` works inside sandboxes with no arguments.
### Build / infra
- `ci.toml`: Added `--cap-add=SYS_PTRACE` to `mise run sandbox` to mirror the k8s pod capabilities.
### Documentation
- `architecture/sandbox.md`: Documented `CAP_SYS_PTRACE` requirement and the full set of proxy env vars (uppercase + lowercase).
## Testing
All 29 sandbox unit tests pass. `mise run pre-commit` passes (fmt, clippy, all workspace tests, python lint).
E2E verified on a live cluster:
| Test | Result |
|------|--------|
| Proxy env vars (6 vars, upper+lowercase) | PASS |
| Blocked endpoints (google, anthropic via curl) | PASS — all denied |
| **gRPC inference from SSH session** (`Inference()` with no args, env var defaults) | **PASS** |
| Proxy log: navigator requests show `engine=control_plane` | PASS |
| Proxy log: blocked requests show `engine=opa` with correct deny reasons | PASS |
Copy file name to clipboardExpand all lines: architecture/sandbox.md
+11-2Lines changed: 11 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,6 +108,12 @@ The implementation lives in `crates/navigator-sandbox/src/sandbox/linux/netns.rs
108
108
109
109
-`CAP_SYS_ADMIN`: Required for creating namespaces and mount operations
110
110
-`CAP_NET_ADMIN`: Required for creating veth pairs and configuring interfaces
111
+
-`CAP_SYS_PTRACE`: Required for the CONNECT proxy to read `/proc/<pid>/fd/` and
112
+
`/proc/<pid>/exe` of sandbox-user processes. The proxy resolves binary identity by mapping
113
+
TCP socket inodes (from `/proc/<entrypoint>/net/tcp{,6}`) to process file descriptors,
114
+
then reading the executable symlink. Without this capability, the kernel blocks access to
115
+
`/proc/<pid>/fd/` for processes running as a different user (the proxy runs as root,
116
+
sandboxed processes run as the `sandbox` user).
111
117
-`iproute2` package: Provides the `ip` command for namespace/interface setup
112
118
113
119
If namespace creation fails (e.g., missing capabilities), the sandbox logs a warning and continues
@@ -118,8 +124,11 @@ production deployments should ensure capabilities are granted.
118
124
119
125
The sandbox exports proxy configuration to the child process:
120
126
121
-
-`HTTP_PROXY` / `HTTPS_PROXY` / `ALL_PROXY`: Set to `http://10.200.0.1:3128` (with netns) or
All set to `http://10.200.0.1:3128` (with netns) or `http://127.0.0.1:3128` (without netns).
Copy file name to clipboardExpand all lines: crates/navigator-sandbox/src/process.rs
+10-2Lines changed: 10 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -93,14 +93,22 @@ impl ProcessHandle {
93
93
// The proxy is on 10.200.0.1:3128 (or configured port)
94
94
let port = proxy.http_addr.map_or(3128, |addr| addr.port());
95
95
let proxy_url = format!("http://10.200.0.1:{port}");
96
+
// Both uppercase and lowercase variants: curl/wget use uppercase,
let proxy_url = format!("http://{http_addr}");
0 commit comments