CRITICAL
Source
Trivy
ID
AVD-AZU-0050

Security group should not allow unrestricted ingress to SSH port from any IP address.

SSH access can be configured on either the network security group or in the network security group rule. SSH access should not be permitted from the internet (*, 0.0.0.0, /0, internet, any)

Impact

Follow the appropriate remediation steps below to resolve the issue.

Block port 22 access from the internet

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
resource "azurerm_network_security_rule" "good_example" {
  name                       = "good_example_security_rule"
  direction                  = "Inbound"
  access                     = "Allow"
  protocol                   = "TCP"
  source_port_range          = "*"
  destination_port_range     = "22"
  source_address_prefix      = "82.102.23.23" # specific address
  destination_address_prefix = "*"
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
resource "azurerm_network_security_rule" "good_example" {
  name                       = "good_example_security_rule"
  direction                  = "Inbound"
  access                     = "Allow"
  protocol                   = "ICMP" # icmp
  source_port_range          = "*"
  destination_port_range     = "22"
  source_address_prefix      = "*"
  destination_address_prefix = "*"
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
resource "azurerm_network_security_rule" "good_example" {
  name                       = "good_example_security_rule"
  direction                  = "Inbound"
  access                     = "Allow"
  protocol                   = "TCP"
  source_port_range          = "*"
  destination_port_range     = "8080" # not ssh
  source_address_prefix      = "*"
  destination_address_prefix = "*"
}