Skip to content

Commit 5cea2b9

Browse files
committed
feat: Improve Profiles support
1 parent 4907706 commit 5cea2b9

File tree

4 files changed

+258
-276
lines changed

4 files changed

+258
-276
lines changed

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

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ module AKS {
9898
result = this.getProperties().getAzureMonitorProfile()
9999
}
100100

101+
/**
102+
* Returns OS profiles for the cluster.
103+
*/
104+
OsProfiles::OsProfile getOsProfile() {
105+
result = this.getProperties().getLinuxProfile()
106+
or
107+
result = this.getProperties().getWindowsProfile()
108+
}
109+
101110
override string toString() { result = "ManagedContainerResource" }
102111
}
103112

@@ -191,7 +200,7 @@ module AKS {
191200
/**
192201
* Gets the network profile for the cluster.
193202
*/
194-
Network::NetworkProfile getNetworkProfile() { result = this.getProperty("networkProfile") }
203+
NetworkingProfiles::NetworkProfile getNetworkProfile() { result = this.getProperty("networkProfile") }
195204

196205
/**
197206
* Gets the API server access profile for the cluster.
@@ -248,7 +257,7 @@ module AKS {
248257
/**
249258
* Gets the storage profile for the cluster.
250259
*/
251-
StorageProfile getStorageProfile() { result = this.getProperty("storageProfile") }
260+
StorageProfiles::StorageProfile getStorageProfile() { result = this.getProperty("storageProfile") }
252261

253262
/**
254263
* Gets the workload auto scaler profile for the cluster.
@@ -260,12 +269,12 @@ module AKS {
260269
/**
261270
* Gets the Windows profile for the cluster.
262271
*/
263-
Profiles::WindowsProfile getWindowsProfile() { result = this.getProperty("windowsProfile") }
272+
OsProfiles::WindowsProfile getWindowsProfile() { result = this.getProperty("windowsProfile") }
264273

265274
/**
266275
* Gets the Linux profile for the cluster.
267276
*/
268-
Profiles::LinuxProfile getLinuxProfile() { result = this.getProperty("linuxProfile") }
277+
OsProfiles::LinuxProfile getLinuxProfile() { result = this.getProperty("linuxProfile") }
269278

270279
/**
271280
* Gets the HTTP proxy configuration for the cluster.
@@ -561,7 +570,7 @@ module AKS {
561570
/**
562571
* Gets the network profile.
563572
*/
564-
Expr getNetworkProfile() { result = this.getProperty("networkProfile") }
573+
NetworkingProfiles::NetworkProfile getNetworkProfile() { result = this.getProperty("networkProfile") }
565574

566575
/**
567576
* Gets the security profile.
@@ -700,7 +709,7 @@ module AKS {
700709
*/
701710
predicate hasCount() { exists(this.getCount()) }
702711

703-
string getToString() { result = "AgentPoolProfile" }
712+
string toString() { result = "AgentPoolProfile" }
704713
}
705714

706715
/**
@@ -1033,40 +1042,6 @@ module AKS {
10331042
string toString() { result = "ServiceMeshProfile" }
10341043
}
10351044

1036-
/**
1037-
* Represents the storage profile for a managed AKS cluster.
1038-
*/
1039-
class StorageProfile extends Object {
1040-
private Properties properties;
1041-
1042-
/**
1043-
* Constructs a StorageProfile object for the given properties.
1044-
*/
1045-
StorageProfile() { this = properties.getProperty("storageProfile") }
1046-
1047-
/**
1048-
* Gets the blob CSI driver property.
1049-
*/
1050-
Expr getBlobCSIDriver() { result = this.getProperty("blobCSIDriver") }
1051-
1052-
/**
1053-
* Gets the disk CSI driver property.
1054-
*/
1055-
Expr getDiskCSIDriver() { result = this.getProperty("diskCSIDriver") }
1056-
1057-
/**
1058-
* Gets the file CSI driver property.
1059-
*/
1060-
Expr getFileCSIDriver() { result = this.getProperty("fileCSIDriver") }
1061-
1062-
/**
1063-
* Gets the snapshot controller property.
1064-
*/
1065-
Expr getSnapshotController() { result = this.getProperty("snapshotController") }
1066-
1067-
string toString() { result = "StorageProfile" }
1068-
}
1069-
10701045
/**
10711046
* Represents the workload auto scaler profile for a managed AKS cluster.
10721047
*/

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

Lines changed: 2 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ module Compute {
7575
/**
7676
* Returns the network profile object for the virtual machine.
7777
*/
78-
NetworkProfile getNetworkProfile() { result = this.getProperty("networkProfile") }
78+
NetworkingProfiles::NetworkProfile getNetworkProfile() { result = this.getProperty("networkProfile") }
7979

8080
/**
8181
* Returns the OS profile object for the virtual machine.
8282
*/
83-
Compute::Profiles::OsProfile getOsProfile() { result = this.getProperty("osProfile") }
83+
OsProfiles::OsProfile getOsProfile() { result = this.getProperty("osProfile") }
8484

8585
override string toString() {
8686
result = "VirtualMachinesProperties[" + virtualMachines.getName() + "]"
@@ -108,171 +108,5 @@ module Compute {
108108
*/
109109
Expr getVmSize() { result = this.getProperty("vmSize") }
110110
}
111-
112-
/**
113-
* Represents a network profile for the Microsoft.Compute/virtualMachines type.
114-
*/
115-
class NetworkProfile extends Object {
116-
private Properties properties;
117-
118-
/**
119-
* Constructs a NetworkProfile object for the given properties.
120-
*/
121-
NetworkProfile() { this = properties.getProperty("networkProfile") }
122-
123-
/**
124-
* Returns a string representation of the network profile.
125-
*/
126-
string toString() { result = "NetworkProfile" }
127-
128-
/**
129-
* Returns the network interfaces for the virtual machine.
130-
*/
131-
Network::NetworkInterfaces getNetworkInterfaces() {
132-
result = resolveResource(this.getNetworkInterfacesObject())
133-
}
134-
135-
/**
136-
* Returns the networkInterfaces property as an object array.
137-
*/
138-
private Object getNetworkInterfacesObject() {
139-
result = this.getProperty("networkInterfaces").(Array).getElements()
140-
}
141-
}
142-
143-
/**
144-
* Represents the storage profile for the Microsoft.Compute/virtualMachines type.
145-
*/
146-
class StorageProfile extends Object {
147-
private Properties properties;
148-
149-
/**
150-
* Constructs a StorageProfile object for the given properties.
151-
*/
152-
StorageProfile() { this = properties.getProperty("storageProfile") }
153-
154-
/**
155-
* Returns the image reference for the storage profile.
156-
*/
157-
ImageReference getImageReference() { result = this.getProperty("imageReference") }
158-
}
159-
160-
/**
161-
* Represents an image reference for the Microsoft.Compute/virtualMachines type.
162-
* See: https://learn.microsoft.com/en-us/azure/templates/microsoft.compute/virtualmachines?pivots=deployment-language-bicep#imagereference
163-
*/
164-
class ImageReference extends Object {
165-
private StorageProfile storageProfile;
166-
167-
/**
168-
* Constructs an ImageReference object for the given storage profile.
169-
*/
170-
ImageReference() { this = storageProfile.getProperty("imageReference") }
171-
172-
/**
173-
* Returns the publisher property of the image reference.
174-
*/
175-
Expr getPublisher() { result = this.getProperty("publisher") }
176-
177-
/**
178-
* Returns the offer property of the image reference.
179-
*/
180-
Expr getOffer() { result = this.getProperty("offer") }
181-
182-
/**
183-
* Returns the sku property of the image reference.
184-
*/
185-
Expr getSku() { result = this.getProperty("sku") }
186-
187-
/**
188-
* Returns the version property of the image reference.
189-
*/
190-
Expr getVersion() { result = this.getProperty("version") }
191-
}
192-
}
193-
194-
module Profiles {
195-
/**
196-
* Represents the OS profile for the Microsoft.Compute/virtualMachines type.
197-
*/
198-
class OsProfile extends Object {
199-
private ResourceProperties properties;
200-
private string profileType;
201-
/**
202-
* Constructs an OsProfile object for the given properties.
203-
*/
204-
OsProfile() {
205-
this = properties.getProperty("osProfile") and profileType = "general"
206-
or
207-
this = properties.getProperty("linuxProfile") and profileType = "linux"
208-
or
209-
this = properties.getProperty("windowsProfile") and profileType = "windows"
210-
}
211-
212-
/**
213-
* Returns the computerName property of the OS profile.
214-
*/
215-
Expr getComputerName() { result = this.getProperty("computerName") }
216-
217-
string osType() {
218-
result = profileType
219-
}
220-
221-
/**
222-
* Returns the adminUsername property of the OS profile.
223-
*/
224-
Expr getAdminUsername() { result = this.getProperty("adminUsername") }
225-
226-
/**
227-
* Returns the adminPassword property of the OS profile.
228-
*/
229-
Expr getAdminPassword() { result = this.getProperty("adminPassword") }
230-
231-
SshConfig getSshConfig() {
232-
result = this.getProperty("ssh")
233-
}
234-
235-
string toString() {
236-
result = "OsProfile[" + profileType + "]"
237-
}
238-
}
239-
240-
class SshConfig extends Object {
241-
private OsProfile osProfile;
242-
243-
/**
244-
* Constructs an SshConfig object for the given OS profile.
245-
*/
246-
SshConfig() { this = osProfile.getProperty("ssh") }
247-
248-
/**
249-
* Returns the publicKeys property of the SSH configuration.
250-
*/
251-
SshPublicKey getPublicKeys() { result = this.getProperty("publicKeys").(Array).getElements() }
252-
253-
/**
254-
* Returns a string representation of the SSH configuration.
255-
*/
256-
string toString() { result = "SshConfig" }
257-
}
258-
259-
class SshPublicKey extends Object {
260-
private SshConfig sshConfig;
261-
262-
/**
263-
* Constructs an SshConfigPublicKey object for the given SSH configuration.
264-
*/
265-
SshPublicKey() { this = sshConfig.getProperty("publicKeys").(Array).getElements() }
266-
267-
/**
268-
* Returns the keyData property of the SSH public key.
269-
*/
270-
Expr getKeyData() { result = this.getProperty("keyData") }
271-
272-
/**
273-
* Returns a string representation of the SSH public key.
274-
*/
275-
string toString() { result = "SshConfigPublicKey" }
276-
}
277111
}
278112
}

0 commit comments

Comments
 (0)