Review the scope of network ACL deny rules

Check that network ACL deny ranges and rule ordering implement the intended traffic restrictions.

Description

Set a network ACL deny rule to the CIDR you intend to block. A narrow range is appropriate when only one network should be denied.

Potential impact

An earlier allow can let unwanted traffic through. An unnecessarily broad deny can also block required management access.

Remediation

Match the direction, protocol, ports and CIDR. Give a specific deny a lower number than any broader allow it must override. The first match applies and unmatched traffic is denied. Check IPv4, IPv6 and return traffic, then test new connections from allowed and blocked sources.

Examples

Both excerpts show only inbound TCP 22 rule 100 on MyNacl. Check the other rules and subnet association separately.

Before

yaml
Resources:
  InboundDenyRule:
    Type: AWS::EC2::NetworkAclEntry
    Properties:
      NetworkAclId: !Ref MyNacl
      RuleNumber: 100
      Protocol: 6
      RuleAction: deny
      CidrBlock: 172.16.0.0/24
      PortRange:
        From: 22
        To: 22

The first rule targets 172.16.0.0/24. Other sources are subject to the remaining rules.

After

yaml
Resources:
  InboundDenyRule:
    Type: AWS::EC2::NetworkAclEntry
    Properties:
      NetworkAclId: !Ref MyNacl
      RuleNumber: 100
      Protocol: 6
      RuleAction: deny
      CidrBlock: 0.0.0.0/0
      PortRange:
        From: 22
        To: 22

Expand the source to 0.0.0.0/0 only if SSH should be denied from every IPv4 source.

References