5 ms·
Network Load Balancers supporting security groups. I've gone through a bunch of audits, and automated scans, and I constantly have to explain this shit, even t
by paranoidrobot 4y ago
Network Load Balancers supporting security groups.
I've gone through a bunch of audits, and automated scans, and I constantly have to explain this shit, even to AWS Employees.
How it works with ALBs, which do support security groups:
You want to receive traffic on port :443, and allow it to be accessible to the world.
You have EC2 instances, and they are listening on the VPC at port :1234
So, you create:
- ALB my_alb which listens on :443, and forwards traffic to tg_traffic
- Target group tg_traffic, which contains the EC2 instances and targets the EC2 instance with port 1234
- Security Group sg_alb, attached to my_alb with two rules:
- rule 1, inbound, from 0.0.0.0/0:443
- rule 2, outbound, to sg_servers:1234
- Security Group sg_servers, attached to the EC2 instances with one rule:
- rule 1, inbound from sg_alb:1234
This makes everyone happy. The rules require that traffic from the internet has to go through the ALB.
Now how it works on a NLB, with the same scenario:
You want to receive traffic on port :443, and allow it to be accessible to the world. You have EC2 instances, and they are listening on the VPC at port :1234
However, NLBs, as mentioned, don't support security groups.
So, you create:
- NLB my_nlb which listens on :443, and forwards traffic to tg_traffic
- Target group tg_traffic, which contains the EC2 instances and targets the EC2 instance with port 1234
- Security Group sg_servers, attached to the EC2 instances with one rule:
- rule 1, inbound from 0.0.0.0:1234 (not :443, because the NLB translates the port for you, but not the source ip)
...that's it.
However, now every audit/automated scan of the EC2 instance & it's security group is going to see that you're listening on some random port, and allowing traffic from anywhere. This throws errors/alerts all the time. Even AWS's automated scans are throwing these alerts.
When it's an auditor you have to take the time to explain that, no, that's how NLBs work. For automated scans, you have to just ignore the warnings/errors constantly.
If your instance has no public IP associated, then at least only that port is exposed, and traffic does have to go through the NLB.
If for some reason the instance does have a public IP associated, then anyone who can reach the public IP can bypass your NLB.
If you could have a SG attached, then you could force the traffic to go via the NLB and not come direct to the instance.
- philliphaydon 4y agoI don’t think that’s right. You wouldn’t use 0.0.0.0/32 you would use the private subnet range so they have no direct access to the internet and use a nat gateway to give them access to the outside world but no inbound access. Edit: in the first example the servers should be in a private subnet. And not have a public ip allocated. They would require ssh hopping via a bastion or a vpn.
- paranoidrobot 4y agoIf your traffic is coming through a NLB, then the instances attached to the target group need to have 0.0.0.0/0 as the permitted source. (Assuming you want traffic from anywhere) If you dont believe me, try setting it up yourself. As for instances being on a private VPC/non-public IPs thats deployment specific. In any case, everything then complains about listening on strange ports with 0.0.0.0/0
- philliphaydon 4y agoI will try test it out this evening.
- philliphaydon 4y agoI tried it out and I don’t know why but I feel like it’s complicated to me. Setting everything up with an application load balancer, public and private subnet’s and security groups all makes perfect sense. But the network load balancer makes me confused. But adding it to my list of things to learn and understand better.
- paranoidrobot 4y ago> But the network load balancer makes me confused yep, it just works differently from everything else. Once you realise that, from a network traffic perspective, AWS wants you to pretend its just a magic straw delivering traffic from your source to your targets, and it's basically invisible to everything, then it started to click more for me. That's why I want NLBs to support SGs. or at least a NLBv2 that does it.
- benmmurphy 4y agoIf you run the NLB in ‘ip’ mode instead of instance mode you don’t have this problem. You still can’t setup security groups. However, you can put the NLB in a small subnet then whitelist the subnet. ‘ip’ mode is very different from instance mode and might not be what you want. Though, ‘instance’ mode is subtly bugged if you are using cross zone load balancing.