Sub topic 15
Quotas and keeping rule sets manageable
This chapter assumes you can read a security group rule, know that rules from multiple groups add up, and have used the AWS CLI. Security groups have quotas. A rule set that grows by one-off additions will eventually hit them, and it will also become hard to audit well before that.
The quotas that matter
The default values below apply per Region, and your account may differ. Check the Service Quotas console for current numbers.
| Quota | Default |
|---|---|
| Security groups per VPC | 2,500 |
| Inbound rules per security group | 60 (IPv4 and IPv6 each count separately) |
| Outbound rules per security group | 60 (IPv4 and IPv6 each count separately) |
| Security groups per network interface | 5 (adjustable up to 16) |
The rules-per-group quota and the groups-per-interface quota are linked. Multiplying them gives the number of rules that can apply to one network interface, and that product cannot exceed 1,000. If you raise the groups per interface, you may have to lower the rules per group. Request changes through Service Quotas.
What counts as one rule
Each rule entry counts once, whatever it matches. A rule that references another security group counts as one rule, however many instances use that group. A rule that references a prefix list counts as the maximum size of the list, not its current number of entries. A list created with --max-entries 20 uses 20 rules of capacity in every group that references it, even if it holds three CIDRs.
Choose the maximum size of a customer-managed prefix list with care. You can change it later, but the change fails if a referencing security group would then exceed its quota.
Strategies for staying under the limits
- Reference groups instead of listing addresses. One rule that names the web tier's group replaces a rule per instance or per subnet.
- Collapse CIDRs into prefix lists. Put office and VPN ranges in one prefix list and reference it from every group that needs them. A change to the list takes effect everywhere without editing the groups.
- Merge adjacent ranges. Two adjacent
/25blocks can often be one/24. Do this only if the wider range is still within least privilege. - Split by role, not by instance. Several small groups attached to one interface (for example
web-sgplusssh-from-office-sg) are easier to audit than one large group. Stay within the groups-per-interface quota. - Delete unused rules and groups. Old rules accumulate. A group still referenced by another group's rule cannot be deleted, which makes unused references a common blocker.
Example: consolidating with a prefix list
The commands below create a prefix list, reference it from a group, and count the inbound rules. Replace the IDs with your own.
aws ec2 create-managed-prefix-list \
--prefix-list-name office-cidrs \
--address-family IPv4 \
--max-entries 10 \
--entries Cidr=203.0.113.0/24,Description=HQ Cidr=198.51.100.0/24,Description=Branch
aws ec2 authorize-security-group-ingress \
--group-id sg-0123456789abcdef0 \
--ip-permissions 'IpProtocol=tcp,FromPort=22,ToPort=22,PrefixListIds=[{PrefixListId=pl-0123456789abcdef0,Description="Office SSH"}]'
aws ec2 describe-security-group-rules \
--filters Name=group-id,Values=sg-0123456789abcdef0 \
--query 'length(SecurityGroupRules[?IsEgress==`false`])'The SSH rule counts as 10 inbound rules, the list's maximum size, although the list holds two CIDRs. The last command counts rule entries, so it shows 1, not the quota consumed.
Common errors
RulesPerSecurityGroupLimitExceeded: the group is full. Consolidate or request an increase.MaxEntriesExceededor a failed prefix list resize: a referencing group would exceed its quota.DependencyViolationwhen deleting a group: another group's rule or an interface still references it.
Exercise
A security group has 55 inbound IPv4 rules. You want to add a rule that references a prefix list with a maximum size of 10 and one current entry. Will it succeed under the default quota of 60, and why?
Show answer
No. The rule counts as 10, the list's maximum size, not as its one entry. 55 + 10 = 65, which exceeds 60. Free up at least 5 rules first, or create the list with a smaller maximum size.