Skip to content

Commit 9240121

Browse files
authored
Create inactive_and_expired_keys.yaml
1 parent e832222 commit 9240121

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
ID: inactive_and_expired_keys
2+
Title: Inactive and Expired API Keys
3+
Description: List of all inactive and expired API Keys from AWS and Azure platforms.
4+
Query:
5+
Engine: CloudQL-v0.0.1
6+
QueryToExecute: |
7+
WITH
8+
-- CTE for expired AWS keys
9+
expired_aws_keys AS (
10+
SELECT
11+
access_key_id AS key_id,
12+
user_name,
13+
status,
14+
'Aws' AS Platform,
15+
platform_account_id AS Integration
16+
FROM
17+
aws_iam_access_key
18+
WHERE
19+
status = 'Inactive'
20+
),
21+
22+
-- CTE for expired Azure key_credentials
23+
expired_azure_key_credentials AS (
24+
SELECT
25+
sp.id AS integration_id,
26+
sp.display_name,
27+
kc->>'keyId' AS key_id,
28+
kc->>'endDate' AS expiration_date
29+
FROM
30+
entraid_service_principal sp,
31+
LATERAL jsonb_array_elements(sp.key_credentials) AS kc
32+
WHERE
33+
(kc->>'endDate')::timestamp < NOW()
34+
),
35+
36+
-- CTE for expired Azure password_credentials
37+
expired_azure_password_credentials AS (
38+
SELECT
39+
sp.id AS integration_id,
40+
sp.display_name,
41+
pc->>'keyId' AS key_id,
42+
pc->>'endDate' AS expiration_date
43+
FROM
44+
entraid_service_principal sp,
45+
LATERAL jsonb_array_elements(sp.password_credentials) AS pc
46+
WHERE
47+
(pc->>'endDate')::timestamp < NOW()
48+
),
49+
50+
-- Combine expired Azure key_credentials and password_credentials
51+
expired_azure_keys AS (
52+
SELECT
53+
ekc.key_id,
54+
ekc.display_name AS user_name,
55+
'Expired' AS status,
56+
'Azure' AS Platform,
57+
ekc.integration_id AS Integration
58+
FROM
59+
expired_azure_key_credentials ekc
60+
61+
UNION ALL
62+
63+
SELECT
64+
epc.key_id,
65+
epc.display_name AS user_name,
66+
'Expired' AS status,
67+
'Azure' AS Platform,
68+
epc.integration_id AS Integration
69+
FROM
70+
expired_azure_password_credentials epc
71+
)
72+
73+
-- Final UNION ALL of AWS and Azure expired keys
74+
SELECT
75+
key_id,
76+
user_name,
77+
status,
78+
Platform,
79+
Integration
80+
FROM
81+
expired_aws_keys
82+
83+
UNION ALL
84+
85+
SELECT
86+
key_id,
87+
user_name,
88+
status,
89+
Platform,
90+
Integration
91+
FROM
92+
expired_azure_keys
93+
Tags:
94+
category:
95+
- Security
96+
subject:
97+
- Expired Keys

0 commit comments

Comments
 (0)