This repository has been archived by the owner on Feb 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 882
/
Copy pathrkt_seccomp_test.go
158 lines (149 loc) · 4.02 KB
/
rkt_seccomp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Copyright 2016 The rkt Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build host coreos src
package main
import (
"fmt"
"os"
"strings"
"testing"
"github.com/coreos/rkt/tests/testutils"
)
const (
baseApp = `--exec=/inspect -file-name / -stat-file`
)
var seccompTestCases = []struct {
name string
aciBuildArgs []string
runArgs []string
expectedOutput string
expectErr bool
}{
{
`default: aci seccomp filter or rkt whitelist`,
[]string{baseApp},
nil,
`/: mode: d`,
false,
},
{
`seccomp opt-out: no filtering`,
[]string{baseApp, "--seccomp-mode=retain", "--seccomp-set=@appc.io/all"},
nil,
`/: mode: d`,
false,
},
{
`seccomp opt-in: rkt whitelist`,
[]string{baseApp, "--seccomp-mode=remove", "--seccomp-set=@appc.io/empty"},
nil,
`/: mode: d`,
false,
},
{
`remove-set rkt blacklist`,
[]string{baseApp, "--seccomp-mode=remove", "--seccomp-set=@rkt/default-blacklist"},
nil,
`/: mode: d`,
false,
},
{
`remove-set unrelated blacklist`,
[]string{baseApp, "--seccomp-mode=remove", "--seccomp-set=reboot"},
nil,
`/: mode: d`,
false,
},
{
`remove-set blacklist stat with custom error`,
[]string{baseApp, "--seccomp-mode=remove,errno=EXFULL", "--seccomp-set=stat"},
nil,
"exchange full",
true,
},
{
`retain-set rkt whitelist`,
[]string{baseApp, "--seccomp-mode=retain", "--seccomp-set=@rkt/default-whitelist"},
nil,
`/: mode: d`,
false,
},
{
`retain-set docker whitelist`,
[]string{baseApp, "--seccomp-mode=retain", "--seccomp-set=@docker/default-whitelist"},
nil,
`/: mode: d`,
false,
},
{
`remove-set unprivileged group`,
[]string{baseApp, "--seccomp-mode=remove", "--seccomp-set=reboot"},
[]string{"--group=100"},
`/: mode: d`,
false,
},
{
`remove-set unprivileged user`,
[]string{baseApp, "--seccomp-mode=remove", "--seccomp-set=reboot"},
[]string{"--user=1000"},
`/: mode: d`,
false,
},
{
`CLI override whitelist all`,
[]string{baseApp, "--seccomp-mode=remove,errno=EXFULL", "--seccomp-set=stat"},
[]string{"--seccomp=mode=retain,@appc.io/all"},
`/: mode: d`,
false,
},
{
`CLI override blacklist stat with custom error`,
[]string{baseApp},
[]string{"--seccomp=mode=remove,errno=EXFULL,stat"},
"exchange full",
true,
},
{
`insecure-options fake override: remove-set blacklist stat with custom error`,
[]string{baseApp, "--seccomp-mode=remove,errno=EMULTIHOP", "--seccomp-set=stat"},
[]string{"--insecure-options=image,ondisk,capabilities,paths"},
"multihop attempted",
true,
},
{
`insecure-options simple override: remove-set blacklist stat with custom error`,
[]string{baseApp, "--seccomp-mode=remove,errno=EMULTIHOP", "--seccomp-set=stat"},
[]string{"--insecure-options=image,seccomp"},
`/: mode: d`,
false,
},
{
`insecure-options complete override: remove-set blacklist stat with custom error`,
[]string{baseApp, "--seccomp-mode=remove,errno=EMULTIHOP", "--seccomp-set=stat"},
[]string{"--insecure-options=image,all-run"},
`/: mode: d`,
false,
},
}
func TestAppIsolatorSeccomp(t *testing.T) {
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
for i, ti := range seccompTestCases {
t.Logf("Running seccomp test #%d: %v", i, ti.name)
aciFileName := patchTestACI(fmt.Sprintf("rkt-inspect-isolators-%d.aci", i), ti.aciBuildArgs...)
defer os.Remove(aciFileName)
rktCmd := fmt.Sprintf("%s --insecure-options=image run --debug %s %s", ctx.Cmd(), aciFileName, strings.Join(ti.runArgs, " "))
runRktAndCheckOutput(t, rktCmd, ti.expectedOutput, ti.expectErr)
}
}