Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Improve seccomp API
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crosby <[email protected]>

Conflicts:
	configs/config.go
	container_linux.go
	seccomp/seccomp.go
	seccomp/seccomp.test
  • Loading branch information
crosbymichael committed Jun 4, 2015
1 parent 25df4a5 commit eabb974
Show file tree
Hide file tree
Showing 23 changed files with 845 additions and 1,777 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ direct-test-short:
go test $(TEST_TAGS) -cover -test.short -v $(GO_PACKAGES)

direct-build:
chmod 755 hack/seccomp.sh
hack/seccomp.sh
go build -v $(GO_PACKAGES)

direct-install:
Expand Down
36 changes: 33 additions & 3 deletions configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,38 @@ type IDMap struct {
Size int `json:"size"`
}

type SeccompConf struct {
SysCalls []int `json:"syscalls"`
type Seccomp struct {
Syscalls []*Syscall `json:"syscalls"`
}

type Action int

const (
Kill Action = iota - 3
Trap
Allow
)

type Operator int

const (
EqualTo Operator = iota
NotEqualTo
GreatherThan
LessThan
MaskEqualTo
)

type Arg struct {
Index int `json:"index"`
Value uint32 `json:"value"`
Op Operator `json:"op"`
}

type Syscall struct {
Value int `json:"value"`
Action Action `json:"action"`
Args []*Arg `json:"args"`
}

// TODO Windows. Many of these fields should be factored out into those parts
Expand Down Expand Up @@ -110,5 +140,5 @@ type Config struct {
SystemProperties map[string]string `json:"system_properties"`

// SysCalls specify the system calls to keep when executing the process inside the container
Seccomps SeccompConf `json:"seccomp"`
Seccomp *Seccomp `json:"seccomp"`
}
13 changes: 6 additions & 7 deletions configs/namespaces_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ package configs
import "fmt"

const (
NEWNET NamespaceType = "NEWNET"
NEWPID NamespaceType = "NEWPID"
NEWNS NamespaceType = "NEWNS"
NEWUTS NamespaceType = "NEWUTS"
NEWIPC NamespaceType = "NEWIPC"
NEWUSER NamespaceType = "NEWUSER"
NEWSECCOMP NamespaceType = "NEWSECCOMP"
NEWNET NamespaceType = "NEWNET"
NEWPID NamespaceType = "NEWPID"
NEWNS NamespaceType = "NEWNS"
NEWUTS NamespaceType = "NEWUTS"
NEWIPC NamespaceType = "NEWIPC"
NEWUSER NamespaceType = "NEWUSER"
)

func NamespaceTypes() []NamespaceType {
Expand Down
17 changes: 6 additions & 11 deletions configs/namespaces_syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@ package configs

import "syscall"

var (
CLONE_SECCOMP = 0x10000 //diffrent from other flag, hard code
)

func (n *Namespace) Syscall() int {
return namespaceInfo[n.Type]
}

var namespaceInfo = map[NamespaceType]int{
NEWNET: syscall.CLONE_NEWNET,
NEWNS: syscall.CLONE_NEWNS,
NEWUSER: syscall.CLONE_NEWUSER,
NEWIPC: syscall.CLONE_NEWIPC,
NEWUTS: syscall.CLONE_NEWUTS,
NEWPID: syscall.CLONE_NEWPID,
NEWSECCOMP: CLONE_SECCOMP,
NEWNET: syscall.CLONE_NEWNET,
NEWNS: syscall.CLONE_NEWNS,
NEWUSER: syscall.CLONE_NEWUSER,
NEWIPC: syscall.CLONE_NEWIPC,
NEWUTS: syscall.CLONE_NEWUTS,
NEWPID: syscall.CLONE_NEWPID,
}

// CloneFlags parses the container's Namespaces options to set the correct
Expand Down
7 changes: 0 additions & 7 deletions container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
cmd.SysProcAttr.Credential = &syscall.Credential{}
}
}
if cloneFlags&uintptr(configs.CLONE_SECCOMP) != 0 {
//os don't surport for CLONE_SECCOMP, remote it
c.config.Namespaces.Remove(configs.NEWSECCOMP)
cloneFlags = c.config.Namespaces.CloneFlags()
} else {
c.config.Seccomps.SysCalls = []int{}
}
cmd.Env = append(cmd.Env, t)
cmd.SysProcAttr.Cloneflags = cloneFlags
return &initProcess{
Expand Down
58 changes: 0 additions & 58 deletions hack/seccomp.pl

This file was deleted.

4 changes: 0 additions & 4 deletions hack/seccomp.sh

This file was deleted.

Loading

0 comments on commit eabb974

Please sign in to comment.