Skip to content

Commit d275240

Browse files
committed
feat: Add managed containers support
1 parent 032b369 commit d275240

File tree

3 files changed

+192
-1
lines changed

3 files changed

+192
-1
lines changed

ql/lib/codeql/bicep/Frameworks.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import frameworks.Microsoft.Cache
22
import frameworks.Microsoft.Compute
33
import frameworks.Microsoft.Containers
44
import frameworks.Microsoft.General
5+
import frameworks.Microsoft.ManagedContainers
56
import frameworks.Microsoft.Network
67
import frameworks.Microsoft.Storage
78
import frameworks.Microsoft.Databases
8-
import frameworks.Microsoft.KeyVault
9+
import frameworks.Microsoft.KeyVault
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
private import bicep
2+
private import codeql.bicep.Concepts
3+
4+
module ManagedContainers {
5+
/**
6+
* Represents a Microsoft.ContainerService/managedClusters resource (AKS) in a Bicep file.
7+
* See: https://learn.microsoft.com/en-us/azure/templates/microsoft.containerservice/managedclusters
8+
*/
9+
class ManagedContainerResource extends Resource {
10+
/**
11+
* Constructs a ManagedContainerResource for Microsoft.ContainerService/managedClusters resources.
12+
*/
13+
ManagedContainerResource() {
14+
this.getResourceType().regexpMatch("^Microsoft.ContainerService/managedClusters@.*")
15+
}
16+
17+
/**
18+
* Returns the properties object for the AKS resource.
19+
*/
20+
ManagedContainerProperties::Properties getProperties() {
21+
result = this.getProperty("properties")
22+
}
23+
24+
/**
25+
* Returns the kubernetesVersion property.
26+
*/
27+
StringLiteral getKubernetesVersion() { result = this.getProperties().getKubernetesVersion() }
28+
29+
/**
30+
* Returns the dnsPrefix property.
31+
*/
32+
StringLiteral getDnsPrefix() { result = this.getProperties().getDnsPrefix() }
33+
34+
/**
35+
* Returns the agentPoolProfiles property.
36+
*/
37+
ManagedContainerProperties::AgentPoolProfiles getAgentPoolProfiles() {
38+
result = this.getProperties().getAgentPoolProfiles()
39+
}
40+
41+
/**
42+
* Returns the networkProfile property.
43+
*/
44+
Network::NetworkProfile getNetworkProfile() {
45+
result = this.getProperties().getNetworkProfile()
46+
}
47+
48+
override string toString() { result = "ManagedContainerResource" }
49+
}
50+
51+
module ManagedContainerProperties {
52+
/**
53+
* Represents the properties object for a Kubernetes (AKS) resource.
54+
*/
55+
class Properties extends Object {
56+
private ManagedContainerResource resource;
57+
58+
Properties() { this = resource.getProperty("properties") }
59+
60+
ManagedContainerResource getManagedContainerResource() { result = resource }
61+
62+
StringLiteral getKubernetesVersion() { result = this.getProperty("kubernetesVersion") }
63+
64+
StringLiteral getDnsPrefix() { result = this.getProperty("dnsPrefix") }
65+
66+
AgentPoolProfiles getAgentPoolProfiles() {
67+
result = this.getProperty("agentPoolProfiles").(Array).getElements()
68+
}
69+
70+
Network::NetworkProfile getNetworkProfile() { result = this.getProperty("networkProfile") }
71+
72+
ApiServerAccessProfile getApiServerAccessProfile() {
73+
result = this.getProperty("apiServerAccessProfile")
74+
}
75+
76+
AddonProfiles getAddonProfiles() { result = this.getProperty("addonProfiles") }
77+
78+
Expr getIdentity() { result = this.getProperty("identity") }
79+
80+
Expr getLinuxProfile() { result = this.getProperty("linuxProfile") }
81+
82+
Expr getWindowsProfile() { result = this.getProperty("windowsProfile") }
83+
84+
Expr getServicePrincipalProfile() { result = this.getProperty("servicePrincipalProfile") }
85+
86+
Expr getAadProfile() { result = this.getProperty("aadProfile") }
87+
88+
Expr getAutoScalerProfile() { result = this.getProperty("autoScalerProfile") }
89+
90+
Expr getHttpProxyConfig() { result = this.getProperty("httpProxyConfig") }
91+
92+
Expr getPodIdentityProfile() { result = this.getProperty("podIdentityProfile") }
93+
94+
Expr getWorkloadAutoScalerProfile() { result = this.getProperty("workloadAutoScalerProfile") }
95+
96+
Expr getStorageProfile() { result = this.getProperty("storageProfile") }
97+
98+
Sku getSku() { result = this.getProperty("sku") }
99+
100+
Tags getTags() { result = this.getProperty("tags") }
101+
102+
string toString() { result = "ManagedContainerProperties" }
103+
}
104+
105+
class AgentPoolProfiles extends Object {
106+
private Properties properties;
107+
108+
AgentPoolProfiles() {
109+
this = properties.getProperty("agentPoolProfiles").(Array).getElements()
110+
}
111+
112+
StringLiteral getName() { result = this.getProperty("name") }
113+
114+
StringLiteral getVmSize() { result = this.getProperty("vmSize") }
115+
116+
Expr getCount() { result = this.getProperty("count") }
117+
118+
Expr getOsType() { result = this.getProperty("osType") }
119+
120+
Expr getMode() { result = this.getProperty("mode") }
121+
122+
string toString() { result = "AgentPoolProfiles" }
123+
}
124+
125+
class ApiServerAccessProfile extends Object {
126+
private Properties properties;
127+
128+
ApiServerAccessProfile() { this = properties.getProperty("apiServerAccessProfile") }
129+
130+
StringLiteral getEnablePrivateCluster() { result = this.getProperty("enablePrivateCluster") }
131+
132+
StringLiteral getPrivateDnsZone() { result = this.getProperty("privateDnsZone") }
133+
134+
string toString() { result = "ApiServerAccessProfile" }
135+
}
136+
137+
class AddonProfiles extends Object {
138+
private Properties properties;
139+
140+
AddonProfiles() { this = properties.getProperty("addonProfiles") }
141+
142+
AddonKubeDashboard getKubeDashboard() { result = this.getProperty("kubeDashboard") }
143+
144+
string toString() { result = "AddonProfiles" }
145+
}
146+
147+
class AddonKubeDashboard extends Object {
148+
private AddonProfiles profiles;
149+
150+
AddonKubeDashboard() { this = profiles.getProperty("kubeDashboard") }
151+
152+
Boolean getEnabled() { result = this.getProperty("enabled") }
153+
154+
string toString() { result = "AddonKubeDashboard" }
155+
}
156+
157+
class AddonAzurePolicy extends Object {
158+
private AddonProfiles profiles;
159+
160+
AddonAzurePolicy() { this = profiles.getProperty("azurePolicy") }
161+
162+
Boolean getEnabled() { result = this.getProperty("enabled") }
163+
164+
string toString() { result = "AddonAzurePolicy" }
165+
}
166+
}
167+
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,27 @@ module Network {
321321
}
322322
}
323323
}
324+
325+
class NetworkProfile extends Object {
326+
private Resource resource;
327+
328+
NetworkProfile() {
329+
exists(Object props |
330+
props = resource.getProperty("properties") and
331+
this = props.getProperty("networkProfile")
332+
)
333+
}
334+
335+
Resource getResource() { result = resource }
336+
337+
StringLiteral getNetworkPlugin() { result = this.getProperty("networkPlugin") }
338+
339+
string networkPlugin() { result = this.getNetworkPlugin().getValue() }
340+
341+
StringLiteral getNetworkPolicy() { result = this.getProperty("networkPolicy") }
342+
343+
string networkPolicy() { result = this.getNetworkPolicy().getValue() }
344+
345+
string toString() { result = "NetworkProfile" }
346+
}
324347
}

0 commit comments

Comments
 (0)