forked from yuvalavra/rbac-police
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrce_weak_ns.rego
28 lines (25 loc) · 873 Bytes
/
rce_weak_ns.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
package policy
import data.police_builtins as pb
import future.keywords.in
describe[{"desc": desc, "severity": severity}] {
desc := "Identities that can update or patch pods or create pods/exec in unprivileged namespaces can execute code on existing pods"
severity := "Medium"
}
targets := {"serviceAccounts", "nodes", "users", "groups"}
# This runs modify_pods and pods_exec but for weak namespaces
evaluateRoles(roles, owner) {
not pb.nodeRestrictionEnabledAndIsNode(owner)
some role in roles
not pb.affectsPrivNS(role)
some rule in role.rules
pb.valueOrWildcard(rule.apiGroups, "")
not pb.hasKey(rule, "resourceNames")
ruleCanRCE(rule)
}
ruleCanRCE(rule) {
pb.updateOrPatchOrWildcard(rule.verbs)
pb.valueOrWildcard(rule.resources, "pods")
} {
pb.valueOrWildcard(rule.verbs, "create")
pb.subresourceOrWildcard(rule.resources, "pods/exec")
}