Azure NSG does not restrict SSH sources

Restrict SSH access in Azure NSGs to required management addresses.

Description

For inbound TCP 22 in an Azure NSG, set sourceAddressPrefix to the administrator IP address or subnet that needs SSH.

Potential impact

A source of * leaves addresses unrestricted. An externally reachable VM can then receive unwanted SSH sign-in attempts.

Remediation

If direct SSH is unnecessary, use the approved management path, such as Azure Bastion. Review the effective rules and priorities on the NIC and subnet, then verify that only the approved path allows a new SSH connection.

Examples

The second example changes only the source of the priority 301 allow rule to 203.0.113.10/32. Replace this documentation address with the actual management address.

Before

bicep
resource security_group 'Microsoft.Network/networkSecurityGroups@2020-11-01' = {
  name: 'security-group'
  location: resourceGroup().location
  properties: {
    securityRules: [
      {
        properties: {
          protocol: 'Tcp'
          sourcePortRange: '*'
          destinationPortRange: '22'
          sourceAddressPrefix: '*'
          destinationAddressPrefix: '*'
          access: 'Allow'
          priority: 301
          direction: 'Inbound'
        }
        name: 'security-rule'
      }
    ]
  }
}

After

bicep
resource security_group 'Microsoft.Network/networkSecurityGroups@2020-11-01' = {
  name: 'security-group'
  location: resourceGroup().location
  properties: {
    securityRules: [
      {
        properties: {
          protocol: 'Tcp'
          sourcePortRange: '*'
          destinationPortRange: '22'
          sourceAddressPrefix: '203.0.113.10/32'
          destinationAddressPrefix: '*'
          access: 'Allow'
          priority: 301
          direction: 'Inbound'
        }
        name: 'security-rule'
      }
    ]
  }
}

References