-
Notifications
You must be signed in to change notification settings - Fork 1
/
all.rego
277 lines (226 loc) · 5.3 KB
/
all.rego
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
package docker.authz
allow = false {
not allow_full
}
allow = true {
allow_full
}
allow_full {
not plugins
not exec
not archive
not export
# not stop - no way to stop container
not kill
not pause
not restart
not update
# not attach - no way to read container output
# not logs - no way to read container output
not commit
not events
not session
not swarm
not services
not tasks
not nodes
not secrets
not configs
not volume
not volumes_ls
not binds
not capadd
not devices
not ipc
not network
not pid
# not ports - low severity
not privileged
not seccomp_apparmor_unconfined
} {
input.Headers["Opa-Bypass"] == "your_secret_password_here"
}
plugins { # docker plugin
val := PathArr[_]
val == "plugins"
}
exec { # docker exec
val := PathArr[_]
val == "exec"
}
archive { # docker cp
val := PathArr[_]
val == "archive"
}
export { # docker export
val := PathArr[_]
val == "export"
}
stop { # docker stop
val := PathArr[_]
val == "stop"
}
kill { #docker kill
val := PathArr[_]
val == "kill"
}
pause { #docker pause
val := PathArr[_]
val == "pause"
}
restart { #docker restart
val := PathArr[_]
val == "restart"
}
update { #docker update
val := PathArr[_]
val == "update"
}
attach { #docker attach
val := PathArr[_]
val == "attach"
}
logs { #docker logs
val := PathArr[_]
val == "logs"
}
commit { # docker commit
val := PathArr[_]
val == "commit"
}
events { # docker events
val := PathArr[_]
val == "events"}
session { # session API method
val := PathArr[_]
val == "session"}
swarm { # docker swarm
val := PathArr[_]
val == "swarm"
}
services { # docker service (part of swarm)
val := PathArr[_]
val == "services"
}
tasks { # tasks API methods
val := PathArr[_]
val == "tasks"
}
nodes { # docker nodes (part of swarm)
val := PathArr[_]
val == "nodes"
}
secrets { # docker secrets (part of swarm)
val := PathArr[_]
val == "secrets"
}
configs { # docker config (part of swarm)
val := PathArr[_]
val == "configs"
}
volume { # allow create only simple volumes. No options allowed. DriverOpts is null or empty object.
input.Body.DriverOpts != null
not driveropts_empty_object
}
driveropts_empty_object {
is_object(input.Body.DriverOpts)
count(input.Body.DriverOpts) == 0
}
volumes_ls {
input.Method == "GET"
count(PathArr) == 3
PathArr[2] == "volumes"
}
binds { # allow no binds or only allowed binds
input.Body.HostConfig.Binds != null
not binds_good_array
}
binds_good_array {
is_array(input.Body.HostConfig.Binds)
not binds_strings
not bad_strings
}
binds_strings {
val := input.Body.HostConfig.Binds[_]
not is_string(val)
}
bad_strings {
val := input.Body.HostConfig.Binds[_]
check_string(val)
}
check_string(s) { #not allow host file/folder binds except 3 allowed ones
startswith(s,"/")
s!= "/var/run/docker.sock:/var/run/docker.sock"
s!= "/var/run/docker.sock:/var/run/docker.sock:rw"
s!= "/cache"
s!= "/usr/local/bin/das-cli:/usr/local/bin/das-cli:ro"
}
capadd { # allow CapAdd == null or CapAdd == [] (empty array)
input.Body.HostConfig.CapAdd != null
not capadd_array
}
capadd_array {
is_array(input.Body.HostConfig.CapAdd)
count(input.Body.HostConfig.CapAdd) == 0
}
devices { #only null and empty arrays are allowed
input.Body.HostConfig.Devices != null
not devices_array
}
devices_array {
is_array(input.Body.HostConfig.Devices)
count(input.Body.HostConfig.Devices) == 0
}
ipc { #(only string values "none", "private" and "") OR null are allowed
input.Body.HostConfig.IpcMode != null
ipc_bad_string
}
ipc_bad_string {
not is_string(input.Body.HostConfig.IpcMode)
} {
input.Body.HostConfig.IpcMode != "none"
input.Body.HostConfig.IpcMode != "private"
input.Body.HostConfig.IpcMode != ""
}
#null or (string and string is good)
# not (not null and (not string or not string is good))
network { #(any string values except "host" and "bridge") OR null are allowed
input.Body.HostConfig.NetworkMode != null
network_bad_string
}
network_bad_string {
not is_string(input.Body.HostConfig.NetworkMode)
} {
input.Body.HostConfig.NetworkMode == "host"
}
pid { #only string values "" are allowed
input.Body.HostConfig.PidMode != null
pid_bad_string
}
pid_bad_string { #only string values "" are allowed
not is_string(input.Body.HostConfig.PidMode)
} {
input.Body.HostConfig.PidMode != ""
}
ports { # only null and empty arrays are allowed
input.Body.HostConfig.PortBindings != null
not ports_object
} { # PublishAllPorts is forbidden
input.Body.HostConfig.PublishAllPorts
}
ports_object {
is_object(input.Body.HostConfig.PortBindings)
count(input.Body.HostConfig.PortBindings) == 0
}
privileged {
input.Body.HostConfig.Privileged != null
privileged_bad
}
privileged_bad {
input.Body.HostConfig.Privileged
}
seccomp_apparmor_unconfined {
contains(input.Body.HostConfig.SecurityOpt[_], "unconfined")
}
PathArr :=split(ClearPath,"/") #some versions of docker do not send input.PathArr. So it's more reliable to compute PathArr ourself
ClearPath:= split(input.Path,"?")[0]