github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/kubernetes/policies/general/attaching_pod_view_logs_realtime.rego (about) 1 # METADATA 2 # title: "Do not allow attaching to shell on pods" 3 # description: "Check whether role permits attaching to shell on pods" 4 # scope: package 5 # schemas: 6 # - input: schema["kubernetes"] 7 # related_resources: 8 # - https://kubernetes.io/docs/concepts/security/rbac-good-practices/ 9 # custom: 10 # id: KSV054 11 # avd_id: AVD-KSV-0054 12 # severity: HIGH 13 # short_code: no-attaching-shell-pods 14 # recommended_action: "Create a role which does not permit attaching to shell on pods" 15 # input: 16 # selector: 17 # - type: kubernetes 18 package builtin.kubernetes.KSV054 19 20 import data.lib.kubernetes 21 import data.lib.utils 22 23 readKinds := ["Role", "ClusterRole"] 24 25 attach_shell_on_pod[ruleA] { 26 input.kind == readKinds[_] 27 some i, j 28 ruleA := input.rules[i] 29 ruleB := input.rules[j] 30 i < j 31 ruleA.apiGroups[_] == "*" 32 ruleA.resources[_] == "pods/attach" 33 ruleA.verbs[_] == "create" 34 ruleB.apiGroups[_] == "*" 35 ruleB.resources[_] == "pods" 36 ruleB.verbs[_] == "get" 37 } 38 39 deny[res] { 40 badRule := attach_shell_on_pod[_] 41 msg := "Role permits attaching to shell on pods" 42 res := result.new(msg, badRule) 43 }