Skip to content

Commit 5ae3636

Browse files
committed
feat: Update Databases support
1 parent aceba46 commit 5ae3636

File tree

3 files changed

+176
-14
lines changed

3 files changed

+176
-14
lines changed

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

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,28 @@ module Databases {
1010
*/
1111
abstract string databaseType();
1212

13-
override string toString() {
14-
result = "DatabaseResource[" + this.databaseType() + "]"
13+
override string toString() { result = "DatabaseResource[" + this.databaseType() + "]" }
14+
15+
DatabaseProperties::Properties getProperties() { result = this.getProperty("properties") }
16+
17+
string version() {
18+
result = this.getProperties().getProperty("version").(StringLiteral).getValue()
19+
}
20+
21+
string sslEnforcement() {
22+
result = this.getProperties().getProperty("sslEnforcement").(StringLiteral).getValue()
23+
}
24+
25+
string infrastructureEncryption() {
26+
result = this.getProperties().getProperty("infrastructureEncryption").(StringLiteral).getValue()
27+
}
28+
29+
string minimalTlsVersion() {
30+
result = this.getProperties().getProperty("minimalTlsVersion").(StringLiteral).getValue()
31+
}
32+
33+
DatabaseProperties::StorageProfile getStorageProfile() {
34+
result = this.getProperties().getProperty("storageProfile")
1535
}
1636
}
1737

@@ -33,6 +53,19 @@ module Databases {
3353
}
3454

3555
override string databaseType() { result = "cosmosdb" }
56+
57+
string databaseAccountOfferType() {
58+
result =
59+
this.getProperties().getProperty("databaseAccountOfferType").(StringLiteral).getValue()
60+
}
61+
62+
boolean isEnableMultipleWriteLocations() {
63+
result = this.getProperties().getProperty("enableMultipleWriteLocations").(Boolean).getBool()
64+
}
65+
66+
DatabaseProperties::BackupPolicy getBackupPolicy() {
67+
result = this.getProperties().getProperty("backupPolicy")
68+
}
3669
}
3770

3871
/**
@@ -103,4 +136,56 @@ module Databases {
103136

104137
override string databaseType() { result = "arc-sql-managed-instance" }
105138
}
139+
140+
module DatabaseProperties {
141+
class Properties extends Object {
142+
private Resource resource;
143+
144+
Properties() { this = resource.getProperty("properties") }
145+
146+
Resource getResource() { result = resource }
147+
}
148+
149+
class Backup extends Object {
150+
private Properties properties;
151+
152+
Backup() { this = properties.getProperty("backup") }
153+
154+
string toString() { result = "Backup" }
155+
156+
string geoRedundantBackup() {
157+
result = this.getProperty("geoRedundantBackup").(StringLiteral).getValue()
158+
}
159+
}
160+
161+
class BackupPolicy extends Object {
162+
private Properties properties;
163+
164+
BackupPolicy() { this = properties.getProperty("backupPolicy") }
165+
166+
string toString() { result = "BackupPolicy" }
167+
168+
string getBackupPolicyType() { result = this.getProperty("type").(StringLiteral).getValue() }
169+
170+
Expr getBackupRetentionDays() { result = this.getProperty("backupRetentionDays") }
171+
172+
Expr getBackupStorageRedundancy() { result = this.getProperty("backupStorageRedundancy") }
173+
}
174+
175+
class StorageProfile extends Object {
176+
private Properties properties;
177+
178+
StorageProfile() { this = properties.getProperty("storageProfile") }
179+
180+
string toString() { result = "StorageProfile" }
181+
182+
int storageMB() {
183+
result = this.getProperty("storageMB").(Number).getValue()
184+
}
185+
186+
string autoGrow() {
187+
result = this.getProperty("autoGrow").(StringLiteral).getValue()
188+
}
189+
}
190+
}
106191
}
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
| app.bicep:2:1:9:1 | DatabaseResource[sql] |
2-
| app.bicep:12:1:18:1 | DatabaseResource[cosmosdb] |
3-
| app.bicep:21:1:29:1 | DatabaseResource[postgresql] |
4-
| app.bicep:32:1:40:1 | DatabaseResource[mysql] |
5-
| app.bicep:43:1:51:1 | DatabaseResource[mariadb] |
6-
| app.bicep:54:1:58:1 | DatabaseResource[datalakestore] |
7-
| app.bicep:61:1:71:1 | DatabaseResource[redis] |
8-
| app.bicep:74:1:83:1 | DatabaseResource[kusto] |
9-
| app.bicep:86:1:93:1 | DatabaseResource[arc-sql-managed-instance] |
1+
| app.bicep:2:1:8:1 | DatabaseResource[cosmosdb] |
2+
| app.bicep:11:1:30:1 | DatabaseResource[cosmosdb] |
3+
| app.bicep:33:1:42:1 | DatabaseResource[cosmosdb] |
4+
| app.bicep:45:1:58:1 | DatabaseResource[cosmosdb] |
5+
| app.bicep:62:1:69:1 | DatabaseResource[sql] |
6+
| app.bicep:72:1:78:1 | DatabaseResource[cosmosdb] |
7+
| app.bicep:81:1:95:1 | DatabaseResource[postgresql] |
8+
| app.bicep:98:1:111:1 | DatabaseResource[mysql] |
9+
| app.bicep:114:1:124:1 | DatabaseResource[mariadb] |
10+
| app.bicep:127:1:131:1 | DatabaseResource[datalakestore] |
11+
| app.bicep:134:1:144:1 | DatabaseResource[redis] |
12+
| app.bicep:147:1:156:1 | DatabaseResource[kusto] |
13+
| app.bicep:159:1:166:1 | DatabaseResource[arc-sql-managed-instance] |

ql/test/library-tests/frameworks/databases/app.bicep

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
1+
// Cosmos DB Account with default settings
2+
resource cosmosDbDefault 'Microsoft.DocumentDB/databaseAccounts@2022-03-15' = {
3+
name: 'cosmosdb-default'
4+
location: 'eastus'
5+
properties: {
6+
databaseAccountOfferType: 'Standard'
7+
}
8+
}
9+
10+
// Cosmos DB Account with geo-redundancy and multi-region write
11+
resource cosmosDbGeo 'Microsoft.DocumentDB/databaseAccounts@2022-03-15' = {
12+
name: 'cosmosdb-geo'
13+
location: 'eastus'
14+
properties: {
15+
databaseAccountOfferType: 'Standard'
16+
enableMultipleWriteLocations: true
17+
locations: [
18+
{
19+
locationName: 'eastus'
20+
failoverPriority: 0
21+
isZoneRedundant: false
22+
}
23+
{
24+
locationName: 'westus'
25+
failoverPriority: 1
26+
isZoneRedundant: true
27+
}
28+
]
29+
}
30+
}
31+
32+
// Cosmos DB Account with continuous backup
33+
resource cosmosDbContinuousBackup 'Microsoft.DocumentDB/databaseAccounts@2022-03-15' = {
34+
name: 'cosmosdb-continuous'
35+
location: 'eastus'
36+
properties: {
37+
databaseAccountOfferType: 'Standard'
38+
backupPolicy: {
39+
type: 'Continuous'
40+
}
41+
}
42+
}
43+
44+
// Cosmos DB Account with periodic backup and custom retention
45+
resource cosmosDbPeriodicBackup 'Microsoft.DocumentDB/databaseAccounts@2022-03-15' = {
46+
name: 'cosmosdb-periodic'
47+
location: 'eastus'
48+
properties: {
49+
databaseAccountOfferType: 'Standard'
50+
backupPolicy: {
51+
type: 'Periodic'
52+
periodicModeProperties: {
53+
backupIntervalInMinutes: 240
54+
backupRetentionIntervalInHours: 24
55+
}
56+
}
57+
}
58+
}
59+
60+
161
// Azure SQL Database
262
resource sqlDb 'Microsoft.Sql/servers@2022-02-01' = {
363
name: 'sqlserver1'
@@ -17,36 +77,49 @@ resource cosmosDb 'Microsoft.DocumentDB/databaseAccounts@2022-03-15' = {
1777
}
1878
}
1979

20-
// Azure Database for PostgreSQL
80+
// Azure Database for PostgreSQL with geo-redundant backup and high availability
2181
resource postgresqlDb 'Microsoft.DBforPostgreSQL/servers@2022-01-20' = {
2282
name: 'pgserver1'
2383
location: 'eastus'
2484
properties: {
2585
administratorLogin: 'pgadmin'
2686
administratorLoginPassword: 'P@ssw0rd!'
2787
version: '11'
88+
backup': {
89+
geoRedundantBackup: 'Enabled'
90+
}
91+
highAvailability: {
92+
mode: 'ZoneRedundant'
93+
}
2894
}
2995
}
3096
31-
// Azure Database for MySQL
97+
// Azure Database for MySQL with SSL enforcement and auto-grow
3298
resource mysqlDb 'Microsoft.DBforMySQL/servers@2022-01-20' = {
3399
name: 'mysqlserver1'
34100
location: 'eastus'
35101
properties: {
36102
administratorLogin: 'mysqladmin'
37103
administratorLoginPassword: 'P@ssw0rd!'
38104
version: '5.7'
105+
sslEnforcement: 'Enabled'
106+
storageProfile: {
107+
storageMB: 51200
108+
autoGrow: 'Enabled'
109+
}
39110
}
40111
}
41112
42-
// Azure Database for MariaDB
113+
// Azure Database for MariaDB with backup retention and geo-redundancy
43114
resource mariadbDb 'Microsoft.DBforMariaDB/servers@2018-06-01' = {
44115
name: 'mariadbserver1'
45116
location: 'eastus'
46117
properties: {
47118
administratorLogin: 'mariadbadmin'
48119
administratorLoginPassword: 'P@ssw0rd!'
49120
version: '10.2'
121+
backupRetentionDays: 14
122+
geoRedundantBackup: 'Enabled'
50123
}
51124
}
52125

0 commit comments

Comments
 (0)