Skip to content

Commit 67471b3

Browse files
committed
feat: Improve storage encryption
1 parent e3f59eb commit 67471b3

File tree

1 file changed

+148
-39
lines changed

1 file changed

+148
-39
lines changed

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

Lines changed: 148 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ module Storage {
2424
*/
2525
StringLiteral getKind() { result = this.getProperty("kind") }
2626

27+
DiskEncryption::EncryptionSettings getEncryptionSettings() {
28+
result = this.getProperties().getProperty("encryption")
29+
}
30+
2731
/**
2832
* Gets the network ACLs for the storage account.
2933
*/
@@ -34,7 +38,7 @@ module Storage {
3438
*/
3539
Sku getSku() { result = this.getProperty("sku") }
3640

37-
override string toString() { result = "StorageAccount" }
41+
override string toString() { result = "StorageAccount[" + this.getName() + "]" }
3842
}
3943

4044
/**
@@ -63,7 +67,7 @@ module Storage {
6367
/**
6468
* Gets the encryption settings for the disk.
6569
*/
66-
DisksProperties::EncryptionSettings getEncryptionSettings() {
70+
DiskEncryption::EncryptionSettings getEncryptionSettings() {
6771
result = this.getProperties().getEncryptionSettings()
6872
}
6973

@@ -235,7 +239,7 @@ module Storage {
235239
/**
236240
* Converts the properties object to a string representation.
237241
*/
238-
string toString() { result = "StorageAccountsProperties" }
242+
override string toString() { result = "StorageAccountsProperties[" + storageAccounts.getName() + "]"}
239243
}
240244
}
241245

@@ -255,7 +259,7 @@ module Storage {
255259
/**
256260
* Gets the encryption settings for the disk.
257261
*/
258-
EncryptionSettings getEncryptionSettings() {
262+
Storage::DiskEncryption::EncryptionSettings getEncryptionSettings() {
259263
result = this.getProperty("encryption")
260264
}
261265

@@ -274,42 +278,9 @@ module Storage {
274278
/**
275279
* Converts the properties object to a string representation.
276280
*/
277-
string toString() { result = "DiskProperties" }
281+
override string toString() { result = "DiskProperties" }
278282
}
279283

280-
/**
281-
* Represents the encryption settings object for disks in Bicep.
282-
*/
283-
class EncryptionSettings extends Object {
284-
private Object encryptionSettings;
285-
286-
/**
287-
* Constructs an EncryptionSettings object for disks.
288-
*/
289-
EncryptionSettings() { this = encryptionSettings.getProperty("encryption") }
290-
291-
/**
292-
* Gets the type of encryption used for the disk.
293-
*/
294-
StringLiteral getType() { result = this.getProperty("type") }
295-
296-
/**
297-
* Gets whether encryption is enabled for the disk.
298-
*/
299-
boolean isEncryptionEnabled() { result = this.getProperty("enabled").(Boolean).getBool() }
300-
301-
/**
302-
* Gets the URI of the key vault key used for encryption.
303-
*/
304-
string getKeyVaultKeyUri() {
305-
result = this.getProperty("keyVaultKeyUri").(StringLiteral).getValue()
306-
}
307-
308-
/**
309-
* Converts the encryption settings object to a string representation.
310-
*/
311-
string toString() { result = "DiskEncryptionSettings" }
312-
}
313284
}
314285

315286
module DiskPoolProperties {
@@ -338,7 +309,7 @@ module Storage {
338309
/**
339310
* Converts the properties object to a string representation.
340311
*/
341-
string toString() { result = "DiskPoolProperties" }
312+
override string toString() { result = "DiskPoolProperties" }
342313
}
343314

344315
/**
@@ -368,4 +339,142 @@ module Storage {
368339
string toString() { result = "DiskRef" }
369340
}
370341
}
342+
343+
module DiskEncryption {
344+
345+
/**
346+
* Represents the encryption settings object for disks or storage accounts in Bicep.
347+
* Supports nested identity, key source, key vault properties, infrastructure encryption, and service-specific encryption.
348+
*/
349+
class EncryptionSettings extends Object {
350+
private ResourceProperties encryptionSettings;
351+
352+
/**
353+
* Constructs an EncryptionSettings object for disks or storage accounts.
354+
*/
355+
EncryptionSettings() { this = encryptionSettings.getProperty("encryption") }
356+
357+
/**
358+
* Gets the identity object for encryption.
359+
*/
360+
EncryptionIdentity getIdentity() { result = this.getProperty("identity") }
361+
362+
/**
363+
* Gets the key source for encryption (e.g., 'Microsoft.Storage', 'Microsoft.Keyvault').
364+
*/
365+
StringLiteral getKeySource() { result = this.getProperty("keySource") }
366+
367+
/**
368+
* Gets the key vault properties object for encryption.
369+
*/
370+
KeyVaultProperties getKeyVaultProperties() { result = this.getProperty("keyvaultproperties") }
371+
372+
/**
373+
* Gets whether infrastructure encryption is required.
374+
*/
375+
Boolean getRequireInfrastructureEncryption() { result = this.getProperty("requireInfrastructureEncryption") }
376+
377+
/**
378+
* Gets the services object for encryption (per-service settings).
379+
*/
380+
Services getServices() { result = this.getProperty("services") }
381+
382+
string toString() { result = "EncryptionSettings" }
383+
}
384+
385+
/**
386+
* Represents the identity object for encryption.
387+
*/
388+
class EncryptionIdentity extends Object {
389+
private EncryptionSettings settings;
390+
391+
EncryptionIdentity() { this = settings.getProperty("identity") }
392+
393+
/**
394+
* Gets the federated identity client ID.
395+
*/
396+
StringLiteral getFederatedIdentityClientId() { result = this.getProperty("federatedIdentityClientId") }
397+
398+
/**
399+
* Gets the user assigned identity.
400+
*/
401+
StringLiteral getUserAssignedIdentity() { result = this.getProperty("userAssignedIdentity") }
402+
}
403+
404+
/**
405+
* Represents the key vault properties object for encryption.
406+
*/
407+
class KeyVaultProperties extends Object {
408+
private EncryptionSettings settings;
409+
410+
KeyVaultProperties() { this = settings.getProperty("keyvaultproperties") }
411+
412+
/**
413+
* Gets the key name.
414+
*/
415+
StringLiteral getKeyName() { result = this.getProperty("keyname") }
416+
417+
/**
418+
* Gets the key vault URI.
419+
*/
420+
StringLiteral getKeyVaultUri() { result = this.getProperty("keyvaulturi") }
421+
422+
/**
423+
* Gets the key version.
424+
*/
425+
StringLiteral getKeyVersion() { result = this.getProperty("keyversion") }
426+
}
427+
428+
/**
429+
* Represents the services object for encryption (per-service settings).
430+
*/
431+
class Services extends Object {
432+
private EncryptionSettings settings;
433+
434+
Services() { this = settings.getProperty("services") }
435+
436+
/**
437+
* Gets the blob service encryption settings.
438+
*/
439+
ServiceEncryption getBlob() { result = this.getProperty("blob") }
440+
441+
/**
442+
* Gets the file service encryption settings.
443+
*/
444+
ServiceEncryption getFile() { result = this.getProperty("file") }
445+
446+
/**
447+
* Gets the queue service encryption settings.
448+
*/
449+
ServiceEncryption getQueue() { result = this.getProperty("queue") }
450+
451+
/**
452+
* Gets the table service encryption settings.
453+
*/
454+
ServiceEncryption getTable() { result = this.getProperty("table") }
455+
}
456+
457+
/**
458+
* Represents encryption settings for a specific service (blob, file, queue, table).
459+
*/
460+
class ServiceEncryption extends Object {
461+
private Services services;
462+
463+
/**
464+
* Characteristic predicate for ServiceEncryption. This class is constructed via property access in Services.
465+
*/
466+
ServiceEncryption() { this = this }
467+
468+
/**
469+
* Gets whether encryption is enabled for the service.
470+
*/
471+
Boolean getEnabled() { result = this.getProperty("enabled") }
472+
473+
/**
474+
* Gets the key type for the service encryption.
475+
*/
476+
StringLiteral getKeyType() { result = this.getProperty("keyType") }
477+
}
478+
479+
}
371480
}

0 commit comments

Comments
 (0)