Skip to content

Commit 0870408

Browse files
Learn Editor: Update defender-for-storage-infrastructure-as-code-enablement.md
1 parent 5423aa7 commit 0870408

File tree

1 file changed

+133
-16
lines changed

1 file changed

+133
-16
lines changed

articles/defender-for-cloud/defender-for-storage-infrastructure-as-code-enablement.md

Lines changed: 133 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ ms.author: v-bernsteina
77
ms.topic: how-to
88
---
99

10-
1110
# Enable and configure with Infrastructure as Code templates
1211

1312
We recommend that you enable Defender for Storage on the subscription level. Doing so ensures all storage accounts in the subscription will be protected, including future ones.
@@ -17,11 +16,47 @@ We recommend that you enable Defender for Storage on the subscription level. Doi
1716
1817
## [Enable on a subscription](#tab/enable-subscription/)
1918

19+
### Terraform template
20+
21+
To enable and configure Microsoft Defender for Storage at the subscription level using Terraform, you can use the following code snippet:
22+
23+
```json
24+
resource "azurerm_security_center_subscription_pricing" "DefenderForStorage" {
25+
tier = "Standard"
26+
resource_type = "StorageAccounts"
27+
subplan = "DefenderForStorageV2"
28+
29+
extension {
30+
name = "OnUploadMalwareScanning"
31+
additional_extension_properties = {
32+
CapGBPerMonthPerStorageAccount = "5000"
33+
}
34+
}
35+
36+
extension {
37+
name = "SensitiveDataDiscovery"
38+
}
39+
}
40+
```
41+
42+
**Modifying the monthly cap for malware scanning**
43+
To modify the monthly cap for malware scanning per storage account, adjust the `CapGBPerMonthPerStorageAccount` parameter to your preferred value. This parameter sets a cap on the maximum data that can be scanned for malware each month per storage account. If you want to permit unlimited scanning, assign the value "-1". The default limit is set at 5,000 GB.
44+
45+
**Disabling features**
46+
If you want to turn off the on-upload malware scanning or sensitive data threat detection features, you can remove the corresponding extension block from the Terraform code.
47+
48+
**Disabling the entire Defender for Storage plan**
49+
To disable the entire Defender for Storage plan, set the `tier` property value to **"Free"** and remove the **subPlan** and **extension** properties.
50+
51+
Learn more about the __azurerm_security_center_subscription_pricing__ resource by referring to the [azurerm_security_center_subscription_pricing documentation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/security_center_subscription_pricing). Additionally, you can find comprehensive details on the Terraform provider for Azure in the [Terraform AzureRM Provider documentation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs).
52+
2053
### Bicep template
2154

2255
To enable and configure Microsoft Defender for Storage at the subscription level using [Bicep](/azure/azure-resource-manager/bicep/overview?tabs=bicep), make sure your [target scope is set to subscription](/azure/azure-resource-manager/bicep/deploy-to-subscription?tabs=azure-cli#scope-to-subscription), and add the following to your Bicep template:
2356

24-
```
57+
58+
59+
```yaml
2560
resource StorageAccounts 'Microsoft.Security/pricings@2023-01-01' = {
2661
name: 'StorageAccounts'
2762
properties: {
@@ -44,19 +79,24 @@ resource StorageAccounts 'Microsoft.Security/pricings@2023-01-01' = {
4479
}
4580
```
4681

82+
**Modifying the monthly cap for malware scanning**
4783
To modify the monthly cap for malware scanning per storage account, adjust the `CapGBPerMonthPerStorageAccount` parameter to your preferred value. This parameter sets a cap on the maximum data that can be scanned for malware each month per storage account. If you want to permit unlimited scanning, assign the value -1. The default limit is set at 5,000 GB.
4884

49-
If you want to turn off the On-upload malware scanning or Sensitive data threat detection features, you can change the `isEnabled` value to **False** under Sensitive data discovery.
85+
**Disabling features**
86+
If you want to turn off the On-upload malware scanning or Sensitive data threat detection features, you can change the `isEnabled` value to **False** under **sensitive data discovery**.
5087

51-
To disable the entire Defender for Storage plan, set the `pricingTier` property value to **Free** and remove the subPlan and extensions properties.
88+
**Disabling the entire Defender for Storage plan**
89+
To disable the entire Defender for Storage plan, set the `pricingTier` property value to **Free** and remove the **subPlan** and **extensions** properties.
5290

5391
Learn more about the [Bicep template in the Microsoft security/pricings documentation](/azure/templates/microsoft.security/pricings?pivots=deployment-language-bicep&source=docs).
5492

5593
### Azure Resource Manager template
5694

5795
To enable and configure Microsoft Defender for Storage at the subscription level using an ARM (Azure Resource Manager) template, add this JSON snippet to the resources section of your ARM template:
5896

59-
```
97+
98+
99+
```json
60100
{
61101
"type": "Microsoft.Security/pricings",
62102
"apiVersion": "2023-01-01",
@@ -81,21 +121,89 @@ To enable and configure Microsoft Defender for Storage at the subscription level
81121
}
82122
```
83123

124+
**Modifying the monthly cap for malware scanning**
84125
To modify the monthly threshold for malware scanning in your storage accounts, simply adjust the `CapGBPerMonthPerStorageAccount` parameter to your preferred value. This parameter sets a cap on the maximum data that can be scanned for malware each month, per storage account. If you want to permit unlimited scanning, assign the value -1. The default limit is set at 5,000 GB.
85126

86-
If you want to turn off the on-upload malware scanning or Sensitive data threat detection features, you can change the `isEnabled` value to **False** under Sensitive data discovery.
127+
**Disabling features**
128+
If you want to turn off the on-upload malware scanning or sensitive data threat detection features, you can change the `isEnabled` value to **False** under **sensitive data discovery**.
87129

88-
To disable the entire Defender plan, set the `pricingTier` property value to **Free** and remove the subPlan and extensions properties.
130+
**Disabling the entire Defender for Storage plan**
131+
To disable the entire Defender plan, set the `pricingTier` property value to **Free** and remove the **subPlan** and **extensions** properties.
89132

90133
Learn more about the ARM template in the Microsoft.Security/Pricings documentation.
91134

92135
## [Enable on a storage account](#tab/enable-storage-account/)
93136

137+
### Terraform template - storage account
138+
139+
To enable and configure Microsoft Defender for Storage at the storage account level using Terraform, import the AzAPI provider and use the following code snippet:
140+
141+
142+
```javascript
143+
resource "azurerm_storage_account" "example" { ... }
144+
145+
resource "azapi_resource_action" "enable_defender_for_Storage" {
146+
type = "Microsoft.Security/defenderForStorageSettings@2022-12-01-preview"
147+
resource_id = "${azurerm_storage_account.example.id}/providers/Microsoft.Security/defenderForStorageSettings/current"
148+
method = "PUT"
149+
150+
body = jsonencode({
151+
properties = {
152+
isEnabled = true
153+
malwareScanning = {
154+
onUpload = {
155+
isEnabled = true
156+
capGBPerMonth = 5000
157+
}
158+
}
159+
sensitiveDataDiscovery = {
160+
isEnabled = true
161+
}
162+
overrideSubscriptionLevelSettings = true
163+
}
164+
})
165+
}
166+
```
167+
168+
> [!NOTE]
169+
> The **"azapi_resource_action"** used here is an action that is specific to the configuration of Microsoft Defender for Storage. It's different from the typical resource declarations in Terraform, and it's used to perform specific actions on the resource, such as enabling or disabling features.
170+
171+
**Modifying the monthly cap for malware scanning**
172+
To modify the monthly threshold for malware scanning in your storage accounts, simply adjust the `capGBPerMonth` parameter to your preferred value. This parameter sets a cap on the maximum data that can be scanned for malware each month, per storage account. If you want to permit unlimited scanning, assign the value "-1". The default limit is set at 5,000 GB.
173+
174+
**Disabling features**
175+
If you want to turn off the on-upload malware scanning or sensitive data threat detection features, you can change the `isEnabled` value to **False** under the **malwareScanning** or **sensitiveDataDiscovery** properties sections.
176+
177+
**Disabling the entire Defender for Storage plan**
178+
To enable and configure Microsoft Defender for Storage at the storage account level using Terraform, import the [AzAPI provider](https://registry.terraform.io/providers/Azure/azapi/latest/docs) and use the following code snippet:
179+
180+
181+
```javascript
182+
resource "azurerm_storage_account" "example" { ... }
183+
184+
resource "azapi_resource_action" "disable_defender_for_Storage" {
185+
type = "Microsoft.Security/defenderForStorageSettings@2022-12-01-preview"
186+
resource_id = "${azurerm_storage_account.example.id}/providers/Microsoft.Security/defenderForStorageSettings/current"
187+
method = "PUT"
188+
189+
body = jsonencode({
190+
properties = {
191+
isEnabled = true
192+
overrideSubscriptionLevelSettings = false
193+
}
194+
})
195+
}
196+
197+
```
198+
199+
You can change the value of `overrideSubscriptionLevelSettings` to **True** to disable Defender for Storage plan for the storage account under subscriptions with Defender for Storage enabled at the subscription level. If you want to keep some features enabled, you can modify the properties accordingly.
200+
Learn more about the __[Microsoft.Security/defenderForStorageSettings](/rest/api/defenderforcloud/defender-for-storage/create)__ API documentation for further customization and control over your storage account's security settings. Additionally, you can find comprehensive details on the Terraform provider for Azure in the [Terraform AzureRM Provider documentation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs).
201+
94202
### Bicep template - storage account
95203

96204
To enable and configure Microsoft Defender for Storage at the storage account level using Bicep, add the following to your Bicep template:
97205

98-
```
206+
```yaml
99207
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' ...
100208

101209
resource defenderForStorageSettings 'Microsoft.Security/DefenderForStorageSettings@2022-12-01-preview' = {
@@ -117,24 +225,29 @@ resource defenderForStorageSettings 'Microsoft.Security/DefenderForStorageSettin
117225
}
118226
```
119227

120-
To modify the monthly threshold for malware scanning in your storage accounts, simply adjust the capGBPerMonth parameter to your preferred value. This parameter sets a cap on the maximum data that can be scanned for malware each month, per storage account. If you want to permit unlimited scanning, assign the value -1. The default limit is set at 5,000 GB.
228+
**Modifying the monthly cap for malware scanning**
229+
To modify the monthly threshold for malware scanning in your storage accounts, simply adjust the `capGBPerMonth parameter` to your preferred value. This parameter sets a cap on the maximum data that can be scanned for malware each month, per storage account. If you want to permit unlimited scanning, assign the value -1. The default limit is set at 5,000 GB.
121230

122-
If you want to turn off the On-upload malware scanning or Sensitive data threat detection features, you can change the `isEnabled` value to **false** under the `malwareScanning` or `sensitiveDataDiscovery` properties sections.
231+
**Disabling features**
232+
If you want to turn off the On-upload malware scanning or sensitive data threat detection features, you can change the `isEnabled` value to **False** under the **malwareScanning** or **sensitiveDataDiscovery** properties sections.
123233

124-
To disable the entire Defender plan for the storage account, set the `isEnabled` property value to **false** and remove the `malwareScanning` and `sensitiveDataDiscovery` sections from the properties.
234+
**Disabling the entire Defender for Storage plan**
235+
To disable the entire Defender plan for the storage account, set the `isEnabled` property value to **False** and remove the **malwareScanning** and **sensitiveDataDiscovery** sections from the properties.
125236

126237
Learn more about the [Microsoft.Security/DefenderForStorageSettings API](/rest/api/defenderforcloud/defender-for-storage/create) documentation.
127238

128239
> [!TIP]
129240
> Malware Scanning can be configured to send scanning results to the following: <br> **Event Grid custom topic** - for near-real time automatic response based on every scanning result. Learn more how to [configure malware scanning to send scanning events to an Event Grid custom topic](/azure/storage/common/azure-defender-storage-configure?toc=%2Fazure%2Fdefender-for-cloud%2Ftoc.json&tabs=enable-storage-account#setting-up-event-grid-for-malware-scanning). <br> **Log Analytics workspace** - for storing every scan result in a centralized log repository for compliance and audit. Learn more how to [configure malware scanning to send scanning results to a Log Analytics workspace](/azure/storage/common/azure-defender-storage-configure?toc=%2Fazure%2Fdefender-for-cloud%2Ftoc.json&tabs=enable-storage-account#setting-up-logging-for-malware-scanning).
130241
131-
Learn more on how to set up response for malware scanning results.
242+
Learn more on how to [set up response for malware scanning results.](/azure/defender-for-cloud/defender-for-storage-configure-malware-scan)
132243

133244
### ARM template - storage account
134245

135246
To enable and configure Microsoft Defender for Storage at the storage account level using an ARM template, add this JSON snippet to the resources section of your ARM template:
136247

137-
```
248+
249+
250+
```json
138251
{
139252
"type": "Microsoft.Security/DefenderForStorageSettings",
140253
"apiVersion": "2022-12-01-preview",
@@ -155,12 +268,16 @@ To enable and configure Microsoft Defender for Storage at the storage account le
155268
"scope": "[resourceId('Microsoft.Storage/storageAccounts', parameters('StorageAccountName'))]"
156269
}
157270
```
271+
**Modifying the monthly cap for malware scanning**
272+
**Modifying the monthly cap for malware scanning**
158273

159-
To modify the monthly threshold for malware scanning in your storage accounts, simply adjust the capGBPerMonth parameter to your preferred value. This parameter sets a cap on the maximum data that can be scanned for malware each month, per storage account. If you want to permit unlimited scanning, assign the value -1. The default limit is set at 5,000 GB.
274+
To modify the monthly threshold for malware scanning in your storage accounts, simply adjust the capGBPerMonth parameter to your preferred value. This parameter sets a cap on the maximum data that can be scanned for malware each month, per storage account. If you want to permit unlimited scanning, assign the value "-1". The default limit is set at 5,000 GB.
160275

161-
If you want to turn off the On-upload malware scanning or Sensitive data threat detection features, you can change the isEnabled value to false under the malwareScanning or sensitiveDataDiscovery properties sections.
276+
**Disabling features**
277+
If you want to turn off the on-upload malware scanning or sensitive data threat detection features, you can change the `isEnabled` value to **False** under the **malwareScanning** or **sensitiveDataDiscovery** properties sections.
162278

163-
To disable the entire Defender plan for the storage account, set the isEnabled property value to false and remove the malwareScanning and sensitiveDataDiscovery sections from the properties.
279+
**Disabling the entire Defender for Storage plan**
280+
To disable the entire Defender plan for the storage account, set the `isEnabled` property value to **False** and remove the **malwareScanning** and **sensitiveDataDiscovery** sections from the properties.
164281

165282
---
166283

0 commit comments

Comments
 (0)