Skip to content

Commit 5729f59

Browse files
committed
feat(tf): Update PublicStorage and tests
1 parent e367146 commit 5729f59

4 files changed

Lines changed: 46 additions & 19 deletions

File tree

ql/lib/codeql/hcl/providers/Azure.qll

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,38 +109,54 @@ module Azure {
109109
*/
110110
override string getName() { result = this.getAttribute("name").(StringLiteral).getValue() }
111111

112+
Expr getAllowBlobPublicAccess() {
113+
this.getProvider().getSemanticVersion().maybeBefore("3.0.0") and
114+
result = this.getAttribute("allow_blob_public_access")
115+
}
116+
112117
/**
113118
* Get the `allow_blob_public_access` property of the storage account. Only available
114119
* for `azurerm` v2 and not v3 onwards.
115120
*
116121
* https://github.com/hashicorp/terraform-provider-azurerm/blob/main/CHANGELOG-v3.md
117122
*/
118-
boolean getAllowBlobPublicAccess() {
119-
this.getProvider().getSemanticVersion().maybeBefore("3.0.0") and
120-
result = this.getAttribute("allow_blob_public_access").(BooleanLiteral).getBool()
123+
boolean getAllowBlobPublicAccessValue() {
124+
result = this.getAllowBlobPublicAccess().(BooleanLiteral).getBool()
121125
or
122126
result = false
123127
}
124128

129+
Expr getEnableHttpsTrafficOnly() {
130+
result = this.getAttribute("enable_https_traffic_only")
131+
}
132+
125133
/**
126134
* Get the `public_network_access_enabled` property of the storage account.
127135
*/
128-
boolean getEnableHttpsTrafficOnly() {
129-
result = this.getAttribute("enable_https_traffic_only").(BooleanLiteral).getBool()
136+
boolean getEnableHttpsTrafficOnlyValue() {
137+
result = this.getEnableHttpsTrafficOnly().(BooleanLiteral).getBool()
138+
}
139+
140+
Expr getPublicNetworkAccess() {
141+
result = this.getAttribute("public_network_access_enabled")
130142
}
131143

132144
/**
133145
* Get the `public_network_access_enabled` property of the storage account.
134146
*/
135-
boolean getPublicNetworkAccess() {
136-
result = this.getAttribute("public_network_access_enabled").(BooleanLiteral).getBool()
147+
boolean getPublicNetworkAccessValue() {
148+
result = this.getPublicNetworkAccess().(BooleanLiteral).getBool()
149+
}
150+
151+
Expr getAllowNestedItemsToBePublic() {
152+
result = this.getAttribute("allow_nested_items_to_be_public")
137153
}
138154

139155
/**
140156
* Get the `allow_nested_items_to_be_public` property of the storage account.
141157
*/
142-
boolean getAllowNestedItemsToBePublic() {
143-
result = this.getAttribute("allow_nested_items_to_be_public").(BooleanLiteral).getBool()
158+
boolean getAllowNestedItemsToBePublicValue() {
159+
result = this.getPublicNetworkAccess().(BooleanLiteral).getBool()
144160
}
145161
}
146162

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
import iac
22

33
abstract class PublicStorage extends Expr {
4-
abstract string getName();
4+
abstract string getProvider();
55
}
66

77
/**
88
* Azure Public Storage.
99
*/
10-
class AzurePublicStorage extends Azure::AzureResource, PublicStorage {
10+
class AzurePublicStorage extends PublicStorage {
1111
AzurePublicStorage() {
1212
// Azure Storage Container
1313
exists(Azure::StorageContainer storage_container |
1414
storage_container.getContainerAccessType() = "blob" and
1515
storage_container.getProperty("publicAccess").(StringLiteral).getValue() = "blob"
16+
and
17+
this = storage_container.getProperty("publicAccess")
1618
)
1719
or
1820
// Azure Storage Accounts
1921
exists(Azure::StorageAccount storage_acount |
20-
// v2
21-
storage_acount.getAllowBlobPublicAccess() = true or
22-
// v3
23-
storage_acount.getPublicNetworkAccess() = true or
24-
storage_acount.getAllowNestedItemsToBePublic() = true
22+
(
23+
// v2
24+
storage_acount.getAllowBlobPublicAccessValue() = true and
25+
this = storage_acount.getAllowBlobPublicAccess()
26+
) or
27+
(
28+
// v3
29+
storage_acount.getAllowNestedItemsToBePublicValue() = true
30+
and
31+
this = storage_acount.getAllowNestedItemsToBePublic()
32+
)
2533
)
2634
}
2735

28-
override string getName() { result = this.getName() }
36+
override string getProvider() {
37+
result = "Azure"
38+
}
2939
}

ql/src/security/Terraform/Azure/ManagedDisk/PublicAccess.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ import codeql.hcl.security.PublicStorage
1717

1818
// https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk
1919
from AzurePublicStorage public_storage
20-
select public_storage, "Azure Storage is Public for '" + public_storage.getName() + "'"
20+
select public_storage, "Azure Storage is Public"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
| storage.tf:9:1:15:1 | resource azurerm_storage_container insecure | Azure Storage is Unencrypted for 'insecure' |
1+
| storage.tf:13:22:13:27 | blob | Azure Storage is Public |
2+
| storage.tf:26:37:26:40 | true | Azure Storage is Public |

0 commit comments

Comments
 (0)