|
| 1 | +--- |
| 2 | +severity: Critical |
| 3 | +pillar: Security |
| 4 | +category: SE:06 Network controls |
| 5 | +resource: Virtual Machine |
| 6 | +online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.VM.PublicIPAttached/ |
| 7 | +--- |
| 8 | + |
| 9 | +# Public IPs attached |
| 10 | + |
| 11 | +## SYNOPSIS |
| 12 | + |
| 13 | +Avoid attaching public IPs directly to virtual machines. |
| 14 | + |
| 15 | +## DESCRIPTION |
| 16 | + |
| 17 | +Attaching a public IP address to a virtual machine network interface (NIC) exposes it directly to the Internet. |
| 18 | +This exposure can make the VM vulnerable to unauthorized inbound access and security compromise. |
| 19 | +Minimize the number of Internet ingress/ egress points to enhance security and reduces potential attack surfaces. |
| 20 | + |
| 21 | +For enhanced security, consider one or more of the following options: |
| 22 | + |
| 23 | +- **Secure remote access** — by RDP or SSH to virtual machines can be configured through Azure Bastion. |
| 24 | + - Azure Bastion provides a secure encrypted connection without exposing a public IP. |
| 25 | +- **Exposing web services** — by HTTP/S can be configured by App Gateway or Azure Front Door (AFD). |
| 26 | + - App Gateway and AFD provide a secure reverse proxy that supports web application firewall (WAF) filtering. |
| 27 | +- **Internet connectivity** — should be managed through a security hardened device such as Azure Firewall. |
| 28 | + - This option also allows additional controls to be applied for east/ west and north/ south traffic filtering. |
| 29 | + - Alternatively a Network Virtual Appliance (NVA) can used. |
| 30 | + |
| 31 | +## RECOMMENDATION |
| 32 | + |
| 33 | +Evaluate alternative methods for inbound access to virtual machines to enhance security and minimize risk. |
| 34 | + |
| 35 | +### Configure with Azure template |
| 36 | + |
| 37 | +To deploy VM network interfaces that pass this rule: |
| 38 | + |
| 39 | +- For each IP configuration specified in the `properties.ipConfigurations` property: |
| 40 | + - Ensure that the `properties.publicIPAddress.id` property does not reference a Public IP resource. |
| 41 | + |
| 42 | +For example: |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "type": "Microsoft.Network/networkInterfaces", |
| 47 | + "apiVersion": "2023-11-01", |
| 48 | + "name": "[parameters('nicName')]", |
| 49 | + "location": "[parameters('location')]", |
| 50 | + "properties": { |
| 51 | + "ipConfigurations": [ |
| 52 | + { |
| 53 | + "name": "[parameters('ipConfig')]", |
| 54 | + "properties": { |
| 55 | + "privateIPAllocationMethod": "Dynamic", |
| 56 | + "subnet": { |
| 57 | + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]" |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + ] |
| 62 | + } |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +### Configure with Bicep |
| 67 | + |
| 68 | +To deploy VM network interfaces that pass this rule: |
| 69 | + |
| 70 | +- For each IP configuration specified in the `properties.ipConfigurations` property: |
| 71 | + - Ensure that the `properties.publicIPAddress.id` property does not reference a Public IP resource. |
| 72 | + |
| 73 | +For example: |
| 74 | + |
| 75 | +```bicep |
| 76 | +resource nic 'Microsoft.Network/networkInterfaces@2023-11-01' = { |
| 77 | + name: nicName |
| 78 | + location: location |
| 79 | + properties: { |
| 80 | + ipConfigurations: [ |
| 81 | + { |
| 82 | + name: ipconfig |
| 83 | + properties: { |
| 84 | + privateIPAllocationMethod: 'Dynamic' |
| 85 | + subnet: { |
| 86 | + id: resourceId('Microsoft.Network/virtualNetworks/subnets', virtualNetworkName, subnetName) |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + ] |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## LINKS |
| 96 | + |
| 97 | +- [SE:06 Network controls](https://learn.microsoft.com/azure/well-architected/security/networking) |
| 98 | +- [Plan for inbound and outbound internet connectivity](https://learn.microsoft.com/azure/cloud-adoption-framework/ready/azure-best-practices/plan-for-inbound-and-outbound-internet-connectivity) |
| 99 | +- [Dissociate public IP address from a VM](https://learn.microsoft.com/azure/virtual-network/ip-services/remove-public-ip-address-vm) |
| 100 | +- [Azure Bastion](https://learn.microsoft.com/azure/bastion/bastion-overview) |
| 101 | +- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.network/networkinterfaces) |
0 commit comments