-
Notifications
You must be signed in to change notification settings - Fork 543
Harden sandbox: drop ptrace, tighten socket egress, enforce cap-drop/no-new-privileges #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a44dc25
d88aec5
f09a34e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,7 +323,6 @@ | |
| "signalfd4", | ||
| "sigprocmask", | ||
| "sigreturn", | ||
| "socketcall", | ||
| "socketpair", | ||
| "splice", | ||
| "stat", | ||
|
|
@@ -378,24 +377,29 @@ | |
| "action": "SCMP_ACT_ALLOW" | ||
| }, | ||
| { | ||
| "names": ["process_vm_readv", "process_vm_writev", "ptrace"], | ||
| "names": ["socket"], | ||
| "action": "SCMP_ACT_ALLOW", | ||
| "includes": { "minKernel": "4.8" } | ||
| "comment": "AF_UNIX(1)/AF_INET(2)/AF_INET6(10) only: local IPC + HTTPS for git clone and the OpenAI API. Everything else (notably AF_NETLINK=16, AF_PACKET=17) is denied by defaultAction; the previous 3-rule form here only blocked AF_ALG=38/AF_VSOCK=40 and left NETLINK/PACKET/everything-else allowed.", | ||
| "args": [{ "index": 0, "value": 1, "op": "SCMP_CMP_EQ" }] | ||
|
Comment on lines
+382
to
+383
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On the explicitly supported Useful? React with 👍 / 👎. |
||
| }, | ||
| { | ||
| "names": ["socket"], | ||
| "action": "SCMP_ACT_ALLOW", | ||
| "args": [{ "index": 0, "value": 38, "op": "SCMP_CMP_LT" }] | ||
| "args": [{ "index": 0, "value": 2, "op": "SCMP_CMP_EQ" }] | ||
| }, | ||
| { | ||
| "names": ["socket"], | ||
| "action": "SCMP_ACT_ALLOW", | ||
| "args": [{ "index": 0, "value": 39, "op": "SCMP_CMP_EQ" }] | ||
| "args": [{ "index": 0, "value": 10, "op": "SCMP_CMP_EQ" }] | ||
| }, | ||
| { | ||
| "names": ["socket"], | ||
| "action": "SCMP_ACT_ALLOW", | ||
| "args": [{ "index": 0, "value": 40, "op": "SCMP_CMP_GT" }] | ||
| "comment": "AF_NETLINK(16) restricted to NETLINK_ROUTE(0): Bubblewrap's Linux sandbox needs a NETLINK_ROUTE socket to run RTM_NEWLINK/RTM_NEWADDR when it configures the loopback interface inside its own (already-isolated) network namespace during codex sandbox startup.", | ||
| "args": [ | ||
| { "index": 0, "value": 16, "op": "SCMP_CMP_EQ" }, | ||
| { "index": 2, "value": 0, "op": "SCMP_CMP_EQ" } | ||
| ] | ||
| }, | ||
| { | ||
| "names": ["personality"], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,24 @@ | |
|
|
||
| set -eu | ||
|
|
||
| # Fail closed instead of silently degrading: docker/codex-security-seccomp.json | ||
| # allows mount/pivot_root/unshare/setns/clone unconditionally, on the assumption | ||
| # (previously only a comment) that the caller runs this image with | ||
| # --cap-drop ALL --security-opt no-new-privileges (as compose.yaml does). If | ||
| # someone runs the raw image without that contract, refuse to start rather than | ||
| # let the seccomp profile's namespace/mount allowlist apply with capabilities | ||
| # or new-privilege escalation still available. | ||
| caps=$(awk '/^CapEff:/{print $2}' /proc/self/status 2>/dev/null || true) | ||
| if [ "$caps" != "0000000000000000" ]; then | ||
| printf '%s\n' "codex-security: refusing to start without --cap-drop ALL (effective capabilities are not empty: ${caps:-unknown})." >&2 | ||
| exit 3 | ||
| fi | ||
| nnp=$(awk '/^NoNewPrivs:/{print $2}' /proc/self/status 2>/dev/null || true) | ||
| if [ "$nnp" != "1" ]; then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the image is invoked by the bare Useful? React with 👍 / 👎. |
||
| printf '%s\n' "codex-security: refusing to start without --security-opt no-new-privileges." >&2 | ||
| exit 3 | ||
| fi | ||
|
|
||
| if [ "${1:-}" = bulk-scan ]; then | ||
| case "${2:-}" in | ||
| --help|-h) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Codex starts its Linux Bubblewrap sandbox with network isolation, Bubblewrap needs an
AF_NETLINKsocket to configure the loopback interface, but this allowlist now rejects that socket beforeRTM_NEWLINK/RTM_NEWADDRcan run. The hardened-sandbox workflow in.github/workflows/container-ci.ymllines 122-126 explicitly recognizes this failure and survives only by manually rerunning withuse_legacy_landlock; the normal scan path contains no equivalent retry or feature override, so container scans that execute sandboxed commands can fail rather than run.Useful? React with 👍 / 👎.