Skip to content

Commit 6f0d58f

Browse files
committed
feat(queries): Add initial queries for Bicep
1 parent 0d36ebc commit 6f0d58f

File tree

10 files changed

+151
-0
lines changed

10 files changed

+151
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Azure Blob Container Public Access
2+
3+
When using a Bicep template to create a storage account, you can specify the public access level for the blob container. The default value is set to `None` which means that the container is private and can only be accessed by the storage account owner. The other options are `Blob` and `Container` which allow anonymous read access to the blob or container respectively.
4+
5+
## Examples
6+
7+
### Bad Example
8+
9+
```bicep
10+
resource containers 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
11+
name: 'insecure'
12+
properties: {
13+
publicAccess: 'Blob'
14+
}
15+
}
16+
```
17+
18+
### Good Example
19+
20+
```bicep
21+
resource containers 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
22+
name: 'secure'
23+
properties: {
24+
publicAccess: 'None'
25+
}
26+
}
27+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @name Azure Blob Container Public Access
3+
* @description Azure Blob Container Public Access
4+
* @kind problem
5+
* @problem.severity error
6+
* @security-severity 10.0
7+
* @precision high
8+
* @id bicep/azure/storage-publicly-accessible
9+
* @tags security
10+
* bicep
11+
* azure
12+
* storage
13+
*/
14+
15+
import bicep
16+
17+
from Storage::BlobServiceContainers container
18+
where container.getPublicAccess() = ["Blob", "Container"]
19+
select container, "Public Blob Container resource."
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Support for HTTP traffic
2+
3+
## Overview
4+
5+
Using HTTP for Azure Storage Accounts is insecure because HTTP transmits data in plaintext, making it vulnerable to interception and eavesdropping by malicious actors. This lack of encryption can expose sensitive information, such as authentication tokens, account keys, or data being transferred, to potential attacks like man-in-the-middle (MITM). Enforcing HTTPS ensures that data is encrypted in transit, providing a secure communication channel and protecting against unauthorized access or data breaches.
6+
7+
## Enforcing HTTPS
8+
9+
To enforce HTTPS for Azure Storage Accounts, you can either set the `supportsHttpsTrafficOnly` property to `true` in the Bicep template.
10+
11+
```bicep
12+
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' = {
13+
// ...
14+
properties: {
15+
supportsHttpsTrafficOnly: true
16+
// ...
17+
}
18+
}
19+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name Supports non-HTTPS traffic for storage accounts
3+
* @description Supports non-HTTPS traffic for storage accounts
4+
* @kind problem
5+
* @severity warning
6+
* @security-severity 9.0
7+
* @precision very-high
8+
* @id bicep/azure/storage-tls-disabled
9+
* @tags security
10+
* bicep
11+
* azure
12+
* storage
13+
*/
14+
15+
import bicep
16+
17+
from Storage::StorageAccountsProperties properties
18+
where properties.getSupportsHttpsTrafficOnly() = false
19+
select properties.getProperty("supportsHttpsTrafficOnly"),
20+
"Supports non-HTTPS traffic for storage accounts."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| storage.bicep:11:1:16:1 | ResourceDeclaration | Public Blob Container resource. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
security/Storage/PublicAccess.ql
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
// Secure
3+
resource containers 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
4+
name: 'secure'
5+
properties: {
6+
publicAccess: 'None'
7+
}
8+
}
9+
10+
// Insecure
11+
resource containers 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
12+
name: 'insecure'
13+
properties: {
14+
publicAccess: 'Blob'
15+
}
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| http-traffic.bicep:35:31:35:35 | false | Supports non-HTTPS traffic for storage accounts. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
security/Storage/SupportHttpTraffic.ql
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
param location string = resourceGroup().location
3+
param storageAccountName string = 'httpEnabledStorage'
4+
5+
// Secure
6+
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' = {
7+
name: storageAccountName
8+
location: location
9+
sku: {
10+
name: 'Standard_LRS'
11+
}
12+
kind: 'StorageV2'
13+
properties: {
14+
networkAcls: {
15+
bypass: 'AzureServices'
16+
defaultAction: 'Allow'
17+
ipRules: [
18+
{
19+
ipAddressOrRange: '0.0.0.0/0'
20+
}
21+
]
22+
}
23+
}
24+
}
25+
26+
// In-Secure
27+
resource storageAccount2 'Microsoft.Storage/storageAccounts@2021-06-01' = {
28+
name: storageAccountName
29+
location: location
30+
sku: {
31+
name: 'Standard_LRS'
32+
}
33+
kind: 'StorageV2'
34+
properties: {
35+
supportsHttpsTrafficOnly: false
36+
networkAcls: {
37+
bypass: 'AzureServices'
38+
defaultAction: 'Allow'
39+
ipRules: [
40+
{
41+
ipAddressOrRange: '0.0.0.0/0'
42+
}
43+
]
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)