Repository navigation
DSTA-683: add Defender for Storage target containers #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cc25597
DSTA-683: create Defender target account and containers
micjustus-nc b86b875
DSTA-683: improved naming and ddefaults and cleanup
micjustus-nc ba82049
DSTA-683: add private endpoint connectivity
micjustus-nc 313acc9
DSTA-683: fixup container key logic
micjustus-nc 4a31fa1
DSTA-683: fixup output object details
micjustus-nc 4b52a83
DSTA-683: format updates
micjustus-nc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,96 @@ | ||
| resource "azapi_resource" "defender_storage" { | ||
| for_each = local.defender_storage_accounts | ||
| locals { | ||
| defender_upload_storage_account_name = substr(replace("sa${var.app_short_name}${var.environment}defender", "/[^0-9a-z]/", ""), 0, 24) | ||
|
|
||
| defender_containers = [ | ||
| "clean-scans", | ||
| "quarantine-scans" | ||
| ] | ||
|
|
||
| defender_target_storage_accounts = { | ||
| (local.upload_storage_account_name) = azurerm_storage_account.upload.id | ||
| } | ||
| } | ||
|
|
||
| # Configure Defender for all trust upload storage accounts | ||
| # Use "update" to modify existing Defender for Storage settings rather than creating new ones | ||
| resource "azapi_update_resource" "defender_settings" { | ||
| for_each = local.defender_target_storage_accounts | ||
|
|
||
| type = "Microsoft.Security/defenderForStorageSettings@2026-01-01-preview" | ||
| name = "current" | ||
| parent_id = each.value | ||
| resource_id = "${each.value}/providers/Microsoft.Security/defenderForStorageSettings/current" | ||
|
|
||
| body = { | ||
| properties = { | ||
| isEnabled = var.scan_is_enabled | ||
| isEnabled = var.scan_is_enabled | ||
|
|
||
| # only provide if the storage accounts absolutely must have their own settings | ||
| overrideSubscriptionLevelSettings = var.override_subscription_settings_enabled | ||
| # only provide if the storage accounts absolutely must have their own settings | ||
| overrideSubscriptionLevelSettings = var.override_subscription_settings_enabled | ||
|
|
||
| malwareScanning = { | ||
| sensitiveDataDiscovery = { | ||
| isEnabled = var.sensitive_data_discovery_enabled && var.scan_is_enabled | ||
| } | ||
|
|
||
| malwareScanning = { | ||
| blobScanResultsOptions = "BlobIndexTags" | ||
| onUpload = { | ||
| isEnabled = var.malware_scanning_on_upload_enabled && var.scan_is_enabled | ||
| capGBPerMonth = var.malware_scanning_on_upload_cap_gb_per_month | ||
| } | ||
| } | ||
|
|
||
| sensitiveDataDiscovery = { | ||
| isEnabled = var.sensitive_data_discovery_enabled && var.scan_is_enabled | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| locals { | ||
| defender_storage_accounts = { | ||
| upload = azurerm_storage_account.upload.id | ||
| # for the incoming function that triggers a move from the upload container to the defender storage account containers | ||
| # we need to ensure that the defender storage accounts are properly configured and accessible | ||
| # Since Defender storage accounts are not publicly accessible, we don't need to worry about write-only | ||
| # permissions as we do with the client landing containers | ||
|
|
||
| resource "azurerm_storage_account" "defender_storage_account" { | ||
| name = local.defender_upload_storage_account_name | ||
| resource_group_name = azurerm_resource_group.deploy_resource_group.name | ||
| location = azurerm_resource_group.deploy_resource_group.location | ||
|
|
||
| account_tier = "Standard" | ||
| account_replication_type = "LRS" | ||
| account_kind = "StorageV2" | ||
|
|
||
| allow_nested_items_to_be_public = false | ||
| cross_tenant_replication_enabled = false | ||
| default_to_oauth_authentication = true | ||
| https_traffic_only_enabled = true | ||
| infrastructure_encryption_enabled = true | ||
| min_tls_version = "TLS1_2" | ||
|
|
||
| public_network_access_enabled = false | ||
|
micjustus-nc marked this conversation as resolved.
|
||
|
|
||
| # The intention for the storage account is to provide Shared Key access and also Entra ID authentication. | ||
| shared_access_key_enabled = true | ||
| } | ||
|
|
||
| resource "azurerm_storage_container" "defender_containers" { | ||
| for_each = toset(local.defender_containers) | ||
| name = each.key | ||
| storage_account_id = azurerm_storage_account.defender_storage_account.id | ||
| container_access_type = "private" | ||
| } | ||
|
|
||
| resource "azurerm_private_endpoint" "defender_storage_blob" { | ||
| provider = azurerm.hub | ||
| name = "${local.defender_upload_storage_account_name}-pep" | ||
| location = data.azurerm_resource_group.hub_private_endpoint.location | ||
| resource_group_name = data.azurerm_resource_group.hub_private_endpoint.name | ||
| subnet_id = data.azurerm_subnet.hub_private_endpoint.id | ||
|
|
||
| private_service_connection { | ||
| name = "${local.defender_upload_storage_account_name}-blob" | ||
| private_connection_resource_id = azurerm_storage_account.defender_storage_account.id | ||
| subresource_names = ["blob"] | ||
| is_manual_connection = false | ||
| } | ||
|
|
||
| private_dns_zone_group { | ||
| name = "${local.defender_upload_storage_account_name}-blob-dns" | ||
| private_dns_zone_ids = [data.azurerm_private_dns_zone.blob.id] | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| locals { | ||
| hub_private_endpoint_resource_group_name = "rg-hub-${var.hub}-uks-hub-private-endpoints" | ||
| hub_private_dns_zone_resource_group_name = "rg-hub-${var.hub}-uks-private-dns-zones" | ||
| hub_network_resource_group_name = "rg-hub-${var.hub}-uks-hub-networking" | ||
| hub_vnet_name = "VNET-${upper(var.hub)}-UKS-HUB" | ||
| hub_private_endpoint_subnet_name = "SN-${upper(var.hub)}-UKS-HUB-pep" | ||
| } | ||
|
|
||
| data "azurerm_resource_group" "hub_private_endpoint" { | ||
| provider = azurerm.hub | ||
| name = local.hub_private_endpoint_resource_group_name | ||
| } | ||
|
|
||
| data "azurerm_resource_group" "hub_private_dns_zones" { | ||
| provider = azurerm.hub | ||
| name = local.hub_private_dns_zone_resource_group_name | ||
| } | ||
|
|
||
| data "azurerm_resource_group" "hub_network" { | ||
| provider = azurerm.hub | ||
| name = local.hub_network_resource_group_name | ||
| } | ||
|
|
||
| data "azurerm_virtual_network" "hub" { | ||
| provider = azurerm.hub | ||
| name = local.hub_vnet_name | ||
| resource_group_name = data.azurerm_resource_group.hub_network.name | ||
| } | ||
|
|
||
| data "azurerm_subnet" "hub_private_endpoint" { | ||
| provider = azurerm.hub | ||
| name = local.hub_private_endpoint_subnet_name | ||
| virtual_network_name = data.azurerm_virtual_network.hub.name | ||
| resource_group_name = data.azurerm_resource_group.hub_network.name | ||
| } | ||
|
|
||
| data "azurerm_private_dns_zone" "blob" { | ||
| provider = azurerm.hub | ||
| name = var.storage_blob_private_dns_zone_name | ||
| resource_group_name = "rg-hub-${var.hub}-uks-private-dns-zones" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,26 @@ | ||
| output "upload_container_urls" { | ||
| value = { | ||
| locals { | ||
| upload_container_details = { | ||
| for container_key, container in azurerm_storage_container.bso : | ||
| container_key => "${azurerm_storage_account.upload.primary_blob_endpoint}${container.name}" | ||
| container_key => { | ||
| endpoint = container.id | ||
| storage_account_id = container.storage_account_id | ||
| } | ||
| } | ||
|
|
||
| upload_container_urls = { | ||
| for container_key, container in local.upload_container_details : | ||
| container_key => container.endpoint | ||
| } | ||
| } | ||
|
|
||
| output "upload_container_urls" { | ||
| value = local.upload_container_urls | ||
|
micjustus-nc marked this conversation as resolved.
|
||
| } | ||
|
|
||
| output "defender_storage_account_id" { | ||
| value = azurerm_storage_account.defender_storage_account.id | ||
| } | ||
|
|
||
| output "defender_storage_private_endpoint_id" { | ||
| value = azurerm_private_endpoint.defender_storage_blob.id | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.