Skip to content

Commit bed0bb7

Browse files
committed
move default seccomp profile into package
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
1 parent 35e5011 commit bed0bb7

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

daemon/execdriver/native/create.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/docker/docker/daemon/execdriver"
1212
derr "github.com/docker/docker/errors"
1313
"github.com/docker/docker/pkg/mount"
14+
"github.com/docker/docker/profiles/seccomp"
1415

1516
"github.com/docker/docker/volume"
1617
"github.com/opencontainers/runc/libcontainer/apparmor"
@@ -71,7 +72,7 @@ func (d *Driver) createContainer(c *execdriver.Command, hooks execdriver.Hooks)
7172
}
7273

7374
if c.SeccompProfile == "" {
74-
container.Seccomp = getDefaultSeccompProfile()
75+
container.Seccomp = seccomp.GetDefaultProfile()
7576
}
7677
}
7778
// add CAP_ prefix to all caps for new libcontainer update to match
@@ -88,7 +89,7 @@ func (d *Driver) createContainer(c *execdriver.Command, hooks execdriver.Hooks)
8889
}
8990

9091
if c.SeccompProfile != "" && c.SeccompProfile != "unconfined" {
91-
container.Seccomp, err = loadSeccompProfile(c.SeccompProfile)
92+
container.Seccomp, err = seccomp.LoadProfile(c.SeccompProfile)
9293
if err != nil {
9394
return nil, err
9495
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"defaultAction": "SCMP_ACT_ERRNO",
3+
"syscalls": [
4+
{
5+
"name": "clone",
6+
"action": "SCMP_ACT_ALLOW",
7+
"args": [
8+
{
9+
"index": 0,
10+
"value": 2080505856,
11+
"valueTwo": 0,
12+
"op": "SCMP_CMP_MASKED_EQ"
13+
}
14+
]
15+
},
16+
{
17+
"name": "open",
18+
"action": "SCMP_ACT_ALLOW",
19+
"args": []
20+
},
21+
{
22+
"name": "close",
23+
"action": "SCMP_ACT_ALLOW",
24+
"args": []
25+
}
26+
]
27+
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build linux
22

3-
package native
3+
package seccomp
44

55
import (
66
"encoding/json"
@@ -11,11 +11,13 @@ import (
1111
"github.com/opencontainers/runc/libcontainer/seccomp"
1212
)
1313

14-
func getDefaultSeccompProfile() *configs.Seccomp {
14+
// GetDefaultProfile returns the default seccomp profile.
15+
func GetDefaultProfile() *configs.Seccomp {
1516
return defaultSeccompProfile
1617
}
1718

18-
func loadSeccompProfile(body string) (*configs.Seccomp, error) {
19+
// LoadProfile takes a file path a decodes the seccomp profile.
20+
func LoadProfile(body string) (*configs.Seccomp, error) {
1921
var config types.Seccomp
2022
if err := json.Unmarshal([]byte(body), &config); err != nil {
2123
return nil, fmt.Errorf("Decoding seccomp profile failed: %v", err)

daemon/execdriver/native/seccomp_default.go renamed to profiles/seccomp/seccomp_default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build linux,seccomp
22

3-
package native
3+
package seccomp
44

55
import (
66
"syscall"

profiles/seccomp/seccomp_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// +build linux
2+
3+
package seccomp
4+
5+
import (
6+
"io/ioutil"
7+
"testing"
8+
)
9+
10+
func TestLoadProfile(t *testing.T) {
11+
f, err := ioutil.ReadFile("fixtures/example.json")
12+
if err != nil {
13+
t.Fatal(err)
14+
}
15+
16+
if _, err := LoadProfile(string(f)); err != nil {
17+
t.Fatal(err)
18+
}
19+
}

daemon/execdriver/native/seccomp_unsupported.go renamed to profiles/seccomp/seccomp_unsupported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build linux,!seccomp
22

3-
package native
3+
package seccomp
44

55
import "github.com/opencontainers/runc/libcontainer/configs"
66

0 commit comments

Comments
 (0)