Skip to content

security: add no-new-privs and seccomp BPF syscall filter#7

Closed
HackStrix wants to merge 1 commit intomainfrom
feature/process-security-seccomp
Closed

security: add no-new-privs and seccomp BPF syscall filter#7
HackStrix wants to merge 1 commit intomainfrom
feature/process-security-seccomp

Conversation

@HackStrix
Copy link
Owner

No-New-Privs

Set PR_SET_NO_NEW_PRIVS on the spawning OS thread via unix.Prctl before forking each worker. Workers inherit the bit and cannot gain privileges through setuid/setgid binaries (sudo, su, etc.). Enabled by default when sandbox is enabled.

sandboxConfig gains a noNewPrivs bool field. ProcessFactory passes noNewPrivs: true in the default sandboxConfig.

Seccomp BPF filter

Add a syscall allowlist filter using github.com/elastic/go-seccomp-bpf (pure Go, no libseccomp dependency). Key properties:

  • SECCOMP_FILTER_FLAG_TSYNC syncs the filter to all Go runtime threads
  • Default policy: SeccompPolicyErrno (blocked calls return EPERM)
  • Explicitly blocks: ptrace, mount, bpf, kexec_load, keyctl, io_uring_, userfaultfd, perf_event_open, setns, process_vm_

Design: ProcessFactory injects HERD_SECCOMP_PROFILE env var into the worker. Go worker binaries call herd.EnterSandbox() at the top of main() to install the filter. Opaque binaries (ollama, playwright) use WithSeccompPolicy(SeccompPolicyOff) to skip seccomp while still benefiting from cgroup + namespace isolation.

New API:

  • EnterSandbox() error — called by worker binaries at startup
  • ProcessFactory.WithSeccompPolicy(SeccompPolicy) *ProcessFactory
  • SeccompPolicy: Off | Log | Errno | Kill

New files:

  • seccomp_linux.go: EnterSandbox, httpWorkerSyscalls allowlist
  • seccomp_unsupported.go: cross-platform no-op stubs
  • seccomp_linux_test.go: unit tests for BPF construction and policy

Updated examples to use WithSeccompPolicy(SeccompPolicyOff) for opaque binaries (ollama, playwright) with explanatory comments.

## No-New-Privs

Set PR_SET_NO_NEW_PRIVS on the spawning OS thread via unix.Prctl before
forking each worker. Workers inherit the bit and cannot gain privileges
through setuid/setgid binaries (sudo, su, etc.). Enabled by default
when sandbox is enabled.

sandboxConfig gains a noNewPrivs bool field. ProcessFactory passes
noNewPrivs: true in the default sandboxConfig.

## Seccomp BPF filter

Add a syscall allowlist filter using github.com/elastic/go-seccomp-bpf
(pure Go, no libseccomp dependency). Key properties:
- SECCOMP_FILTER_FLAG_TSYNC syncs the filter to all Go runtime threads
- Default policy: SeccompPolicyErrno (blocked calls return EPERM)
- Explicitly blocks: ptrace, mount, bpf, kexec_load, keyctl,
  io_uring_*, userfaultfd, perf_event_open, setns, process_vm_*

Design: ProcessFactory injects HERD_SECCOMP_PROFILE env var into
the worker. Go worker binaries call herd.EnterSandbox() at the top
of main() to install the filter. Opaque binaries (ollama, playwright)
use WithSeccompPolicy(SeccompPolicyOff) to skip seccomp while
still benefiting from cgroup + namespace isolation.

New API:
- EnterSandbox() error — called by worker binaries at startup
- ProcessFactory.WithSeccompPolicy(SeccompPolicy) *ProcessFactory
- SeccompPolicy: Off | Log | Errno | Kill

New files:
- seccomp_linux.go: EnterSandbox, httpWorkerSyscalls allowlist
- seccomp_unsupported.go: cross-platform no-op stubs
- seccomp_linux_test.go: unit tests for BPF construction and policy

Updated examples to use WithSeccompPolicy(SeccompPolicyOff) for
opaque binaries (ollama, playwright) with explanatory comments.
@HackStrix
Copy link
Owner Author

@HackStrix HackStrix closed this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant