feat(upstream): native sandbox launcher (Landlock + rlimits) for stdio servers (MCP-34.3)#768
Open
Dumbris wants to merge 1 commit into
Open
feat(upstream): native sandbox launcher (Landlock + rlimits) for stdio servers (MCP-34.3)#768Dumbris wants to merge 1 commit into
Dumbris wants to merge 1 commit into
Conversation
…o servers (MCP-34.3)
Implements the `sandbox` spawn branch alongside docker/plain in connectStdio and
buildLauncherCmd, using the Landlock mechanism proven by the MCP-34.1 spike and
wired into the mode-aware selector from MCP-34.2.
Mechanism: a tiny re-exec wrapper. mcpproxy launches itself as
`mcpproxy __sandbox_exec -- <command> [args...]` with the confinement Spec
encoded in the environment; the hidden child applies Landlock + setrlimit, does a
best-effort uid/gid drop, then execs the real command — so confinement is
inherited across execve and the server's stdin/stdout pass straight through with
no mux. Reuses the existing SysProcAttr{Setpgid} process-group cleanup.
- internal/sandbox: WrapCommand/SpecFromEnv (cross-platform), RunChild (unix +
non-unix guard), Available() honest-diagnostic helper.
- internal/upstream/core: wrapWithSandbox + buildSandboxSpec (filesystem WRITE
allowlist: RO "/", RW working_dir + temp + package caches; RLIMIT_CORE=0 +
NOFILE; BestEffort graceful degrade). Wired into both stdio + launcher plain
branches behind ResolveMode == sandbox.
- cmd/mcpproxy: hidden __sandbox_exec subcommand.
- Graceful fallback: non-Linux / Landlock-less kernels degrade to unconfined
(effective "none") with a logged diagnostic; fail-closed when BestEffort=false.
- docs/features/sandbox-isolation.md documents enforcement, honest limits
(no read confinement, uid/gid no-op without root), and platform support.
Tests (red→green): WrapCommand argv/env round-trip, SpecFromEnv absent/malformed,
buildSandboxSpec write-allowlist defaults; Linux end-to-end (cmd construction,
RLIMIT_NOFILE application, write-outside-allowlist denied, stdin/stdout
passthrough) + fail-closed refuses to run unconfined. Landlock enforcement runs
on ubuntu-latest CI (24.04), mirroring the MCP-34.1 spike's empirical proof.
Co-Authored-By: Paperclip <[email protected]>
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 28144942328 --repo smart-mcp-proxy/mcpproxy-go
|
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.
What
Implements the
sandboxspawn branch alongside docker/plain inconnectStdioandbuildLauncherCmd(MCP-34.3), using the Landlock mechanism proven by the MCP-34.1 spike (#754) and wired into the mode-aware selector from MCP-34.2 (#759).Mechanism — re-exec wrapper
Landlock confines the current process and every process it then execs, irreversibly — so it can't be applied in-process before mcp-go spawns the server. Integration is a tiny re-exec wrapper:
with the confinement
SpecJSON-encoded in the env. The hidden child applies Landlock +setrlimit, does a best-effort uid/gid drop, thenexecs the real command. Confinement is inherited acrossexecve; stdin/stdout pass straight through, no mux. Reuses the existingSysProcAttr{Setpgid}process-group cleanup.Scope coverage
RLIMIT_CORE=0,RLIMIT_NOFILE)/, RW = working_dir + temp + package cachesSetuid/Setgidonly when root w/ non-root real user — documented no-op otherwise)none)ResolveMode == sandbox(MCP-34.2 selector) in both stdio + launcher pathsHonest limits (documented in
docs/features/sandbox-isolation.md)CAP_SETUID.dockermode for a hard guarantee.Tests (red→green)
internal/sandbox:WrapCommandargv/env round-trip,SpecFromEnvabsent/malformed.internal/upstream/core:buildSandboxSpecwrite-allowlist defaults; Linux end-to-end via real re-exec — cmd construction,RLIMIT_NOFILEapplication, write-outside-allowlist denied, stdin/stdout passthrough; fail-closed refuses to run unconfined.ubuntu-latestCI (24.04) — same empirical-proof approach as the MCP-34.1 spike (sandbox.Available()skips on kernels without Landlock).Local:
go build ./...,go vet(linux cross),go test ./internal/sandbox/... ./internal/upstream/core/..., gofmt, golangci-lint v2 all clean.Closes MCP-3234.