Skip to content

Commit 23eafa1

Browse files
committed
feat: Add Network ACL support
1 parent f8665ef commit 23eafa1

File tree

5 files changed

+94
-8
lines changed

5 files changed

+94
-8
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
private import bicep
22
private import codeql.bicep.Concepts
3+
private import Network
34

45
module KeyVault {
56
class VaultResource extends Resource {
@@ -16,6 +17,10 @@ module KeyVault {
1617
result = this.getProperties().getAccessPolicies()
1718
}
1819

20+
Network::NetworkAcl getNetworkAcls() {
21+
result = this.getProperties().getNetworkAcls()
22+
}
23+
1924
override string toString() { result = "Key Vault Resource" }
2025
}
2126

@@ -93,6 +98,10 @@ module KeyVault {
9398

9499
string publicNetworkAccess() { result = this.getPublicNetworkAccess().getValue() }
95100

101+
Network::NetworkAcl getNetworkAcls() {
102+
result = this.getProperty("networkAcls")
103+
}
104+
96105
AccessPolicy getAccessPolicies() {
97106
result = this.getProperty("accessPolicies").(Array).getElements()
98107
}

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,62 @@ module Network {
112112
}
113113
}
114114

115+
116+
class NetworkAcl extends Object {
117+
private Resource resource;
118+
119+
NetworkAcl() {
120+
exists(Object props |
121+
props = resource.getProperty("properties") and
122+
this = props.getProperty(["networkAcl", "networkAcls"])
123+
)
124+
}
125+
126+
Resource getResource() { result = resource }
127+
128+
StringLiteral getBypass() {
129+
result = this.getProperty("bypass")
130+
}
131+
132+
string bypass() {
133+
result = this.getBypass().getValue()
134+
}
135+
136+
StringLiteral getDefaultAction() {
137+
result = this.getProperty("defaultAction")
138+
}
139+
140+
string defaultAction() {
141+
result = this.getDefaultAction().getValue()
142+
}
143+
144+
IpRule getIpRules() {
145+
result = this.getProperty("ipRules").(Array).getElements()
146+
}
147+
148+
string toString() {
149+
result = "Network ACL"
150+
}
151+
}
152+
153+
class IpRule extends Object {
154+
private NetworkAcl acl;
155+
156+
IpRule() {
157+
this = acl.getProperty("ipRules").(Array).getElements()
158+
}
159+
160+
NetworkAcl getNetworkAcl() { result = acl }
161+
162+
StringLiteral getValue() {
163+
result = this.getProperty("value")
164+
}
165+
166+
string toString() {
167+
result = "IP Rule"
168+
}
169+
}
170+
115171
module VirtualNetworkProperties {
116172
/**
117173
* The properties object for the Microsoft.Network/virtualNetworks/subnets type.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
keyvault
2-
| app.bicep:1:1:37:1 | Key Vault Resource |
2+
| app.bicep:1:1:51:1 | Key Vault Resource |
33
keyvaultPolicies
4-
| app.bicep:1:1:37:1 | Key Vault Resource | app.bicep:11:7:19:7 | AccessPolicy |
5-
| app.bicep:1:1:37:1 | Key Vault Resource | app.bicep:20:7:28:7 | AccessPolicy |
4+
| app.bicep:1:1:51:1 | Key Vault Resource | app.bicep:11:7:19:7 | AccessPolicy |
5+
| app.bicep:1:1:51:1 | Key Vault Resource | app.bicep:20:7:28:7 | AccessPolicy |
6+
keyvaultNetworkAcls
7+
| app.bicep:1:1:51:1 | Key Vault Resource | app.bicep:36:18:49:5 | Network ACL |
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import bicep
22

3-
query predicate keyvault(KeyVault::VaultResource vault) {
4-
any()
5-
}
3+
query predicate keyvault(KeyVault::VaultResource vault) { any() }
64

7-
query predicate keyvaultPolicies(KeyVault::VaultResource vault, KeyVault::KeyVaultProperties::AccessPolicy policy) {
5+
query predicate keyvaultPolicies(
6+
KeyVault::VaultResource vault, KeyVault::KeyVaultProperties::AccessPolicy policy
7+
) {
88
policy = vault.getAccessPolicies()
9-
9+
}
10+
11+
query predicate keyvaultNetworkAcls(
12+
KeyVault::VaultResource vault, Network::NetworkAcl networkAcl
13+
) {
14+
networkAcl = vault.getNetworkAcls()
1015
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,19 @@ resource keyVault 'Microsoft.KeyVault/vaults@2021-06-01-preview' = {
3333
enableSoftDelete: true
3434
enablePurgeProtection: true
3535
publicNetworkAccess: 'Disabled' // Recommended: restrict public access
36+
networkAcls: {
37+
bypass: 'AzureServices'
38+
defaultAction: 'Deny'
39+
ipRules: [
40+
{
41+
value: '203.0.113.0/24'
42+
}
43+
]
44+
virtualNetworkRules: [
45+
{
46+
id: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myrg/providers/Microsoft.Network/virtualNetworks/myvnet/subnets/mysubnet'
47+
}
48+
]
49+
}
3650
}
3751
}

0 commit comments

Comments
 (0)