Skip to content

Commit cdf51ec

Browse files
committed
Fix: adding new queries
1 parent c673e25 commit cdf51ec

13 files changed

+645
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
id: aws_cognito_user_pool_2
2+
type: query
3+
title: List All AWS Cognito User Pools with MFA Configuration
4+
description: Allows users to query AWS Cognito User Pools to fetch detailed information about each user pool, including the pool's configuration, status, and associated metadata.
5+
integration_type:
6+
- aws_cloud_account
7+
query: |
8+
SELECT
9+
name,
10+
arn,
11+
mfa_configuration
12+
FROM
13+
aws_cognito_user_pool
14+
WHERE
15+
mfa_configuration != 'OFF';
16+
tags:
17+
cloud_asset_management:
18+
- 'true'
19+
cloud_identity_security:
20+
- 'true'
21+
cloud_provider:
22+
- aws
23+
cloud_service:
24+
- Cognito
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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" ]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
id: k8s_containers_running_as_root
2+
title: Kubernetes Containers Running as Root
3+
type: query
4+
primary_table: k8_pod
5+
description: Finds containers that are configured to run as root (or likely to run as root by default) within pods. This checks for securityContext.runAsNonRoot=false or missing, and securityContext.runAsUser=0 or missing at both pod and container levels. Running containers as root increases the potential impact of a container compromise.
6+
metadata:
7+
reasoning: Containers running as the root user have elevated privileges within the container's namespaces. If a vulnerability is exploited, the attacker gains root access within the container, potentially facilitating escape or further exploitation. Best practice is to run containers as non-root users with the minimum required privileges.
8+
value: Reduce the potential impact of container compromises by enforcing the principle of least privilege for container user IDs.
9+
integration_type:
10+
- kubernetes_cluster
11+
query: |
12+
SELECT DISTINCT
13+
p.platform_integration_id,
14+
p.namespace || '/' || p.title AS resource,
15+
'alarm' AS status,
16+
'Pod ''' || p.title || ''' in namespace ''' || p.namespace || ''' container ''' || (c ->> 'Name') || ''' may run as root.' AS reason,
17+
jsonb_build_object(
18+
'pod_title', p.title,
19+
'namespace', p.namespace,
20+
'container_name', c ->> 'Name',
21+
'container_image', c ->> 'Image',
22+
'container_security_context', c -> 'SecurityContext',
23+
'pod_security_context', p.security_context,
24+
'node_name', p.node_name
25+
) AS finding_details
26+
FROM
27+
k8_pod AS p,
28+
jsonb_array_elements(COALESCE(p.containers, '[]'::jsonb)) AS c
29+
WHERE
30+
-- Condition 1: Container explicitly configured to run as root
31+
(
32+
(c -> 'SecurityContext' ->> 'RunAsNonRoot' = 'false') -- Explicitly false
33+
OR
34+
( (c -> 'SecurityContext' ->> 'RunAsNonRoot' IS NULL) AND (c -> 'SecurityContext' ->> 'RunAsUser' = '0') ) -- runAsNonRoot is null, and runAsUser is 0
35+
)
36+
-- Condition 2: Pod context forces root, and container doesn't override
37+
OR
38+
(
39+
( (p.security_context ->> 'RunAsNonRoot' = 'false') OR ( (p.security_context ->> 'RunAsNonRoot' IS NULL) AND (p.security_context ->> 'RunAsUser' = '0') ) ) -- Pod context forces root
40+
AND (c -> 'SecurityContext' ->> 'RunAsUser' IS NULL) -- Container does not specify user
41+
AND (c -> 'SecurityContext' ->> 'RunAsNonRoot' IS NULL OR c -> 'SecurityContext' ->> 'RunAsNonRoot' = 'false') -- Container does not specify runAsNonRoot=true
42+
)
43+
-- Condition 3: Neither Pod nor Container specifies user/nonRoot (defaults to image definition, often root) - check if *no* setting prevents root
44+
OR
45+
(
46+
(p.security_context ->> 'RunAsUser' IS NULL AND p.security_context ->> 'RunAsNonRoot' IS NULL) -- Pod has no relevant settings
47+
AND (c -> 'SecurityContext' ->> 'RunAsUser' IS NULL AND c -> 'SecurityContext' ->> 'RunAsNonRoot' IS NULL) -- Container has no relevant settings
48+
)
49+
ORDER BY
50+
p.platform_integration_id ASC,
51+
resource ASC;
52+
tags:
53+
asset: Kubernetes
54+
value: Reduce Security Risk
55+
outcome: Limit Blast Radius
56+
standard: CIS Kubernetes Benchmark
57+
classification:
58+
- [ "Security", "Workload Configuration" ]
59+
- [ "Security", "Vulnerabilities", "Containers" ]
60+
- [ "Security", "IAM", "Excessive Permissions" ]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
id: k8s_ingress_without_tls
2+
title: Kubernetes Ingress Without TLS Configuration
3+
type: query
4+
primary_table: k8_ingress
5+
description: Finds Ingress resources that define routing rules but do not have a corresponding TLS configuration section. This indicates potential HTTP traffic exposure for paths defined in the Ingress, lacking encryption.
6+
metadata:
7+
reasoning: Ingress resources managing external access should enforce TLS (HTTPS) to encrypt traffic between clients and the cluster. Ingresses without TLS configuration handle traffic over unencrypted HTTP, exposing sensitive data in transit and enabling potential man-in-the-middle attacks.
8+
value: Protect data confidentiality and integrity for external traffic by ensuring all Ingress resources enforce TLS encryption.
9+
integration_type:
10+
- kubernetes_cluster
11+
query: |
12+
SELECT
13+
i.platform_integration_id,
14+
i.namespace || '/' || i.title AS resource,
15+
'alarm' AS status,
16+
'Ingress ''' || i.title || ''' in namespace ''' || i.namespace || ''' defines rules but lacks TLS configuration.' AS reason,
17+
jsonb_build_object(
18+
'ingress_title', i.title,
19+
'namespace', i.namespace,
20+
'ingress_class_name', i.ingress_class_name,
21+
'rules_defined', i.rules,
22+
'tls_configured', i.tls -- Will be null or empty array
23+
) AS finding_details
24+
FROM
25+
k8_ingress AS i
26+
WHERE
27+
COALESCE(jsonb_array_length(i.rules), 0) > 0 -- Has rules defined
28+
AND COALESCE(jsonb_array_length(i.tls), 0) = 0 -- Has no TLS section defined
29+
ORDER BY
30+
i.platform_integration_id ASC,
31+
resource ASC;
32+
tags:
33+
asset: Kubernetes
34+
value: Enhance Data Security
35+
outcome: Enforce Encryption
36+
standard: CIS Kubernetes Benchmark
37+
classification:
38+
- [ "Security", "Web Security" ]
39+
- [ "Security", "Data Protection" ]
40+
- [ "Infrastructure", "Kubernetes", "Networking" ]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
id: k8s_pod_privileged_containers
2+
title: Kubernetes Pods with Privileged Containers
3+
type: query
4+
primary_table: k8_pod
5+
description: Finds container workloads running with the securityContext.privileged=true setting enabled across all clusters. Privileged containers bypass standard container isolation and security controls, significantly increasing risk and potential blast radius if compromised.
6+
metadata:
7+
reasoning: Privileged containers bypass kernel namespacing and control group restrictions, gaining access to host devices and elevated kernel capabilities. This significantly increases the risk and potential impact of a container escape if the workload is breached, expanding the blast radius.
8+
value: Limit the blast radius of potential workload compromises and reduce overall security risk by enforcing standard container isolation and removing privileged access.
9+
integration_type:
10+
- kubernetes_cluster
11+
query: |
12+
SELECT DISTINCT
13+
p.platform_integration_id,
14+
p.namespace || '/' || p.title AS resource, -- Use namespace/name as unique resource identifier
15+
'alarm' as status,
16+
'Pod ''' || p.title || ''' in namespace ''' || p.namespace || ''' has privileged container ''' || (c ->> 'Name') || '''.' AS reason,
17+
jsonb_build_object(
18+
'pod_title', p.title,
19+
'namespace', p.namespace,
20+
'container_name', c ->> 'Name',
21+
'container_image', c ->> 'Image',
22+
'container_security_context', c -> 'SecurityContext',
23+
'node_name', p.node_name
24+
) AS finding_details
25+
FROM
26+
k8_pod AS p,
27+
jsonb_array_elements(COALESCE(p.containers, '[]'::jsonb)) AS c -- Use jsonb_array_elements for safety
28+
WHERE
29+
-- Check if securityContext exists and privileged is explicitly true
30+
c -> 'SecurityContext' ->> 'Privileged' = 'true'
31+
ORDER BY
32+
p.platform_integration_id ASC,
33+
resource ASC;
34+
tags:
35+
asset: Kubernetes
36+
value: Reduce Security Risk
37+
outcome: Limit Blast Radius
38+
classification:
39+
- [ "Security", "Workload Configuration" ]
40+
- [ "Security", "Vulnerabilities", "Containers" ]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
id: k8s_pods_mounting_sensitive_hostpaths
2+
title: Kubernetes Pods Mounting Sensitive Host Paths
3+
type: query
4+
primary_table: k8_pod
5+
description: Finds pods mounting potentially sensitive host filesystem paths using hostPath volumes (e.g., '/', '/etc', '/var/run/docker.sock', '/var/lib/kubelet', '/proc'). Access to sensitive host paths can break node isolation, allowing container escape, data exposure, or modification of the host system.
6+
metadata:
7+
reasoning: Mounting host paths directly into pods bypasses storage abstractions and couples the pod lifecycle to the node's filesystem. Accessing sensitive paths like '/', '/etc', '/var/run/docker.sock', or '/proc' can grant the pod excessive privileges, allow container escape, or enable interference with the node's operation or other pods.
8+
value: Maintain node isolation, prevent container escape vectors, and protect host system integrity by disallowing or strictly controlling hostPath volumes, especially for sensitive paths.
9+
integration_type:
10+
- kubernetes_cluster
11+
query: |
12+
WITH sensitive_paths (path) AS (
13+
VALUES ('/'), ('/etc'), ('/var/run/docker.sock'), ('/var/lib/kubelet'), ('/proc'), ('/root') -- Hardcoded list as requested
14+
)
15+
SELECT DISTINCT
16+
p.platform_integration_id,
17+
p.namespace || '/' || p.title AS resource,
18+
'alarm' AS status,
19+
'Pod ''' || p.title || ''' in namespace ''' || p.namespace || ''' mounts sensitive hostPath ''' || (v -> 'HostPath' ->> 'Path') || ''' via volume ''' || (v ->> 'Name') || '''.' AS reason,
20+
jsonb_build_object(
21+
'pod_title', p.title,
22+
'namespace', p.namespace,
23+
'node_name', p.node_name,
24+
'volume_name', v ->> 'Name',
25+
'host_path_mounted', v -> 'HostPath' ->> 'Path',
26+
'volume_definition', v
27+
) AS finding_details
28+
FROM
29+
k8_pod AS p,
30+
jsonb_array_elements(COALESCE(p.volumes, '[]'::jsonb)) AS v
31+
WHERE
32+
v ->> 'HostPath' IS NOT NULL -- It is a hostPath volume
33+
AND EXISTS ( -- Check if the mounted path matches any sensitive path
34+
SELECT 1
35+
FROM sensitive_paths sp
36+
WHERE v -> 'HostPath' ->> 'Path' = sp.path
37+
OR sp.path = '/' -- If '/' is sensitive, any hostPath is sensitive (except maybe empty path?)
38+
-- Basic check if mounted path is a parent of a sensitive path
39+
OR (sp.path LIKE (v -> 'HostPath' ->> 'Path') || '/%' AND v -> 'HostPath' ->> 'Path' != '/')
40+
)
41+
ORDER BY
42+
p.platform_integration_id ASC,
43+
resource ASC;
44+
tags:
45+
asset: Kubernetes
46+
value: Reduce Attack Surface
47+
outcome: # Use list format for multiple outcomes
48+
- Enhance Isolation
49+
- Prevent Container Escape
50+
standard: CIS Kubernetes Benchmark
51+
classification:
52+
- [ "Security", "Workload Configuration" ]
53+
- [ "Security", "Vulnerabilities", "Configuration" ]
54+
- [ "Infrastructure", "Storage" ]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
id: k8s_pods_using_host_network
2+
title: Kubernetes Pods Using Host Network
3+
type: query
4+
primary_table: k8_pod
5+
description: Finds pods configured with spec.hostNetwork=true. These pods share the host's network namespace, bypassing pod network isolation and potentially exposing host network services or allowing network sniffing.
6+
metadata:
7+
reasoning: Pods running with hostNetwork share the network namespace of the underlying node. This breaks network isolation between pods, allows access to the node's loopback device, potentially exposes node services, and enables sniffing of network traffic on the node. It significantly increases the attack surface and risk.
8+
value: Maintain network isolation, reduce attack surface, and prevent potential information disclosure or interference by avoiding hostNetwork where possible.
9+
integration_type:
10+
- kubernetes_cluster
11+
query: |
12+
SELECT DISTINCT
13+
p.platform_integration_id,
14+
p.namespace || '/' || p.title AS resource,
15+
'alarm' AS status,
16+
'Pod ''' || p.title || ''' in namespace ''' || p.namespace || ''' is configured to use host network (spec.hostNetwork=true).' AS reason,
17+
jsonb_build_object(
18+
'pod_title', p.title,
19+
'namespace', p.namespace,
20+
'node_name', p.node_name,
21+
'host_network_setting', p.host_network
22+
) AS finding_details
23+
FROM
24+
k8_pod AS p
25+
WHERE
26+
p.host_network = true
27+
ORDER BY
28+
p.platform_integration_id ASC,
29+
resource ASC;
30+
tags:
31+
asset: Kubernetes
32+
value: Reduce Attack Surface
33+
outcome: Enhance Isolation
34+
standard: CIS Kubernetes Benchmark
35+
classification:
36+
- [ "Security", "Workload Configuration" ]
37+
- [ "Security", "Vulnerabilities", "Configuration" ]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
id: k8s_pods_using_host_pid_ipc
2+
title: Kubernetes Pods Using Host PID or IPC Namespaces
3+
type: query
4+
primary_table: k8_pod
5+
description: Finds pods configured with spec.hostPID=true or spec.hostIPC=true. These pods share the host's process ID or inter-process communication namespaces, breaking isolation and potentially allowing process inspection/manipulation or interference with host processes.
6+
metadata:
7+
reasoning: Sharing the host's PID namespace allows processes within the pod to see (and potentially signal) all other processes on the host node. Sharing the host's IPC namespace allows processes in the pod to interact with host processes via shared memory or other IPC mechanisms. Both break crucial container isolation boundaries.
8+
value: Maintain process and IPC isolation, reduce attack surface, and prevent potential information disclosure or interference with host node processes.
9+
integration_type:
10+
- kubernetes_cluster
11+
query: |
12+
SELECT DISTINCT
13+
p.platform_integration_id,
14+
p.namespace || '/' || p.title AS resource,
15+
'alarm' AS status,
16+
'Pod ''' || p.title || ''' in namespace ''' || p.namespace || ''' is configured to use ' ||
17+
CASE WHEN p.host_pid = true AND p.host_ipc = true THEN 'host PID and IPC namespaces'
18+
WHEN p.host_pid = true THEN 'host PID namespace'
19+
ELSE 'host IPC namespace'
20+
END || '.' AS reason,
21+
jsonb_build_object(
22+
'pod_title', p.title,
23+
'namespace', p.namespace,
24+
'node_name', p.node_name,
25+
'host_pid_setting', p.host_pid,
26+
'host_ipc_setting', p.host_ipc
27+
) AS finding_details
28+
FROM
29+
k8_pod AS p
30+
WHERE
31+
p.host_pid = true OR p.host_ipc = true
32+
ORDER BY
33+
p.platform_integration_id ASC,
34+
resource ASC;
35+
tags:
36+
asset: Kubernetes
37+
value: Reduce Attack Surface
38+
outcome: Enhance Isolation
39+
standard: CIS Kubernetes Benchmark
40+
classification:
41+
- [ "Security", "Workload Configuration" ]
42+
- [ "Security", "Vulnerabilities", "Configuration" ]

0 commit comments

Comments
 (0)