|
| 1 | +name: Sandbox Integration Tests |
| 2 | + |
| 3 | +# MCP-34.5 / MCP-3236: Prove sandbox isolation works on Linux (Landlock LSM). |
| 4 | +# ubuntu-latest == Ubuntu 24.04, kernel 6.8 — Landlock ABI ≥ 3 available. |
| 5 | +# These tests are also covered by unit-tests.yml; this job surfaces them |
| 6 | +# explicitly and adds the server-startup probe so CI shows dedicated evidence. |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: ["*"] |
| 11 | + paths: |
| 12 | + - "internal/sandbox/**" |
| 13 | + - "internal/upstream/core/sandbox*.go" |
| 14 | + - "internal/security/scanner/**" |
| 15 | + - "internal/upstream/core/**" |
| 16 | + - ".github/workflows/sandbox-integration.yml" |
| 17 | + pull_request: |
| 18 | + branches: ["*"] |
| 19 | + paths: |
| 20 | + - "internal/sandbox/**" |
| 21 | + - "internal/upstream/core/sandbox*.go" |
| 22 | + - "internal/security/scanner/**" |
| 23 | + - "internal/upstream/core/**" |
| 24 | + - ".github/workflows/sandbox-integration.yml" |
| 25 | + workflow_dispatch: |
| 26 | + |
| 27 | +jobs: |
| 28 | + sandbox-integration: |
| 29 | + name: Sandbox Integration (Linux / Landlock) |
| 30 | + runs-on: ubuntu-latest |
| 31 | + |
| 32 | + env: |
| 33 | + GO111MODULE: "on" |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout code |
| 37 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 38 | + |
| 39 | + - name: Set up Go |
| 40 | + uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 |
| 41 | + with: |
| 42 | + go-version: "1.25" |
| 43 | + cache: true |
| 44 | + |
| 45 | + - name: Download dependencies |
| 46 | + run: go mod download |
| 47 | + |
| 48 | + # Confirm the kernel supports Landlock before running enforcement tests. |
| 49 | + - name: Check Landlock availability |
| 50 | + run: | |
| 51 | + uname -r |
| 52 | + if grep -qi landlock /proc/kallsyms 2>/dev/null || \ |
| 53 | + cat /proc/sys/kernel/landlock/abi 2>/dev/null | grep -q "[1-9]"; then |
| 54 | + echo "Landlock available" |
| 55 | + else |
| 56 | + # ubuntu 24.04 exposes ABI via a prctl probe — let the Go test skip logic handle it |
| 57 | + echo "Landlock probe inconclusive — Go tests will auto-skip if unavailable" |
| 58 | + fi |
| 59 | +
|
| 60 | + # 1. sandbox package: Landlock enforcement (TestLandlockEnforcesFilesystemAllowlist), |
| 61 | + # wrap/encode round-trip, rlimit constants. |
| 62 | + - name: Run sandbox package tests |
| 63 | + run: go test -v -race ./internal/sandbox/... |
| 64 | + |
| 65 | + # 2. upstream/core: wrapWithSandbox full re-exec integration |
| 66 | + # (TestSandboxWrapper_EndToEnd, TestSandboxWrapper_FailClosed, spec builders). |
| 67 | + - name: Run upstream/core sandbox tests |
| 68 | + run: go test -v -race -run "Sandbox|sandbox|buildSandbox" ./internal/upstream/core/... |
| 69 | + |
| 70 | + # 3. scanner/engine: degradation under sandbox/none isolation mode |
| 71 | + # (TestEngineResolveScannersSkipsDockerUnderSandbox, TestEngineEffectiveIsolationMode). |
| 72 | + - name: Run scanner isolation-mode tests |
| 73 | + run: go test -v -race -run "Sandbox|sandbox|IsolationMode|isolation" ./internal/security/scanner/... |
| 74 | + |
| 75 | + # 4. Full sandbox + scanner test set with race detector. |
| 76 | + - name: Run all sandbox-related tests (race) |
| 77 | + run: | |
| 78 | + go test -race \ |
| 79 | + ./internal/sandbox/... \ |
| 80 | + ./internal/upstream/core/... \ |
| 81 | + ./internal/security/scanner/... |
| 82 | +
|
| 83 | + # 5. Build the binary (proves sandbox code compiles on linux/amd64). |
| 84 | + - name: Build mcpproxy binary |
| 85 | + run: go build -v -o mcpproxy ./cmd/mcpproxy |
| 86 | + |
| 87 | + # 6. Server startup probe: start mcpproxy with isolation.mode=sandbox, |
| 88 | + # verify it starts healthy, check the upstream list (no stdio servers |
| 89 | + # configured so no wrapWithSandbox is called — this proves the binary |
| 90 | + # starts cleanly under this config, not sandbox enforcement itself). |
| 91 | + - name: Start mcpproxy with isolation.mode=sandbox (startup probe) |
| 92 | + run: | |
| 93 | + mkdir -p /tmp/mcp3236-ci |
| 94 | + cat > /tmp/mcp3236-ci/mcp_config.json <<'EOF' |
| 95 | + { |
| 96 | + "listen": "127.0.0.1:19237", |
| 97 | + "api_key": "qa-sandbox-ci-test", |
| 98 | + "enable_web_ui": false, |
| 99 | + "docker_isolation": { "mode": "sandbox" }, |
| 100 | + "mcpServers": [] |
| 101 | + } |
| 102 | + EOF |
| 103 | + MCPPROXY_DATA_DIR=/tmp/mcp3236-ci ./mcpproxy serve \ |
| 104 | + --config /tmp/mcp3236-ci/mcp_config.json \ |
| 105 | + --log-level=debug \ |
| 106 | + > /tmp/mcp3236-ci/server.log 2>&1 & |
| 107 | + SERVER_PID=$! |
| 108 | + echo "SERVER_PID=$SERVER_PID" >> "$GITHUB_ENV" |
| 109 | + # Wait for server to be ready |
| 110 | + for i in $(seq 1 20); do |
| 111 | + if curl -sf -H "X-API-Key: qa-sandbox-ci-test" \ |
| 112 | + http://127.0.0.1:19237/api/v1/status > /dev/null 2>&1; then |
| 113 | + echo "Server ready after ${i}s" |
| 114 | + break |
| 115 | + fi |
| 116 | + sleep 1 |
| 117 | + done |
| 118 | +
|
| 119 | + - name: Verify server health under sandbox config |
| 120 | + run: | |
| 121 | + # Use the dedicated readiness endpoint (/readyz returns 200 once the |
| 122 | + # server has completed startup) — structure-independent, unlike parsing |
| 123 | + # the /api/v1/status JSON. The server serves HTTP before it's ready, so |
| 124 | + # poll up to 30s. |
| 125 | + READY=0 |
| 126 | + for i in $(seq 1 30); do |
| 127 | + if curl -sf http://127.0.0.1:19237/readyz > /dev/null 2>&1; then |
| 128 | + READY=1; echo "Server ready (/readyz 200) after ${i}s"; break |
| 129 | + fi |
| 130 | + sleep 1 |
| 131 | + done |
| 132 | + echo "--- /readyz body ---"; curl -s http://127.0.0.1:19237/readyz || true; echo |
| 133 | + echo "--- /api/v1/status ---" |
| 134 | + curl -sf -H "X-API-Key: qa-sandbox-ci-test" http://127.0.0.1:19237/api/v1/status | python3 -m json.tool || true |
| 135 | + if [ "$READY" != "1" ]; then |
| 136 | + echo "ERROR: /readyz did not return 200 within 30s" |
| 137 | + cat /tmp/mcp3236-ci/server.log |
| 138 | + exit 1 |
| 139 | + fi |
| 140 | + # Prove the server actually resolved SANDBOX mode (the global key is |
| 141 | + # docker_isolation.mode — a wrong key silently falls back to "none", |
| 142 | + # which would make this probe vacuous). |
| 143 | + if ! grep -i "isolation_mode" /tmp/mcp3236-ci/server.log | grep -qi "sandbox"; then |
| 144 | + echo "ERROR: server did not start in sandbox mode (expected isolation_mode=sandbox)" |
| 145 | + grep -i "isolation_mode" /tmp/mcp3236-ci/server.log || echo "(no isolation_mode log line found)" |
| 146 | + exit 1 |
| 147 | + fi |
| 148 | + echo "Server healthy (/readyz) and confirmed isolation_mode=sandbox" |
| 149 | +
|
| 150 | + - name: macOS/non-Linux graceful-degrade probe (build check) |
| 151 | + run: | |
| 152 | + # Cross-compile for darwin to prove the no-op path compiles cleanly. |
| 153 | + GOOS=darwin GOARCH=arm64 go build -o /dev/null ./internal/sandbox/... 2>&1 || true |
| 154 | + GOOS=darwin GOARCH=arm64 go build -o /dev/null ./internal/upstream/core/ 2>&1 || true |
| 155 | + echo "Cross-compile probe done (darwin build tags: sandbox_other.go path)" |
| 156 | +
|
| 157 | + - name: Stop server |
| 158 | + if: always() |
| 159 | + run: | |
| 160 | + if [ -n "$SERVER_PID" ]; then kill "$SERVER_PID" 2>/dev/null || true; fi |
| 161 | + cat /tmp/mcp3236-ci/server.log 2>/dev/null || true |
| 162 | +
|
| 163 | + - name: Upload server log |
| 164 | + if: always() |
| 165 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 166 | + with: |
| 167 | + name: sandbox-server-log |
| 168 | + path: /tmp/mcp3236-ci/server.log |
| 169 | + retention-days: 7 |
0 commit comments