File tree Expand file tree Collapse file tree
src/security/Terraform/Azure/ManagedDisk Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,8 +10,16 @@ private import codeql.hcl.AST
1010class Resource extends Block {
1111 Resource ( ) { this .hasType ( "resource" ) }
1212
13+ /**
14+ * Get the name of the resource.
15+ */
1316 string getName ( ) { result = this .getLabel ( 1 ) }
1417
18+ /**
19+ * Get the provider of the resource.
20+ */
21+ string getProvider ( ) { result = "Unknown Provider" }
22+
1523 /**
1624 * Returns the resource id.
1725 */
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ module Azure {
1010 */
1111 class AzureResource extends Resource , Block {
1212 AzureResource ( ) { this .getResourceType ( ) .regexpMatch ( "^azurerm.*" ) }
13+
14+ override string getProvider ( ) { result = "Azurerm" }
1315 }
1416
1517 /**
@@ -78,6 +80,11 @@ module Azure {
7880 class StorageContainer extends AzureResource {
7981 StorageContainer ( ) { this .getResourceType ( ) = "azurerm_storage_container" }
8082
83+ /**
84+ * Get the name of the storage container.
85+ */
86+ override string getName ( ) { result = this .getAttribute ( "name" ) .( StringLiteral ) .getValue ( ) }
87+
8188 string getContainerAccessType ( ) {
8289 result = this .getAttribute ( "container_access_type" ) .( StringLiteral ) .getValue ( )
8390 }
@@ -96,6 +103,11 @@ module Azure {
96103 class StorageAccount extends AzureResource {
97104 StorageAccount ( ) { this .getResourceType ( ) = "azurerm_storage_account" }
98105
106+ /**
107+ * Get the name of the storage account.
108+ */
109+ override string getName ( ) { result = this .getAttribute ( "name" ) .( StringLiteral ) .getValue ( ) }
110+
99111 boolean getEnableHttpsTrafficOnly ( ) {
100112 result = this .getAttribute ( "enable_https_traffic_only" ) .( BooleanLiteral ) .getBool ( )
101113 }
Original file line number Diff line number Diff line change 11import iac
22
3- abstract class PublicStorage extends Expr { }
3+ abstract class PublicStorage extends Expr {
4+ abstract string getName ( ) ;
5+ }
46
57/**
68 * Azure Public Storage.
79 */
8- class AzurePublicStorage extends PublicStorage {
10+ class AzurePublicStorage extends Azure :: AzureResource , PublicStorage {
911 AzurePublicStorage ( ) {
1012 // Azure Storage Container
1113 exists ( Azure:: StorageContainer storage_container |
@@ -19,4 +21,6 @@ class AzurePublicStorage extends PublicStorage {
1921 storage_acount .getAllowNestedItemsToBePublic ( ) = true
2022 )
2123 }
24+
25+ override string getName ( ) { result = this .getName ( ) }
2226}
Original file line number Diff line number Diff line change 1313 */
1414
1515import hcl
16+ import codeql.hcl.security.PublicStorage
1617
1718// https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk
18- from Azure:: StorageContainer managed_disk
19- where
20- managed_disk .getContainerAccessType ( ) = "blob" and
21- managed_disk .getProperty ( "publicAccess" ) .( StringLiteral ) .getValue ( ) = "blob"
22- select managed_disk , "Azure Storage is Unencrypted for '" + managed_disk .getName ( ) + "'"
19+ from AzurePublicStorage public_storage
20+ select public_storage , "Azure Storage is Public for '" + public_storage .getName ( ) + "'"
You can’t perform that action at this time.
0 commit comments