-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabases.qll
More file actions
386 lines (331 loc) · 11.3 KB
/
Databases.qll
File metadata and controls
386 lines (331 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
private import bicep
private import codeql.bicep.Concepts
module Databases {
/**
* Base class for all database resources in Azure.
* Provides common properties and methods for Azure database resources.
*/
abstract class DatabaseResource extends AzureResource {
/**
* Returns the type of the database resource (e.g., sql, postgresql, etc).
*/
abstract string databaseType();
/**
* Returns a string representation of the database resource.
*/
override string toString() { result = "DatabaseResource[" + this.databaseType() + "]" }
/**
* Returns the properties object for the database resource.
*/
DatabaseProperties::Properties getProperties() { result = this.getProperty("properties") }
/**
* Returns the version property as a StringLiteral, if present.
*/
StringLiteral getVersion() {
result = this.getProperties().getProperty("version")
}
/**
* Returns the version property of the database resource, if present.
*/
string version() {
result = this.getVersion().getValue()
}
/**
* Returns the publicNetworkAccess property as a StringLiteral, if present.
*/
StringLiteral getPublicNetworkAccess() {
result = this.getProperties().getProperty("publicNetworkAccess")
}
/**
* Returns the value of the publicNetworkAccess property, if present.
*/
string publicNetworkAccess() {
result = this.getPublicNetworkAccess().getValue()
}
/**
* Returns the sslEnforcement property as a StringLiteral, if present.
*/
StringLiteral getSslEnforcement() {
result = this.getProperties().getProperty("sslEnforcement")
}
/**
* Returns the sslEnforcement property of the database resource, if present.
*/
string sslEnforcement() {
result = this.getSslEnforcement().getValue()
}
/**
* Returns the infrastructureEncryption property of the database resource, if present.
*/
string infrastructureEncryption() {
result = this.getProperties().getProperty("infrastructureEncryption").(StringLiteral).getValue()
}
/**
* Returns the minimalTlsVersion property as a StringLiteral, if present.
*/
StringLiteral getMinimalTlsVersion() {
result = this.getProperties().getProperty("minimalTlsVersion")
}
/**
* Returns the minimalTlsVersion property of the database resource, if present.
*/
string minimalTlsVersion() {
result = this.getMinimalTlsVersion().getValue()
}
/**
* Returns the storage profile for the database resource, if present.
*/
DatabaseProperties::StorageProfile getStorageProfile() {
result = this.getProperties().getProperty("storageProfile")
}
}
/**
* Represents an Azure SQL Database or Managed Instance resource.
*/
class SqlServers extends DatabaseResource, Resource {
/**
* Constructs an instance for Azure SQL Database/Managed Instance resources.
*/
SqlServers() { this.getResourceType().regexpMatch("^Microsoft.Sql/servers@.*") }
/**
* Returns the type of the database resource ("sql").
*/
override string databaseType() { result = "sql" }
}
/**
* Represents an Azure Cosmos DB account resource.
*/
class CosmosDBAccounts extends DatabaseResource, Resource {
/**
* Constructs an instance for Azure Cosmos DB account resources.
*/
CosmosDBAccounts() {
this.getResourceType().regexpMatch("^Microsoft.DocumentDB/databaseAccounts@.*")
}
/**
* Returns the type of the database resource ("cosmosdb").
*/
override string databaseType() { result = "cosmosdb" }
/**
* Returns the databaseAccountOfferType property of the Cosmos DB account.
*/
string databaseAccountOfferType() {
result =
this.getProperties().getProperty("databaseAccountOfferType").(StringLiteral).getValue()
}
/**
* Returns true if multiple write locations are enabled for the Cosmos DB account.
*/
boolean isEnableMultipleWriteLocations() {
result = this.getProperties().getProperty("enableMultipleWriteLocations").(Boolean).getBool()
}
/**
* Returns the backup policy for the Cosmos DB account.
*/
DatabaseProperties::BackupPolicy getBackupPolicy() {
result = this.getProperties().getProperty("backupPolicy")
}
}
/**
* Represents an Azure Database for PostgreSQL server resource.
*/
class PostgreSQLServers extends DatabaseResource, Resource {
/**
* Constructs an instance for Azure Database for PostgreSQL server resources.
*/
PostgreSQLServers() {
this.getResourceType().regexpMatch("^Microsoft.DBforPostgreSQL/servers@.*")
}
/**
* Returns the type of the database resource ("postgresql").
*/
override string databaseType() { result = "postgresql" }
}
/**
* Represents an Azure Database for MySQL server resource.
*/
class MySQLServers extends DatabaseResource, Resource {
/**
* Constructs an instance for Azure Database for MySQL server resources.
*/
MySQLServers() { this.getResourceType().regexpMatch("^Microsoft.DBforMySQL/servers@.*") }
/**
* Returns the type of the database resource ("mysql").
*/
override string databaseType() { result = "mysql" }
}
/**
* Represents an Azure Database for MariaDB server resource.
*/
class MariaDBServers extends DatabaseResource, Resource {
/**
* Constructs an instance for Azure Database for MariaDB server resources.
*/
MariaDBServers() { this.getResourceType().regexpMatch("^Microsoft.DBforMariaDB/servers@.*") }
/**
* Returns the type of the database resource ("mariadb").
*/
override string databaseType() { result = "mariadb" }
}
/**
* Represents an Azure Data Lake Store Gen1 account resource.
*/
class DataLakeStoreAccounts extends DatabaseResource, Resource {
/**
* Constructs an instance for Azure Data Lake Store Gen1 account resources.
*/
DataLakeStoreAccounts() {
this.getResourceType().regexpMatch("^Microsoft.DataLakeStore/accounts@.*")
}
/**
* Returns the type of the database resource ("datalakestore").
*/
override string databaseType() { result = "datalakestore" }
}
/**
* Represents an Azure Data Explorer (Kusto) cluster resource.
*/
class KustoClusters extends DatabaseResource, Resource {
/**
* Constructs an instance for Azure Data Explorer (Kusto) cluster resources.
*/
KustoClusters() { this.getResourceType().regexpMatch("^Microsoft.Kusto/Clusters@.*") }
/**
* Returns the type of the database resource ("kusto").
*/
override string databaseType() { result = "kusto" }
}
/**
* Represents an Azure Arc-enabled SQL Managed Instance resource.
*/
class ArcSqlManagedInstances extends DatabaseResource, Resource {
/**
* Constructs an instance for Azure Arc-enabled SQL Managed Instance resources.
*/
ArcSqlManagedInstances() {
this.getResourceType().regexpMatch("^Microsoft.AzureArcData/sqlManagedInstances@.*")
}
/**
* Returns the type of the database resource ("arc-sql-managed-instance").
*/
override string databaseType() { result = "arc-sql-managed-instance" }
}
private class PublicDatabaseResource extends PublicResource {
private DatabaseResource database;
/**
* Constructs a PublicDatabaseResource if the database has public network access enabled.
*/
PublicDatabaseResource() {
database.publicNetworkAccess() = "Enabled" and
this = database
}
/**
* Returns the property that indicates public access for the database resource.
*/
override Expr getPublicAccessProperty() {
result = database.getProperties().getProperty("publicNetworkAccess")
}
}
/**
* Represents a database resource with a weak TLS version configuration.
*/
private class WeakDatabaseTlsVersion extends Cryptography::WeakTlsVersion instanceof DatabaseResource {
/**
* Returns the minimalTlsVersion property as a StringLiteral for weak TLS version detection.
*/
override StringLiteral getWeakTlsVersionProperty() {
result = DatabaseResource.super.getProperties().getProperty("minimalTlsVersion")
}
}
module DatabaseProperties {
/**
* Represents the properties object for a database resource.
*/
class Properties extends ResourceProperties {
private DatabaseResource resource;
/**
* Constructs a Properties object for the given resource.
*/
Properties() { this = resource.getProperty("properties") }
/**
* Returns the underlying resource for these properties.
*/
Resource getResource() { result = resource }
override string toString() {
result = "DatabaseProperties[" + resource.databaseType() + "]"
}
}
/**
* Represents the backup object within database properties.
*/
class Backup extends Object {
private Properties properties;
/**
* Constructs a Backup object for the given properties.
*/
Backup() { this = properties.getProperty("backup") }
/**
* Returns a string representation of the backup object.
*/
string toString() { result = "Backup" }
/**
* Returns the geoRedundantBackup property of the backup object.
*/
string geoRedundantBackup() {
result = this.getProperty("geoRedundantBackup").(StringLiteral).getValue()
}
}
/**
* Represents the backup policy object within database properties.
*/
class BackupPolicy extends Object {
private Properties properties;
/**
* Constructs a BackupPolicy object for the given properties.
*/
BackupPolicy() { this = properties.getProperty("backupPolicy") }
/**
* Returns a string representation of the backup policy object.
*/
string toString() { result = "BackupPolicy" }
/**
* Returns the type of the backup policy.
*/
string getBackupPolicyType() { result = this.getProperty("type").(StringLiteral).getValue() }
/**
* Returns the backupRetentionDays property of the backup policy.
*/
Expr getBackupRetentionDays() { result = this.getProperty("backupRetentionDays") }
/**
* Returns the backupStorageRedundancy property of the backup policy.
*/
Expr getBackupStorageRedundancy() { result = this.getProperty("backupStorageRedundancy") }
}
/**
* Represents the storage profile object within database properties.
*/
class StorageProfile extends Object {
private Properties properties;
/**
* Constructs a StorageProfile object for the given properties.
*/
StorageProfile() { this = properties.getProperty("storageProfile") }
/**
* Returns a string representation of the storage profile object.
*/
string toString() { result = "StorageProfile" }
/**
* Returns the storageMB property of the storage profile.
*/
int storageMB() {
result = this.getProperty("storageMB").(Number).getValue()
}
/**
* Returns the autoGrow property of the storage profile.
*/
string autoGrow() {
result = this.getProperty("autoGrow").(StringLiteral).getValue()
}
}
}
}