Skip to content

Commit 5edcda9

Browse files
committed
Improve seccomp API
Signed-off-by: Michael Crosby <[email protected]> Conflicts: configs/config.go container_linux.go seccomp/seccomp.go seccomp/seccomp.test
1 parent 4a99434 commit 5edcda9

24 files changed

+853
-1780
lines changed

Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ direct-test-short:
1818
go test $(TEST_TAGS) -cover -test.short -v $(GO_PACKAGES)
1919

2020
direct-build:
21-
chmod 755 hack/seccomp.sh
22-
hack/seccomp.sh
2321
go build -v $(GO_PACKAGES)
2422

2523
direct-install:

configs/config.go

+36-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,38 @@ type IDMap struct {
1313
Size int `json:"size"`
1414
}
1515

16-
type SeccompConf struct {
17-
SysCalls []int `json:"syscalls"`
16+
type Seccomp struct {
17+
Syscalls []*Syscall `json:"syscalls"`
18+
}
19+
20+
type Action int
21+
22+
const (
23+
Kill Action = iota - 3
24+
Trap
25+
Allow
26+
)
27+
28+
type Operator int
29+
30+
const (
31+
EqualTo Operator = iota
32+
NotEqualTo
33+
GreatherThan
34+
LessThan
35+
MaskEqualTo
36+
)
37+
38+
type Arg struct {
39+
Index int `json:"index"`
40+
Value uint32 `json:"value"`
41+
Op Operator `json:"op"`
42+
}
43+
44+
type Syscall struct {
45+
Value int `json:"value"`
46+
Action Action `json:"action"`
47+
Args []*Arg `json:"args"`
1848
}
1949

2050
// TODO Windows. Many of these fields should be factored out into those parts
@@ -109,6 +139,8 @@ type Config struct {
109139
// sysctl -w my.property.name value in Linux.
110140
SystemProperties map[string]string `json:"system_properties"`
111141

112-
// SysCalls specify the system calls to keep when executing the process inside the container
113-
Seccomps SeccompConf `json:"seccomp"`
142+
// Seccomp allows actions to be taken whenever a syscall is made within the container.
143+
// By default, all syscalls are allowed with actions to allow, trap, kill, or return an errno
144+
// can be specified on a per syscall basis.
145+
Seccomp *Seccomp `json:"seccomp"`
114146
}

configs/namespaces_syscall.go

+6-11
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@ package configs
44

55
import "syscall"
66

7-
var (
8-
CLONE_SECCOMP = 0x10000 //diffrent from other flag, hard code
9-
)
10-
117
func (n *Namespace) Syscall() int {
128
return namespaceInfo[n.Type]
139
}
1410

1511
var namespaceInfo = map[NamespaceType]int{
16-
NEWNET: syscall.CLONE_NEWNET,
17-
NEWNS: syscall.CLONE_NEWNS,
18-
NEWUSER: syscall.CLONE_NEWUSER,
19-
NEWIPC: syscall.CLONE_NEWIPC,
20-
NEWUTS: syscall.CLONE_NEWUTS,
21-
NEWPID: syscall.CLONE_NEWPID,
22-
NEWSECCOMP: CLONE_SECCOMP,
12+
NEWNET: syscall.CLONE_NEWNET,
13+
NEWNS: syscall.CLONE_NEWNS,
14+
NEWUSER: syscall.CLONE_NEWUSER,
15+
NEWIPC: syscall.CLONE_NEWIPC,
16+
NEWUTS: syscall.CLONE_NEWUTS,
17+
NEWPID: syscall.CLONE_NEWPID,
2318
}
2419

2520
// CloneFlags parses the container's Namespaces options to set the correct

configs/namespaces_unix.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ package configs
55
import "fmt"
66

77
const (
8-
NEWNET NamespaceType = "NEWNET"
9-
NEWPID NamespaceType = "NEWPID"
10-
NEWNS NamespaceType = "NEWNS"
11-
NEWUTS NamespaceType = "NEWUTS"
12-
NEWIPC NamespaceType = "NEWIPC"
13-
NEWUSER NamespaceType = "NEWUSER"
14-
NEWSECCOMP NamespaceType = "NEWSECCOMP"
8+
NEWNET NamespaceType = "NEWNET"
9+
NEWPID NamespaceType = "NEWPID"
10+
NEWNS NamespaceType = "NEWNS"
11+
NEWUTS NamespaceType = "NEWUTS"
12+
NEWIPC NamespaceType = "NEWIPC"
13+
NEWUSER NamespaceType = "NEWUSER"
1514
)
1615

1716
func NamespaceTypes() []NamespaceType {

container_linux.go

-7
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,6 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
169169
cmd.SysProcAttr.Credential = &syscall.Credential{}
170170
}
171171
}
172-
if cloneFlags&uintptr(configs.CLONE_SECCOMP) != 0 {
173-
//os don't surport for CLONE_SECCOMP, remote it
174-
c.config.Namespaces.Remove(configs.NEWSECCOMP)
175-
cloneFlags = c.config.Namespaces.CloneFlags()
176-
} else {
177-
c.config.Seccomps.SysCalls = []int{}
178-
}
179172
cmd.Env = append(cmd.Env, t)
180173
cmd.SysProcAttr.Cloneflags = cloneFlags
181174
return &initProcess{

hack/seccomp.pl

-58
This file was deleted.

hack/seccomp.sh

-4
This file was deleted.

0 commit comments

Comments
 (0)