Review access scope for service ports in Azure NSGs

Restrict administrative and internal service ports to the clients that need them.

Description

If TCP 23 is unnecessary, block new inbound connections to it in the Azure NSG. Keep any required public web ports in their own rules.

Potential impact

If the target is reachable and Telnet is listening, unintended clients can attempt sign-in. Plaintext sessions can expose credentials.

Remediation

Check the effective subnet and network interface rules. Test that new TCP 23 connections are blocked and required services still work. With the default purge_rules: false, rules omitted from the task remain in place, so explicitly remove obsolete grants.

Examples

With current Ansible, select the installed azure.azcollection in the play’s collections to use the short module name shown. Attach the NSG to the target subnet or network interface separately.

Before

yaml
- name: Allow TCP 23 from all IPv4 addresses
  azure_rm_securitygroup:
    resource_group: myResourceGroup
    name: mysecgroup
    rules:
      - name: example
        priority: 100
        direction: Inbound
        access: Allow
        protocol: TCP
        source_port_range: "*"
        destination_port_range: "23"
        source_address_prefix: "0.0.0.0/0"
        destination_address_prefix: "*"

The first rule allows TCP 23 from every IPv4 address (0.0.0.0/0).

After

yaml
- name: Deny new TCP 23 connections from all sources
  azure_rm_securitygroup:
    resource_group: myResourceGroup
    name: mysecgroup
    rules:
      - name: example
        priority: 100
        direction: Inbound
        access: Deny
        protocol: TCP
        source_port_range: "*"
        destination_port_range: "23"
        source_address_prefix: "*"
        destination_address_prefix: "*"

At the same priority of 100, the second denies new TCP 23 connections from every source (*). Established connections can continue after a rule change.

References