security: add no-new-privs and seccomp BPF syscall filter#7
Closed
security: add no-new-privs and seccomp BPF syscall filter#7
Conversation
## 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.
Owner
Author
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.
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:
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:
New files:
Updated examples to use WithSeccompPolicy(SeccompPolicyOff) for opaque binaries (ollama, playwright) with explanatory comments.