Files
codex-security/docker/codex-security-seccomp.json
T
23c37b9c98 feat(container): restrict sockets and process tracing in Compose (#160)
* Harden sandbox seccomp: drop ptrace and tighten socket domain allowlist

Two fixes from a security audit of this repo:

- Remove process_vm_readv/process_vm_writev/ptrace from the allowlist.
  All sandboxed processes share the same uid, so ptrace let one process
  inspect/modify another's memory (e.g. read a secret held by a sibling
  process) inside the sandbox -- inter-process isolation was effectively
  void despite the seccomp profile's intent.

- Replace the 3 socket-domain rules with an explicit allowlist of
  AF_UNIX(1)/AF_INET(2)/AF_INET6(10). The previous rules (domain<38,
  domain==39, domain>40) only actually blocked AF_ALG(38) and
  AF_VSOCK(40) -- AF_NETLINK(16) and AF_PACKET(17) were allowed, along
  with everything else outside that narrow gap, making the egress
  control close to a no-op.

Verified with a real Docker build + run on a separate host, under the
exact production security contract (--cap-drop ALL --security-opt
no-new-privileges + this seccomp profile):
- DNS resolution (getaddrinfo) and `git clone` over HTTPS still work
  (AF_INET/AF_INET6 unaffected) -- confirms this doesn't break the
  scanner's own legitimate network use.
- AF_NETLINK and AF_PACKET socket() calls now fail with EPERM inside
  the container (previously succeeded) -- confirms the fix is real, not
  cosmetic.

Local commit only -- this is an audit clone of openai/codex-security,
not a fork with push access.

* Fail closed if not launched with --cap-drop ALL --security-opt no-new-privileges

docker/codex-security-seccomp.json unconditionally allows mount/pivot_root/
unshare/setns/clone for Codex's own unprivileged Bubblewrap sandboxing --
those syscalls can't be removed without breaking that feature entirely.
Their safety previously depended entirely on a comment in the seccomp
profile asserting the caller runs with --cap-drop ALL and
--security-opt no-new-privileges (true for compose.yaml, not enforced for
a bare `docker run`).

Adds a runtime self-check at the top of the entrypoint: read
/proc/self/status, refuse to start (exit 3, clear message) unless CapEff
is all-zero and NoNewPrivs is 1. Converts an undocumented-until-you-read-
the-seccomp-comment assumption into a loud, immediate failure.

Verified with a real Docker build + run on a separate host, 4 launch
scenarios:
- --cap-drop ALL --security-opt no-new-privileges (contract met): starts
  normally.
- No flags, default non-root user (10001 from the Dockerfile): blocked by
  the NoNewPrivs check.
- --security-opt no-new-privileges only, no --cap-drop: starts -- correct,
  not a false block, since a non-root process already has an empty
  effective capability set regardless of --cap-drop.
- --user root, no flags: blocked by the CapEff check, message shows the
  actual non-empty capability bitmask (00000000a80425fb).

Local commit only -- this is an audit clone of openai/codex-security, not
a fork with push access.

* Address Codex review: CI hardening flags, AF_NETLINK for bwrap, drop socketcall

Three fixes for the automated review findings on this PR:

1. .github/workflows/container-ci.yml: the bare `docker run` smoke-test
   invocations (Verify bundled scanner, Reject interactive repository
   discovery) never passed --cap-drop ALL --security-opt no-new-privileges,
   so entrypoint.sh's new fail-closed check aborted them with exit 3 before
   --version/help/discovery validation could run. Added the flags to match
   the production contract these tests are supposed to exercise.

2. docker/codex-security-seccomp.json: the AF_UNIX/AF_INET/AF_INET6-only
   socket() allowlist rejected AF_NETLINK, which Bubblewrap needs (a
   NETLINK_ROUTE socket) to run RTM_NEWLINK/RTM_NEWADDR when configuring
   the loopback interface inside its own isolated network namespace during
   codex sandbox startup. The CI workflow already silently tolerated this
   by retrying with --enable use_legacy_landlock; added an explicit
   AF_NETLINK(16) rule restricted to protocol NETLINK_ROUTE(0) so the
   normal Bubblewrap path succeeds without needing that fallback.

3. docker/codex-security-seccomp.json: "socketcall" was unconditionally
   allowed in the generic syscall list with no argument filtering. On the
   supported SCMP_ARCH_X86 subarchitecture, this legacy multiplexer lets a
   32-bit executable open sockets (including AF_NETLINK/AF_PACKET) via
   socketcall's own SYS_SOCKET dispatch, bypassing the domain-restricted
   socket() rules entirely -- seccomp can't filter socketcall by socket
   domain since that lives behind a pointer argument, not a plain integer,
   so the safe fix is to stop allowing it unconditionally. socketpair (only
   ever AF_UNIX by kernel definition) stays allowed.

Verified with a real Docker build + container runs on a separate host
(not the CI runner, not the openai org):
- Bare `docker run` (no flags): still fails closed with exit 3, unchanged.
- With the added flags: --version, bulk-scan --help, info --json all
  exit 0; the discovery-rejection test still returns exit 2 with the
  expected message.
- A/B on the sandbox seccomp: the pre-fix profile reproduces the exact
  error from the review ("bwrap: loopback: Failed to create NETLINK_ROUTE
  socket: Operation not permitted"); the fixed profile runs the same
  `codex sandbox /usr/bin/true` command to completion (exit 0) without
  the use_legacy_landlock fallback.
- Normal HTTPS egress (AF_INET, via Node's https module) still works
  under the fixed profile, confirming the socketcall removal doesn't
  regress git-clone/API access on x86_64.

---------

Co-authored-by: mldangelo-oai <mdangelo@openai.com>
Co-authored-by: mldangelo-oai <269034524+mldangelo-oai@users.noreply.github.com>
2026-11-04 12:06:09 -08:00

472 lines
10 KiB
JSON

{
"defaultAction": "SCMP_ACT_ERRNO",
"defaultErrnoRet": 1,
"archMap": [
{
"architecture": "SCMP_ARCH_X86_64",
"subArchitectures": ["SCMP_ARCH_X86", "SCMP_ARCH_X32"]
},
{
"architecture": "SCMP_ARCH_AARCH64",
"subArchitectures": ["SCMP_ARCH_ARM"]
}
],
"syscalls": [
{
"names": [
"accept",
"accept4",
"access",
"adjtimex",
"alarm",
"bind",
"brk",
"cachestat",
"capget",
"capset",
"chdir",
"chmod",
"chown",
"chown32",
"clock_adjtime",
"clock_adjtime64",
"clock_getres",
"clock_getres_time64",
"clock_gettime",
"clock_gettime64",
"clock_nanosleep",
"clock_nanosleep_time64",
"close",
"close_range",
"connect",
"copy_file_range",
"creat",
"dup",
"dup2",
"dup3",
"epoll_create",
"epoll_create1",
"epoll_ctl",
"epoll_ctl_old",
"epoll_pwait",
"epoll_pwait2",
"epoll_wait",
"epoll_wait_old",
"eventfd",
"eventfd2",
"execve",
"execveat",
"exit",
"exit_group",
"faccessat",
"faccessat2",
"fadvise64",
"fadvise64_64",
"fallocate",
"fanotify_mark",
"fchdir",
"fchmod",
"fchmodat",
"fchmodat2",
"fchown",
"fchown32",
"fchownat",
"fcntl",
"fcntl64",
"fdatasync",
"fgetxattr",
"flistxattr",
"flock",
"fork",
"fremovexattr",
"fsetxattr",
"fstat",
"fstat64",
"fstatat64",
"fstatfs",
"fstatfs64",
"fsync",
"ftruncate",
"ftruncate64",
"futex",
"futex_requeue",
"futex_time64",
"futex_wait",
"futex_waitv",
"futex_wake",
"futimesat",
"getcpu",
"getcwd",
"getdents",
"getdents64",
"getegid",
"getegid32",
"geteuid",
"geteuid32",
"getgid",
"getgid32",
"getgroups",
"getgroups32",
"getitimer",
"getpeername",
"getpgid",
"getpgrp",
"getpid",
"getppid",
"getpriority",
"getrandom",
"getresgid",
"getresgid32",
"getresuid",
"getresuid32",
"getrlimit",
"get_robust_list",
"getrusage",
"getsid",
"getsockname",
"getsockopt",
"get_thread_area",
"gettid",
"gettimeofday",
"getuid",
"getuid32",
"getxattr",
"getxattrat",
"inotify_add_watch",
"inotify_init",
"inotify_init1",
"inotify_rm_watch",
"io_cancel",
"ioctl",
"io_destroy",
"io_getevents",
"io_pgetevents",
"io_pgetevents_time64",
"ioprio_get",
"ioprio_set",
"io_setup",
"io_submit",
"ipc",
"kill",
"landlock_add_rule",
"landlock_create_ruleset",
"landlock_restrict_self",
"lchown",
"lchown32",
"lgetxattr",
"link",
"linkat",
"listen",
"listmount",
"listxattr",
"listxattrat",
"llistxattr",
"_llseek",
"lremovexattr",
"lseek",
"lsetxattr",
"lstat",
"lstat64",
"madvise",
"map_shadow_stack",
"membarrier",
"memfd_create",
"memfd_secret",
"mincore",
"mkdir",
"mkdirat",
"mknod",
"mknodat",
"mlock",
"mlock2",
"mlockall",
"mmap",
"mmap2",
"mprotect",
"mq_getsetattr",
"mq_notify",
"mq_open",
"mq_timedreceive",
"mq_timedreceive_time64",
"mq_timedsend",
"mq_timedsend_time64",
"mq_unlink",
"mremap",
"mseal",
"msgctl",
"msgget",
"msgrcv",
"msgsnd",
"msync",
"munlock",
"munlockall",
"munmap",
"name_to_handle_at",
"nanosleep",
"newfstatat",
"_newselect",
"open",
"openat",
"openat2",
"pause",
"pidfd_open",
"pidfd_send_signal",
"pipe",
"pipe2",
"pkey_alloc",
"pkey_free",
"pkey_mprotect",
"poll",
"ppoll",
"ppoll_time64",
"prctl",
"pread64",
"preadv",
"preadv2",
"prlimit64",
"process_mrelease",
"pselect6",
"pselect6_time64",
"pwrite64",
"pwritev",
"pwritev2",
"read",
"readahead",
"readlink",
"readlinkat",
"readv",
"recv",
"recvfrom",
"recvmmsg",
"recvmmsg_time64",
"recvmsg",
"remap_file_pages",
"removexattr",
"removexattrat",
"rename",
"renameat",
"renameat2",
"restart_syscall",
"rmdir",
"rseq",
"rt_sigaction",
"rt_sigpending",
"rt_sigprocmask",
"rt_sigqueueinfo",
"rt_sigreturn",
"rt_sigsuspend",
"rt_sigtimedwait",
"rt_sigtimedwait_time64",
"rt_tgsigqueueinfo",
"sched_getaffinity",
"sched_getattr",
"sched_getparam",
"sched_get_priority_max",
"sched_get_priority_min",
"sched_getscheduler",
"sched_rr_get_interval",
"sched_rr_get_interval_time64",
"sched_setaffinity",
"sched_setattr",
"sched_setparam",
"sched_setscheduler",
"sched_yield",
"seccomp",
"select",
"semctl",
"semget",
"semop",
"semtimedop",
"semtimedop_time64",
"send",
"sendfile",
"sendfile64",
"sendmmsg",
"sendmsg",
"sendto",
"setfsgid",
"setfsgid32",
"setfsuid",
"setfsuid32",
"setgid",
"setgid32",
"setgroups",
"setgroups32",
"setitimer",
"setpgid",
"setpriority",
"setregid",
"setregid32",
"setresgid",
"setresgid32",
"setresuid",
"setresuid32",
"setreuid",
"setreuid32",
"setrlimit",
"set_robust_list",
"setsid",
"setsockopt",
"set_thread_area",
"set_tid_address",
"setuid",
"setuid32",
"setxattr",
"setxattrat",
"shmat",
"shmctl",
"shmdt",
"shmget",
"shutdown",
"sigaltstack",
"signalfd",
"signalfd4",
"sigprocmask",
"sigreturn",
"socketcall",
"splice",
"stat",
"stat64",
"statfs",
"statfs64",
"statmount",
"statx",
"symlink",
"symlinkat",
"sync",
"sync_file_range",
"syncfs",
"sysinfo",
"tee",
"tgkill",
"time",
"timer_create",
"timer_delete",
"timer_getoverrun",
"timer_gettime",
"timer_gettime64",
"timer_settime",
"timer_settime64",
"timerfd_create",
"timerfd_gettime",
"timerfd_gettime64",
"timerfd_settime",
"timerfd_settime64",
"times",
"tkill",
"truncate",
"truncate64",
"ugetrlimit",
"umask",
"uname",
"unlink",
"unlinkat",
"uretprobe",
"utime",
"utimensat",
"utimensat_time64",
"utimes",
"vfork",
"vmsplice",
"wait4",
"waitid",
"waitpid",
"write",
"writev"
],
"action": "SCMP_ACT_ALLOW"
},
{
"names": ["socket", "socketpair"],
"action": "SCMP_ACT_ALLOW",
"args": [{ "index": 0, "value": 1, "op": "SCMP_CMP_EQ" }]
},
{
"names": ["socket"],
"action": "SCMP_ACT_ALLOW",
"comment": "IPv4 SOCK_PACKET (10) opens a packet socket. Other assigned socket types and the CLOEXEC and NONBLOCK flags leave bit 0x8 clear.",
"args": [
{ "index": 0, "value": 2, "op": "SCMP_CMP_EQ" },
{ "index": 1, "value": 8, "valueTwo": 0, "op": "SCMP_CMP_MASKED_EQ" }
]
},
{
"names": ["socket"],
"action": "SCMP_ACT_ALLOW",
"args": [{ "index": 0, "value": 10, "op": "SCMP_CMP_EQ" }]
},
{
"names": ["socket"],
"action": "SCMP_ACT_ALLOW",
"comment": "Bubblewrap uses NETLINK_ROUTE to configure loopback in a new network namespace.",
"args": [
{ "index": 0, "value": 16, "op": "SCMP_CMP_EQ" },
{ "index": 2, "value": 0, "op": "SCMP_CMP_EQ" }
]
},
{
"names": ["personality"],
"action": "SCMP_ACT_ALLOW",
"args": [{ "index": 0, "value": 0, "op": "SCMP_CMP_EQ" }]
},
{
"names": ["personality"],
"action": "SCMP_ACT_ALLOW",
"args": [{ "index": 0, "value": 8, "op": "SCMP_CMP_EQ" }]
},
{
"names": ["personality"],
"action": "SCMP_ACT_ALLOW",
"args": [{ "index": 0, "value": 131072, "op": "SCMP_CMP_EQ" }]
},
{
"names": ["personality"],
"action": "SCMP_ACT_ALLOW",
"args": [{ "index": 0, "value": 131080, "op": "SCMP_CMP_EQ" }]
},
{
"names": ["personality"],
"action": "SCMP_ACT_ALLOW",
"args": [{ "index": 0, "value": 4294967295, "op": "SCMP_CMP_EQ" }]
},
{
"names": [
"arm_fadvise64_64",
"arm_sync_file_range",
"breakpoint",
"cacheflush",
"set_tls"
],
"action": "SCMP_ACT_ALLOW",
"includes": { "arches": ["arm", "arm64"] }
},
{
"names": ["arch_prctl"],
"action": "SCMP_ACT_ALLOW",
"includes": { "arches": ["amd64", "x32"] }
},
{
"names": ["modify_ldt"],
"action": "SCMP_ACT_ALLOW",
"includes": { "arches": ["amd64", "x32", "x86"] }
},
{
"names": [
"clone",
"clone3",
"mount",
"mount_setattr",
"move_mount",
"open_tree",
"pivot_root",
"setns",
"umount",
"umount2",
"unshare"
],
"action": "SCMP_ACT_ALLOW",
"comment": "Allow Codex's unprivileged Bubblewrap user and mount namespaces; run with --cap-drop ALL and no-new-privileges."
}
]
}