# forensic-workstation / azure / t0 "Quick start" # # An analysis machine in a network of its own: no public IP, no peering, no # route to the internet, reached only through Azure Bastion in the portal, and # able to read one evidence storage account and nothing else. # # Change the two values below, then: # az login # export ARM_SUBSCRIPTION_ID=$(az account show --query id -o tsv) # terraform init && terraform apply # # Connect: in the portal, open the virtual machine, choose Connect, then # Bastion, and sign in with the SSH key. # # Verify, on the machine. The first command fails; the last lists the # evidence, using the machine's own identity: # curl -m 5 https://example.com # TOKEN=$(curl -s -H Metadata:true "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://storage.azure.com/" | python3 -c 'import json,sys; print(json.load(sys.stdin)["access_token"])') # curl -s -H "Authorization: Bearer $TOKEN" -H "x-ms-version: 2021-08-06" "https://.blob.core.windows.net/?restype=container&comp=list" locals { evidence_storage_account_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-evidence/providers/Microsoft.Storage/storageAccounts/evidence" # change me analyst_ssh_public_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAVLSNVHxwTkfF6QlOHKLaAYXoPNlChUBMMleVjJvDyi replace-me" # change me: your key; nobody has this one location = "eastus2" # Bastion Developer is offered in some regions only; keep the evidence account in this region tags = { owner = "security-engineering" environment = "prod" data_classification = "restricted" managed_by = "terraform" } } terraform { required_version = ">= 1.6" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 5.0" } } } provider "azurerm" { features {} } resource "azurerm_resource_group" "forensics" { name = "rg-forensics" location = local.location tags = local.tags } resource "azurerm_virtual_network" "forensics" { name = "vnet-forensics" location = azurerm_resource_group.forensics.location resource_group_name = azurerm_resource_group.forensics.name address_space = ["10.99.0.0/24"] tags = local.tags } # No implicit route to the internet for machines in this subnet. The storage # service endpoint carries evidence reads over Azure's network. resource "azurerm_subnet" "analysis" { name = "analysis" resource_group_name = azurerm_resource_group.forensics.name virtual_network_name = azurerm_virtual_network.forensics.name address_prefixes = ["10.99.0.0/26"] default_outbound_access_enabled = false service_endpoint { service = "Microsoft.Storage" } } # Outbound: Azure Storage in this region, for the evidence, and nothing else. resource "azurerm_network_security_group" "analysis" { name = "nsg-forensics" location = azurerm_resource_group.forensics.location resource_group_name = azurerm_resource_group.forensics.name tags = local.tags } resource "azurerm_network_security_rule" "to_storage" { name = "out-storage" network_security_group_name = azurerm_network_security_group.analysis.name resource_group_name = azurerm_resource_group.forensics.name priority = 100 direction = "Outbound" access = "Allow" protocol = "Tcp" source_port_range = "*" destination_port_range = "443" source_address_prefix = "*" destination_address_prefix = "Storage.${local.location}" } resource "azurerm_network_security_rule" "no_internet" { name = "out-deny-internet" network_security_group_name = azurerm_network_security_group.analysis.name resource_group_name = azurerm_resource_group.forensics.name priority = 4000 direction = "Outbound" access = "Deny" protocol = "*" source_port_range = "*" destination_port_range = "*" source_address_prefix = "*" destination_address_prefix = "Internet" } resource "azurerm_subnet_network_security_group_association" "analysis" { subnet_id = azurerm_subnet.analysis.id network_security_group_id = azurerm_network_security_group.analysis.id } # Developer Bastion is free and needs no subnet of its own. It connects from # the portal only. resource "azurerm_bastion_host" "forensics" { name = "bastion-forensics" location = azurerm_resource_group.forensics.location resource_group_name = azurerm_resource_group.forensics.name sku = "Developer" virtual_network_id = azurerm_virtual_network.forensics.id tags = local.tags } resource "azurerm_network_interface" "workstation" { name = "nic-forensic-workstation" location = azurerm_resource_group.forensics.location resource_group_name = azurerm_resource_group.forensics.name tags = local.tags ip_configuration { name = "internal" subnet_id = azurerm_subnet.analysis.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_linux_virtual_machine" "workstation" { name = "forensic-workstation" location = azurerm_resource_group.forensics.location resource_group_name = azurerm_resource_group.forensics.name size = "Standard_D4s_v5" admin_username = "analyst" disable_password_authentication = true allow_extension_operations = false network_interface_ids = [azurerm_network_interface.workstation.id] tags = local.tags admin_ssh_key { username = "analyst" public_key = local.analyst_ssh_public_key } os_disk { caching = "ReadWrite" storage_account_type = "Premium_LRS" disk_size_gb = 256 } source_image_reference { publisher = "Canonical" offer = "ubuntu-24_04-lts" sku = "server" version = "latest" } identity { type = "SystemAssigned" } lifecycle { precondition { condition = !endswith(local.analyst_ssh_public_key, "replace-me") error_message = "Set analyst_ssh_public_key to your own public key." } } } # Read, never write or delete, on the evidence. resource "azurerm_role_assignment" "evidence_reader" { scope = local.evidence_storage_account_id role_definition_name = "Storage Blob Data Reader" principal_id = azurerm_linux_virtual_machine.workstation.identity[0].principal_id }