forked from ad-freiburg/docker-no-trivial-root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.go
111 lines (90 loc) · 2.47 KB
/
plugin.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
package main
import (
"encoding/json"
"log"
"net/url"
"strings"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/go-plugins-helpers/authorization"
)
func NewNoRootPlugin() (*noroot, error) {
return &noroot{}, nil
}
type ContainerCreateConfig struct {
container.Config
HostConfig container.HostConfig
NetworkingConfig network.NetworkingConfig
}
type noroot struct {
}
func (p *noroot) AuthZReq(req authorization.Request) authorization.Response {
ruri, err := url.QueryUnescape(req.RequestURI)
if err != nil {
return authorization.Response{Err: err.Error()}
}
log.Println("User:", req.User)
log.Println("RequestMethod:", req.RequestMethod)
log.Println("ruri:", ruri)
if !strings.Contains(ruri, "containers/create") {
return authorization.Response{Allow: true}
}
var create ContainerCreateConfig
if err := json.Unmarshal(req.RequestBody, &create); err != nil {
return authorization.Response{Err: err.Error()}
}
if create.HostConfig.UsernsMode == "host" {
return authorization.Response{
Allow: false,
Err: "--userns=host not allowed"}
}
if create.HostConfig.UTSMode == "host" {
return authorization.Response{
Allow: false,
Err: "--uts=host not allowed"}
}
if create.HostConfig.PidMode == "host" {
return authorization.Response{
Allow: false,
Err: "--pid=host not allowed"}
}
if create.HostConfig.NetworkMode == "host" {
return authorization.Response{
Allow: false,
Err: "--net=host not allowed"}
}
if len(create.HostConfig.LogConfig.Type) > 0 {
return authorization.Response{
Allow: false,
Err: "--log-driver not allowed"}
}
if len(create.HostConfig.LogConfig.Config) > 0 {
return authorization.Response{
Allow: false,
Err: "--log-opt not allowed"}
}
if len(create.HostConfig.CapAdd) > 0 {
return authorization.Response{
Allow: false,
Err: "--cap-add not allowed"}
}
if len(create.HostConfig.Devices) > 0 {
return authorization.Response{
Allow: false,
Err: "--device not allowed"}
}
if len(create.HostConfig.SecurityOpt) > 0 {
return authorization.Response{
Allow: false,
Err: "--security-opt not allowed"}
}
if create.HostConfig.Privileged {
return authorization.Response{
Allow: false,
Err: "--privileged not allowed"}
}
return authorization.Response{Allow: true}
}
func (p *noroot) AuthZRes(req authorization.Request) authorization.Response {
return authorization.Response{Allow: true}
}