github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/kubernetes/policies/general/allowing_users_rolebinding_add_other_users_rolebindings.rego (about)

     1  # METADATA
     2  # title: "Do not allow users in a rolebinding to add other users to their rolebindings"
     3  # description: "Check whether role permits allowing users in a rolebinding to add other users to their rolebindings"
     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: KSV055
    11  #   avd_id: AVD-KSV-0055
    12  #   severity: LOW
    13  #   short_code: view-all-secrets
    14  #   recommended_action: "Create a role which does not permit allowing users in a rolebinding to add other users to their rolebindings if not needed"
    15  #   input:
    16  #     selector:
    17  #     - type: kubernetes
    18  package builtin.kubernetes.KSV055
    19  
    20  import data.lib.kubernetes
    21  import data.lib.utils
    22  
    23  readKinds := ["Role", "ClusterRole"]
    24  
    25  allowing_users_rolebinding_add_other_users_their_rolebindings[input.rules[ru]] {
    26  	some ru
    27  	input.kind == readKinds[_]
    28  	input.rules[ru].apiGroups[_] == "*"
    29  	input.rules[ru].resources[_] == "rolebindings"
    30  	input.rules[ru].verbs[_] == "get"
    31  	input.rules[ru].verbs[_] == "patch"
    32  }
    33  
    34  deny[res] {
    35  	badRule := allowing_users_rolebinding_add_other_users_their_rolebindings[_]
    36  	msg := "Role permits allowing users in a rolebinding to add other users to their rolebindings"
    37  	res := result.new(msg, badRule)
    38  }