Skip to content

Commit b3fbec2

Browse files
committed
feat: Add security queries for AKS configurations and tests
1 parent 949d93d commit b3fbec2

File tree

11 files changed

+131
-0
lines changed

11 files changed

+131
-0
lines changed

ql/lib/codeql/bicep/frameworks/Microsoft/AKS.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ module AKS {
295295
*/
296296
Boolean getEnabled() { result = this.getProperty("enabled") }
297297

298+
boolean enabled() {
299+
result = this.getEnabled().getBool()
300+
}
301+
298302
string toString() { result = "AddonKubeDashboard" }
299303
}
300304

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name AKS cluster with kubeDashboard enabled
3+
* @description Detects Azure Kubernetes Service (AKS) clusters where the kubeDashboard addon is enabled (insecure configuration).
4+
* @kind problem
5+
* @problem.severity warning
6+
* @id bicep/aks-kubedashboard-enabled
7+
* @tags security, kubernetes, azure, aks
8+
*/
9+
import codeql.bicep.frameworks.Microsoft.AKS
10+
11+
from AKS::ManagedContainerResource r,
12+
AKS::ManagedContainerProperties::AddonProfiles addons,
13+
AKS::ManagedContainerProperties::AddonKubeDashboard dashboard
14+
where
15+
addons = r.getProperties().getAddonProfiles() and
16+
dashboard = addons.getKubeDashboard() and
17+
dashboard.enabled() = true
18+
select r, "AKS cluster has kubeDashboard addon enabled (insecure configuration)."
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name AKS cluster with private API server enabled
3+
* @description Detects Azure Kubernetes Service (AKS) clusters where the API server is private (private cluster enabled).
4+
* @kind problem
5+
* @problem.severity recommendation
6+
* @id bicep/aks-private-api-server-enabled
7+
* @tags security
8+
* kubernetes
9+
* azure
10+
*/
11+
import codeql.bicep.frameworks.Microsoft.AKS
12+
13+
from AKS::ManagedContainerResource r,
14+
AKS::ManagedContainerProperties::ApiServerAccessProfile api
15+
where
16+
api = r.getProperties().getApiServerAccessProfile() and
17+
api.enablePrivateCluster() = true
18+
select r, "AKS cluster API server is private (private cluster enabled)."

ql/src/security/AKS/AKSPublicApi.ql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @name AKS cluster with public API server
3+
* @description Detects Azure Kubernetes Service (AKS) clusters where the API server is publicly accessible (private cluster not enabled).
4+
* @kind problem
5+
* @problem.severity warning
6+
* @id bicep/aks-public-api-server
7+
* @tags security
8+
* azure
9+
* kubernetes
10+
*/
11+
import bicep
12+
13+
from AKS::ManagedContainerResource r,
14+
AKS::ManagedContainerProperties::ApiServerAccessProfile api
15+
where
16+
api = r.getProperties().getApiServerAccessProfile() and
17+
(
18+
// enablePrivateCluster is missing or set to false
19+
not exists(api.getEnablePrivateCluster()) or
20+
api.enablePrivateCluster() = false
21+
)
22+
select r, "AKS cluster API server is publicly accessible (private cluster not enabled)."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| aks-security-examples.bicep:2:1:30:1 | ManagedContainerResource | AKS cluster has kubeDashboard addon enabled (insecure configuration). |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
security/AKS/AKSKubeDashboardEnabled.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| aks-security-examples.bicep:32:1:62:1 | ManagedContainerResource | AKS cluster API server is private (private cluster enabled). |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
security/AKS/AKSPrivateApiEnabled.ql
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| aks-security-examples.bicep:2:1:30:1 | ManagedContainerResource | AKS cluster API server is publicly accessible (private cluster not enabled). |
2+
| aks-security-examples.bicep:32:1:62:1 | ManagedContainerResource | AKS cluster API server is publicly accessible (private cluster not enabled). |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
security/AKS/AKSPublicApi.ql
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Example Bicep file with AKS security issues for CodeQL testing
2+
resource insecureAks 'Microsoft.ContainerService/managedClusters@2023-01-01' = {
3+
name: 'aks-insecure-public'
4+
location: 'eastus'
5+
properties: {
6+
kubernetesVersion: '1.25.6' // Outdated version
7+
dnsPrefix: 'aks-public'
8+
agentPoolProfiles: [
9+
{
10+
name: 'agentpool'
11+
count: 1
12+
vmSize: 'Standard_DS2_v2'
13+
osType: 'Linux'
14+
mode: 'System'
15+
enableAutoScaling: false // No autoscaling
16+
}
17+
]
18+
networkProfile: {
19+
networkPlugin: 'azure'
20+
}
21+
apiServerAccessProfile: {
22+
enablePrivateCluster: false // Public API server
23+
}
24+
addonProfiles: {
25+
kubeDashboard: {
26+
enabled: true // Insecure: dashboard enabled
27+
}
28+
}
29+
}
30+
}
31+
32+
resource secureAks 'Microsoft.ContainerService/managedClusters@2023-01-01' = {
33+
name: 'aks-secure-private'
34+
location: 'eastus'
35+
properties: {
36+
kubernetesVersion: '1.28.3' // Supported version
37+
dnsPrefix: 'aks-private'
38+
agentPoolProfiles: [
39+
{
40+
name: 'agentpool'
41+
count: 3
42+
vmSize: 'Standard_DS2_v2'
43+
osType: 'Linux'
44+
mode: 'System'
45+
enableAutoScaling: true
46+
minCount: 1
47+
maxCount: 5
48+
}
49+
]
50+
networkProfile: {
51+
networkPlugin: 'azure'
52+
}
53+
apiServerAccessProfile: {
54+
enablePrivateCluster: true // Private API server
55+
}
56+
addonProfiles: {
57+
kubeDashboard: {
58+
enabled: false // Secure: dashboard disabled
59+
}
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)