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)."
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

0 commit comments

Comments
 (0)