fix(sandbox): harden sandbox containers against privilege escalation#355
Open
manusjs wants to merge 1 commit into
Open
fix(sandbox): harden sandbox containers against privilege escalation#355manusjs wants to merge 1 commit into
manusjs wants to merge 1 commit into
Conversation
a7138f7 to
a924213
Compare
a924213 to
3c034c9
Compare
Address the container escape risk reported in issue vxcontrol#337 (Docker socket bind-mount when DOCKER_INSIDE=true). Changes: backend/pkg/docker/client.go — RunContainer hardening • Add `no-new-privileges:true` to SecurityOpt on every sandbox container. Prevents setuid/setgid and file-capability escalation inside the sandbox. • Add PidsLimit=2048 as a cheap fork-bomb / resource exhaustion guard. • Add startup warning (logrus.Warn) when DOCKER_INSIDE=true so operators see the socket-escape risk at boot rather than only in documentation. • Correct the comment to not imply the socket-escape vector is mitigated by no-new-privileges alone (it is not; the real fix is DOCKER_INSIDE=false or a least-privilege socket proxy). backend/pkg/tools/tools.go — CapDrop ALL on primary terminal container • Drop all Linux capabilities then add back only NET_RAW (always) and NET_ADMIN (when DOCKER_NET_ADMIN=true). Removes ~14 unnecessary caps from the default Docker set (e.g. SYS_CHROOT, AUDIT_WRITE, MKNOD) that pentest tools should not need and that could be abused in an escape chain. .env.example • Flip DOCKER_INSIDE default to false (aligned with config.go envDefault). The previous example was contradicting the code default. • Expand the DOCKER_INSIDE comment: explains socket-escape risk, DinD guidance, and links to docker-socket-proxy as a least-privilege alternative. Note: DOCKER_INSIDE=false is the safest configuration; operators who need DinD should consider fronting /var/run/docker.sock with a proxy rather than mounting it directly.
3c034c9 to
a50ba4c
Compare
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.
Summary
Four targeted container hardening changes for issue #337.
Important clarification (flagged by code review):
no-new-privilegesalone does not close the Docker socket escape vector — an attacker with socket access can ask the host daemon to launch a privileged container regardless of this flag. The changes here are genuine defense-in-depth, but the definitive fix for #337 remainsDOCKER_INSIDE=falseor fronting the socket with a least-privilege proxy. Issue #337 should stay open until that is addressed.Changes
backend/pkg/docker/client.go— RunContainer hardeningno-new-privileges:true: prevents setuid/setgid and file-capability escalation inside the containerPidsLimit=2048: fork-bomb / resource exhaustion guardbackend/pkg/tools/tools.go— CapDrop ALLDrop all Linux capabilities, add back only NET_RAW + optionally NET_ADMIN. Removes ~14 unnecessary caps (SYS_CHROOT, AUDIT_WRITE, MKNOD, etc.) from the default Docker set.
.env.exampleWhat is NOT addressed (why #337 stays open)
The root cause — a process in the sandbox can POST to the Docker socket to launch a privileged container with the host filesystem mounted — is not addressed by these changes. Definitive mitigations are: DOCKER_INSIDE=false, a socket proxy, or rootless/sysbox DinD. This PR does the hardening safe to ship immediately while that architectural question is resolved.
Testing
go build ./pkg/docker/... ./pkg/tools/...— cleango test ./pkg/docker/... ./pkg/tools/...— all pass