-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to load a seccomp filter
- Loading branch information
Showing
11 changed files
with
252 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package env | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
|
||
"github.com/elastic/go-seccomp-bpf" | ||
"github.com/elastic/go-ucfg/yaml" | ||
"golang.org/x/net/bpf" | ||
) | ||
|
||
func readSeccompConf(name string) ([]syscall.SockFilter, error) { | ||
conf, err := yaml.NewConfigWithFile(name) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return nil, nil | ||
} | ||
return nil, err | ||
} | ||
|
||
var policy seccomp.Policy | ||
if err := conf.Unpack(&policy); err != nil { | ||
return nil, err | ||
} | ||
inst, err := policy.Assemble() | ||
if err != nil { | ||
return nil, err | ||
} | ||
rawInst, err := bpf.Assemble(inst) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return toSockFilter(rawInst), nil | ||
} | ||
|
||
func toSockFilter(raw []bpf.RawInstruction) []syscall.SockFilter { | ||
filter := make([]syscall.SockFilter, 0, len(raw)) | ||
for _, instruction := range raw { | ||
filter = append(filter, syscall.SockFilter{ | ||
Code: instruction.Op, | ||
Jt: instruction.Jt, | ||
Jf: instruction.Jf, | ||
K: instruction.K, | ||
}) | ||
} | ||
return filter | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# This is an example seccomp policy for x86_64 that whitelist regular syscalls and prevents network syscalls. | ||
# The example is not ready for production use now, should be tuned for specific usages | ||
|
||
# The default action is applied if none of the syscalls match. | ||
# | ||
# Possible actions: | ||
# - kill_process (since Linux 4.14) | ||
# - kill_thread | ||
# - trap | ||
# - errno (returns EPERM) | ||
# - trace | ||
# - log (since Linux 4.14) | ||
# - allow | ||
default_action: kill_process | ||
|
||
syscalls: | ||
- action: allow | ||
names: | ||
# file actions | ||
- read | ||
- write | ||
- readv | ||
- writev | ||
- close | ||
- fstat | ||
- lseek | ||
- dup | ||
- dup2 | ||
- dup3 | ||
- ioctl | ||
- fcntl | ||
- fadvise64 | ||
- pipe | ||
- pread64 | ||
- pwrite64 | ||
|
||
# memory action | ||
- mmap | ||
- mprotect | ||
- munmap | ||
- brk | ||
- mremap | ||
- msync | ||
- mincore | ||
- madvise | ||
|
||
# signal | ||
- rt_sigaction | ||
- rt_sigprocmask | ||
- rt_sigreturn | ||
- rt_sigpending | ||
- sigaltstack | ||
|
||
# work dir | ||
- getcwd | ||
|
||
# exit | ||
- exit | ||
- exit_group | ||
|
||
# others | ||
- arch_prctl | ||
- restart_syscall | ||
|
||
# time | ||
- gettimeofday | ||
- times | ||
- time | ||
- clock_gettime | ||
- clock_getres | ||
|
||
# rlimit | ||
- getrlimit | ||
- getrusage | ||
- setrlimit | ||
|
||
# execve | ||
- execve | ||
- execveat | ||
|
||
# open | ||
- open | ||
- openat | ||
|
||
# delete | ||
- unlink | ||
- unlinkat | ||
|
||
# link | ||
- readlink | ||
- readlinkat | ||
|
||
# permission check | ||
- lstat | ||
- stat | ||
- access | ||
- faccessat | ||
|
||
# process | ||
- clone | ||
- fork | ||
- vfork | ||
- nanosleep | ||
- wait4 | ||
|
||
- getpid | ||
- gettid | ||
|
||
# lock | ||
- futex | ||
|
||
# other | ||
- getdents | ||
- getdents64 | ||
- sysinfo | ||
- set_tid_address | ||
- set_robust_list | ||
- getrandom | ||
|
||
- umask | ||
- rename | ||
- chmod | ||
- mkdir | ||
- chdir | ||
- fchdir | ||
- ftruncate | ||
- sched_getaffinity | ||
- sched_yield | ||
- uname | ||
- prlimit64 | ||
- fchmodat | ||
- poll | ||
|
||
# user | ||
- getuid | ||
- geteuid | ||
- getgid | ||
- getegid | ||
|
||
- action: errno | ||
names: | ||
- connect | ||
- accept | ||
- sendto | ||
- recvfrom | ||
- sendmsg | ||
- recvmsg | ||
- bind | ||
- listen | ||
- setsockopt | ||
- socketpair | ||
- getsockopt | ||
|
||
|