|
| 1 | +id: k8s_clusterrolebindings_granting_cluster_admin |
| 2 | +title: Kubernetes ClusterRoleBindings Granting Cluster-Admin Role |
| 3 | +type: query |
| 4 | +primary_table: k8_cluster_role_binding |
| 5 | +description: Finds ClusterRoleBindings that grant the highly privileged 'cluster-admin' ClusterRole to users, groups, or service accounts. Granting cluster-admin provides unrestricted access across the entire cluster and should be strictly controlled. Allows excluding specific binding titles via parameter. |
| 6 | +metadata: |
| 7 | + reasoning: The 'cluster-admin' role provides superuser access to the entire Kubernetes cluster, allowing the subject to perform any action on any resource. Granting this role unnecessarily violates the principle of least privilege and significantly increases risk if the subject's credentials are compromised or misused. |
| 8 | + value: Enforce least privilege and minimize security risk by ensuring the powerful 'cluster-admin' role is only granted when absolutely necessary and to trusted entities, excluding known/approved bindings. |
| 9 | +integration_type: |
| 10 | + - kubernetes_cluster |
| 11 | +is_view: false |
| 12 | +parameters: |
| 13 | + - key: excluded_binding_titles |
| 14 | + # Comma-separated list of ClusterRoleBinding titles (exact match) to exclude from findings. |
| 15 | + # Use this to exempt specific, approved bindings granting cluster-admin. Max 4 suggested, but accepts more. |
| 16 | + # Example: "system:kube-dns-autoscaler-binding,my-admin-tool-binding" |
| 17 | + value: "" # Default: Report all cluster-admin bindings |
| 18 | +query: | |
| 19 | + WITH excluded_bindings AS ( |
| 20 | + SELECT trim(title) AS title |
| 21 | + FROM unnest(string_to_array('{{.excluded_binding_titles}}', ',')) AS title |
| 22 | + WHERE trim(title) != '' |
| 23 | + ) |
| 24 | + SELECT DISTINCT -- Distinct on binding, not subject, as the finding is about the binding itself |
| 25 | + crb.platform_integration_id, |
| 26 | + crb.title AS resource, -- The binding title is the resource |
| 27 | + CASE |
| 28 | + WHEN crb.title IN (SELECT title FROM excluded_bindings) THEN 'ok' |
| 29 | + ELSE 'alarm' |
| 30 | + END AS status, |
| 31 | + 'ClusterRoleBinding ''' || crb.title || ''' grants ''cluster-admin'' role' || |
| 32 | + CASE |
| 33 | + WHEN crb.title IN (SELECT title FROM excluded_bindings) THEN ' (Excluded by parameter).' |
| 34 | + ELSE '.' |
| 35 | + END |
| 36 | + AS reason, |
| 37 | + -- Flag if excluded |
| 38 | + (crb.title IN (SELECT title FROM excluded_bindings)) AS is_excluded_by_parameter, |
| 39 | + jsonb_build_object( |
| 40 | + 'binding_title', crb.title, |
| 41 | + 'role_ref_kind', crb.role_kind, |
| 42 | + 'role_ref_name', crb.role_name, |
| 43 | + 'subjects', crb.subjects -- Show all subjects granted by this binding |
| 44 | + ) AS finding_details |
| 45 | + FROM |
| 46 | + k8_cluster_role_binding crb |
| 47 | + WHERE crb.role_kind = 'ClusterRole' AND crb.role_name = 'cluster-admin' |
| 48 | + ORDER BY |
| 49 | + status ASC, -- Show alarms first |
| 50 | + crb.platform_integration_id ASC, |
| 51 | + resource ASC; |
| 52 | +tags: |
| 53 | + asset: Kubernetes |
| 54 | + value: Enforce Least Privilege |
| 55 | + outcome: Reduce Security Risk |
| 56 | + standard: CIS Kubernetes Benchmark |
| 57 | +classification: |
| 58 | + - [ "Security", "IAM", "Admin Rights" ] |
| 59 | + - [ "Security", "IAM", "Excessive Permissions" ] |
| 60 | + - [ "Infrastructure", "Kubernetes", "Access Control" ] |
0 commit comments