Description
Within one ACL and direction, the lowest-numbered rule that matches the CIDR, protocol and port wins. Two rules can cover the same ports without conflicting when their source networks are disjoint.
Potential impact
An early, broad allow can prevent a later deny from taking effect. Removing a needed port can also interrupt valid connections.
Remediation
Give exceptions that must take precedence lower numbers. Remove only redundant rules and test required connections and replies from each affected CIDR before and after the change.
Examples
The two inbound rules cover disjoint source ranges. The referenced MyNacl and its other rules are omitted.
Before
Resources:
AllowRangeOne:
Type: AWS::EC2::NetworkAclEntry
Properties:
NetworkAclId: !Ref MyNacl
RuleNumber: 100
Protocol: 6
RuleAction: allow
CidrBlock: 172.16.0.0/24
PortRange:
From: 13
To: 22
AllowRangeTwo:
Type: AWS::EC2::NetworkAclEntry
Properties:
NetworkAclId: !Ref MyNacl
RuleNumber: 110
Protocol: 6
RuleAction: allow
CidrBlock: 173.20.0.0/24
PortRange:
From: 20
To: 25
Each rule allows TCP ports 20–22 for its own source network.
After
Resources:
AllowRangeOne:
Type: AWS::EC2::NetworkAclEntry
Properties:
NetworkAclId: !Ref MyNacl
RuleNumber: 100
Protocol: 6
RuleAction: allow
CidrBlock: 172.16.0.0/24
PortRange:
From: 13
To: 19
AllowRangeTwo:
Type: AWS::EC2::NetworkAclEntry
Properties:
NetworkAclId: !Ref MyNacl
RuleNumber: 110
Protocol: 6
RuleAction: allow
CidrBlock: 173.20.0.0/24
PortRange:
From: 20
To: 25
Only the range for 172.16.0.0/24 shrinks to 13–19. Keep the original range if that network still needs ports 20–22.