Skip to content

Commit c3e4525

Browse files
committed
feat: Impove storage
1 parent 44f4ab1 commit c3e4525

File tree

1 file changed

+79
-3
lines changed

1 file changed

+79
-3
lines changed

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

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,102 @@ private import bicep
33
module Storage {
44
/**
55
* Represents a resource of type Microsoft.Storage/storageAccounts in Bicep.
6+
* Provides access to storage account properties, kind, network ACLs, and SKU.
67
* See: https://learn.microsoft.com/en-us/azure/templates/microsoft.storage/storageaccounts
78
*/
89
class StorageAccounts extends Resource {
10+
/**
11+
* Constructs a StorageAccounts resource.
12+
*/
913
StorageAccounts() {
1014
this.getResourceType().regexpMatch("^Microsoft.Storage/storageAccounts@.*")
1115
}
1216

17+
/**
18+
* Gets the properties object for the storage account.
19+
*/
1320
StorageAccountProperies::Properties getProperties() { result = this.getProperty("properties") }
1421

22+
/**
23+
* Gets the kind of the storage account (e.g., StorageV2, BlobStorage).
24+
*/
1525
StringLiteral getKind() { result = this.getProperty("kind") }
1626

27+
/**
28+
* Gets the network ACLs for the storage account.
29+
*/
1730
Network::NetworkAcl getNetworkAcls() { result = this.getProperties().getNetworkAcls() }
1831

32+
/**
33+
* Gets the SKU for the storage account.
34+
*/
1935
Sku getSku() { result = this.getProperty("sku") }
2036

2137
override string toString() { result = "StorageAccount" }
2238
}
2339

2440
/**
2541
* Represents a resource of type Microsoft.Compute/disks in Bicep.
42+
* Provides access to disk pools and disk properties.
2643
* See: https://learn.microsoft.com/en-us/azure/templates/microsoft.compute/disks
2744
*/
2845
class Disks extends Resource {
46+
/**
47+
* Constructs a Disks resource.
48+
*/
2949
Disks() { this.getResourceType().regexpMatch("^Microsoft.Compute/disks@.*") }
3050

51+
DisksProperties::Properties getProperties() { result = this.getProperty("properties") }
52+
53+
StringLiteral getZones() {
54+
result = this.getProperty("zones").(Array).getElements()
55+
}
56+
57+
DisksProperties::EncryptionSettings getEncryptionSettings() {
58+
result = this.getProperties().getEncryptionSettings()
59+
}
60+
61+
/**
62+
* Gets the disk pools that this disk is attached to.
63+
*/
3164
DiskPools getDiskPools() { exists(DiskPools pools | pools.getDisks() = this | result = pools) }
3265

3366
override string toString() { result = "Disks" }
3467
}
3568

69+
private class PublicDisks extends PublicResource {
70+
private StorageAccounts accounts;
71+
72+
PublicDisks() {
73+
accounts.getProperties().allowBlobPublicAccess() = true
74+
and
75+
this = accounts
76+
}
77+
78+
override Expr getPublicAccessProperty() {
79+
result = accounts.getProperties().getAllowBlobPublicAccess()
80+
}
81+
}
82+
83+
/**
84+
* Represents a resource of type Microsoft.StoragePool/diskPools in Bicep.
85+
* Provides access to disk pool properties, attached disks, and SKU.
86+
* See: https://learn.microsoft.com/en-us/azure/templates/microsoft.storagepool/diskpools
87+
*/
3688
class DiskPools extends Resource {
89+
/**
90+
* Constructs a DiskPools resource.
91+
*/
3792
DiskPools() { this.getResourceType().regexpMatch("^Microsoft.StoragePool/diskPools@.*") }
3893

94+
/**
95+
* Gets the properties object for the disk pool.
96+
*/
3997
DiskPoolProperties::Properties getProperties() { result = this.getProperty("properties") }
4098

99+
/**
100+
* Gets the disks attached to this disk pool.
101+
*/
41102
Disks getDisks() {
42103
exists(DiskPoolProperties::DiskRef refs, Disks disks |
43104
refs = this.getProperties().getDisksRef() and
@@ -47,23 +108,36 @@ module Storage {
47108
)
48109
}
49110

111+
/**
112+
* Gets the SKU for the disk pool.
113+
*/
50114
Sku getSku() { result = this.getProperty("sku") }
51115

52116
override string toString() { result = "DiskPools" }
53117
}
54118

55119
/**
56120
* Represents a resource of type Microsoft.Storage/storageAccounts/blobServices/containers in Bicep.
121+
* Provides access to container properties and public access settings.
57122
* See: https://learn.microsoft.com/en-us/azure/templates/microsoft.storage/storageaccounts/blobservices/containers
58123
*/
59124
class BlobServiceContainers extends Resource {
125+
/**
126+
* Constructs a BlobServiceContainers resource.
127+
*/
60128
BlobServiceContainers() {
61129
this.getResourceType()
62130
.regexpMatch("^Microsoft.Storage/storageAccounts/blobServices/containers@.*")
63131
}
64132

133+
/**
134+
* Gets the properties object for the blob service container.
135+
*/
65136
Object getProperties() { result = this.getProperty("properties") }
66137

138+
/**
139+
* Gets the public access setting for the container.
140+
*/
67141
string getPublicAccess() {
68142
result = this.getProperties().getProperty("publicAccess").(StringLiteral).getValue()
69143
}
@@ -122,20 +196,22 @@ module Storage {
122196
Properties() { this = disks.getProperty("properties") }
123197

124198
EncryptionSettings getEncryptionSettings() {
125-
result = this.getProperty("encryptionSettingsCollection")
199+
result = this.getProperty("encryption")
126200
}
127201

128202
boolean getEncryptionEnabled() {
129203
result = this.getEncryptionSettings().getProperty("enabled").(Boolean).getBool()
130204
}
131205

132206
Number getDiskSizeGB() { result = this.getProperty("diskSizeGB") }
207+
208+
string toString() { result = "DiskProperties" }
133209
}
134210

135-
class EncryptionSettings extends Properties {
211+
class EncryptionSettings extends Object {
136212
private Object encryptionSettings;
137213

138-
EncryptionSettings() { this = encryptionSettings.getProperty("encryptionSettings") }
214+
EncryptionSettings() { this = encryptionSettings.getProperty("encryption") }
139215

140216
StringLiteral getType() { result = this.getProperty("type") }
141217

0 commit comments

Comments
 (0)