-
Notifications
You must be signed in to change notification settings - Fork 4
/
execPodsClusterRole.go
45 lines (37 loc) · 1.01 KB
/
execPodsClusterRole.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
// OPR-R15-RBAC - ClusterRole can exec into Pods
package rules
import (
"encoding/json"
rbacv1 "k8s.io/api/rbac/v1"
)
func ExecPodsClusterRole(input []byte) int {
rbac := 0
var foundPodsGet, foundExecCreate bool
clusterRole := &rbacv1.ClusterRole{}
err := json.Unmarshal(input, clusterRole)
if err != nil {
return 0
}
for _, rule := range clusterRole.Rules {
if contains("", rule.APIGroups) &&
containsAll([]string{"pods", "pods/exec"}, rule.Resources) &&
(contains("*", rule.Verbs) || containsAll([]string{"get", "create"}, rule.Verbs)) {
rbac++
} else if contains("", rule.APIGroups) &&
contains("pods", rule.Resources) &&
containsAny([]string{"*", "get"}, rule.Verbs) {
foundPodsGet = true
if foundPodsGet && foundExecCreate {
rbac++
}
} else if contains("", rule.APIGroups) &&
contains("pods/exec", rule.Resources) &&
containsAny([]string{"*", "create"}, rule.Verbs) {
foundExecCreate = true
if foundPodsGet && foundExecCreate {
rbac++
}
}
}
return rbac
}