We are planning to migrate some of our workloads to AWS EC2. One Service Running depends on a Server and we want to restrict access to this server granulary through Security Groups.
Now we noted, that AWS seems to have a limit of 60 Rules per Security Group and 6 attached Security Groups per Network Interface. While this can be extended through a quota request, the product of attached Security Groups multiplied by the max rules must not exceed 1000.
While i understand that more than 1000 granular connections can be an architectural nightmare, this is not completely impossible in our setup and is considered as a risk.
Do you also expierience similar problems? How do you handle such cases?
Avoid solving this by simply increasing the security group limits. If you have that many granular rules, consider using prefix lists to group CIDR ranges, separate security groups by service or access pattern, or move some filtering to AWS Network Firewall. It’s worth reviewing whether every connection really needs an individual rule. That might simplify the architecture considerably
You’re likely doing something wrong. Can you explain the nature of the kind of security group rules you’d like in an ideal world? When I see people ask this, the solution they’re looking for is actually to use “source security group ID” as the client identifier, rather than IP address ranges. But it’s hard to say without knowing what you’re actually trying to do.
Two details that change the maths before you go near the quota:
A rule that references another security group counts as one rule no matter how many instances carry that group. If most of your sources are EC2 instances or other AWS resources, give each client tier its own SG and reference it as the source. Thousands of hosts can then collapse into a handful of rules.
Managed prefix lists help with organisation, but not with the limit. A referenced prefix list counts against the quota by its max-entries value, not as one rule, so a 200-entry list still uses 200.
NACLs aren’t the escape hatch either. They’re stateless, ordered and capped much lower (20 rules by default), so they’re only useful for coarse subnet-level denies.
If your sources really are 1000+ distinct external IPs (partners, branch offices, on-prem ranges), I’d stop treating IP allowlisting as the authorisation layer. Put the server behind something that authenticates the caller: an ALB with mutual TLS (or mTLS terminated at the service itself), Verified Access for user-facing traffic, or PrivateLink for partners who are also on AWS. The SG then only needs to allow the load balancer or endpoint. Network Firewall makes sense if you need central L3/L4 policy at that scale, but it’s a cost and ops jump for a single service.
How many distinct sources are you really expecting, and are they mostly inside AWS or outside it? That decides which of these fits.
I did want to note that managed prefix lists don’t necessarily solve this.
If you are creating 10 rules and use a managed prefix list that has a max of 10 entries, that counts as 100 rules. Even if there are only 2 entries in the prefix list.
Remember that you can use Security Group as a source/destination for the rules. So if you have 15 servers that each need access via 10 rules on another server, create a SG for the source and destination (2x SG total). Create 10 rules in each (ingress in one and egress in the other) referencing the other SG as the source/destination.
Now every server that needs that access gets the source SG and the target resource gets the target SG.
We’ve found this works well if you generally have one service/use per server or use cases that overlap access needs. But you may still hit the SG per resource limit.
Restricting AD inbound has been the hard one for us. It’s like 14 rules with a huge amount of sources.
Exactly, it makes it worse in some cases because it reserves X number of “slots” in the SG for whatever the size of the list is and unless you have each PL sized perfectly, it’s going to waste space in the SG.
One angle I haven’t seen mentioned yet: stop making that one server the enforcement point.
Put a Network Load Balancer (or ALB if the traffic is HTTP) in front of the service and move the per-source allow-listing up a tier. The per-partner rules then live on the load balancer’s security group or on AWS Network Firewall in front of it, and the server’s own security group allows traffic only from the load balancer — one rule instead of a thousand. That also buys you a stable place to add or remove a partner without touching the server at all, and without waiting on a rule change to propagate across a thousand-entry group.
A second thing worth checking before you chase the quota: how many of those sources are actually distinct networks? Partners that all come in through one NAT gateway, one on-prem egress, or one branch office can usually be collapsed into a single supernet, and that’s often where the count drops from scary to manageable. Same for anything inside AWS — if the sources are other services in your accounts, one security group per role referenced as the source collapses hundreds of instance IPs into a single rule, and it stays correct when instances are replaced.
If after that you still genuinely need hundreds of distinct external sources, that’s the point where I’d reach for Network Firewall with stateful rule groups rather than keep stretching security groups — but only after the collapsing exercise, because a firewall full of rules you didn’t need is its own maintenance headache.
The 1,000 is per network interface, so the biggest win is using source security groups instead of individual IPs, since one rule covers every instance in that group. Prefix lists won’t save you rule count either, because AWS counts their max entries against the quota, so use them for tidiness and not capacity. If you still need more granular than that, I’d do the fine-grained part at a proxy, Network Firewall, or the app itself and keep the security group as the coarse outer layer.
referencing source security groups only works if the clients are actually inside the same vpc or peered though, if OP is whitelisting external customer IPs theyre stuck with raw CIDR blocks
Insufficient information provided, where do these clients connect ftom, etc.
Think of security groups as a primitive firewall restriction. Each network interface has one security group on it, the group defines which ports and protocols are open, and what other systems in AWS can access these resources.
There are situations where you need something more complicated than the above, but don’t start with that until you understand why you need that. In the majority of cases you don’t need the complex multi security group setup.
A security group is not by instance (you can, but don’t), but type of instance. So if for example you have 10 web servers to distribute the load across then they all have the same security group.
Keep it simple where you can.
You may be tempted to have a security group that grants web server access, another group for SSH, etc and compose the access permissions to an instance from these multiple security groups, don’t, that way lies madness especially when you start restricting things with source security group IDs.