AWS Security Groups - The Good, the bad and the Ugly
AWS security groups have been around for ages. They are one of the fundamental controls in a VPC (virtual private cloud). You can attach them to so many products (like ec2, RDS etc). I though it was worth re-visiting them based on recent experience...
What is a security group (and the good points)?
Security groups are pretty much firewalls. They are a great way of protecting resources. They can be applied to individual resources so rather than having one firewall protecting your ingress, you can have a separate firewall protecting each individual resource. This is a big improvement over traditional firewalls. Not only does it protect your resources from internal traffic, it also greatly simplifies the management of your firewall rules.
As well as security groups, there are Network Access Control Lists (nACL). These can be used in addition to security groups. NALC are a perimeter control, they are not stateful and have both allow and deny lists. It this article I am focussing on security groups but it is worth mentioning nACL also. In general I would recommend using security groups as the 'primary' control and then use nACL as either a 'belt and braces' approach or if you need to add explicit deny rules.
The bad points
There are not many bad points to security groups:
There are some account/vpc limits. It is normally rare to reach them. They can be viewed here https://docs.aws.amazon.com/vpc/latest/userguide/amazon-vpc-limits.html In most cases if you are hitting the security group limits you may want to split up your services between separate AWS accounts anyway. This can be good from a security point of view and helps reduce blast radius in case of an issue.
As mentioned in the good points security groups are default deny and only has allow rules. In 99% of cases this is absolutely fine. If you do need an explicit deny rule, then you have to do that using VPC network access control lists (nACL). That sometimes takes a bit of planning when you have a very dynamic network. Generally though other tools like AWS shield (and associated products) should be used to block attacks. It is very rare to use explicit deny rules.
领英推荐
The ugly
There are a couple of security group features that conspire to annoy you with security groups.
If you have 2 security groups that reference each other it can make deleting them quite interesting. Most of the problems come when trying to use infrastructure as code (which you really should be doing). You can create dependancies that can't be resolved and cause changes to fail. One saving grace is that a lot of this can be used by using a create before destroy lifecycle. Rather than altering a security group a new one is created. It is then assigned to the relevant resource. Then the old security group can be removed. This can generally be done with zero outage but you do have to check if you can stand a service being unavailable even momentarily.
There are 2 other annoyances with security groups. One of which is minor, the other is a major pain:
Security group changes are a common reason why IaC updates can fail. Minor changes like a simple name change can fail because of references to the security group. Create before deleting fixes may items, but the one time when you can have major issues is when you have multiple IaC stacks for different elements of your environments and they reference each other. There are a few ways to resolve these issues but it does feel more painful than it should be.
Conclusion
Security groups are one of the most powerful networking concepts in the AWS world. They can be very useful for creating security in depth rather than just perimeter security. There its a real advantage in simplifying security. Many security issues are created by complexity. There are a