Score:1

AWS NLB with inbound whitelist IP

in flag

First of all, I'm newbie with docker-compose and AWS services but I have tried to learn about it and prepare it correctly, any advice is welcome.

I need to publish a app with ECS (this part works well, i use a docker-compose to do it. It publish correctly with a elastic public ip and it works) but the access to the app must be limited by allowed IPs. My idea was to publish the app with a public IP (Elastic IP assigned to load balancer) and limit access by security groups there.

But I can add any type of security group to load balancers, and if I modified security group of my services, they don't work.

My question is, can I assign a whitelist IPs to a NLB? I have seen that I can do like a whitelist IP in ALB but it doesn't assign elastic ip.

Score:1
gp flag
Tim

Are you publishing a web application / API? If so you should probably use an application load balancer rather than a network load balancer. NLBs are usually used for non-http(s) applications, you can use them with http(s) but ALBs tend to be better suited.

Design Considerations

I suggest you think about whether you really need a static IP. Some legacy or embedded systems might need it, but most are ok with a DNS address. If you really need a static IP you can use one of these techniques (or others you find on Google) to give an ALB a static IP, AWS Global Accelerator would do it but I'm not sure it's a good solution for you. You'd also have to consider high availability.

Regarding static IPs for whitelisting, you could consider doing authentication either with AWS Cognito integrated with the ALB (best) or inside your container. We usually federate with Azure AD, but you can define users / groups in Cognito. Users traffic to the ALB only gets to the target container / server if Cognito authorises the traffic.

Primary recommendation: AWS ALB integrated with AWS Cognito for authentication, security group around the ALB if you like but no whitelisting required.

Original Question

ALBs have security groups. Network load balancers do not. An NLB is invisible to the traffic so you put a security group around your resource (container) rather than your load balancer.

ALB IP whitelisting options:

  • You can whitelist access to an ALB with a security group, but you can't blacklist with a security group. There's a maximum number of rules, but each ALB can probably have multiple SGs attached - though be careful as it can impact performance. This is my secondary recommendation to you if you don't want to use Cognito.
  • You can whitelist or blacklist with Network Access Control Lists (NACLs)
  • You can do something inside the container with a local firewall, but I don't suggest that

NLB IP Whitelisting options:

  • Security group around the ECS container
  • NACL around the subnet(s)
Xeven avatar
in flag
Yes, I'm publishing a web app (in the future also its api). I have used a NLB because i can assign a elastic IP to it (it let me access to web app and api), but in case of ALB i have seen that i can use SG for a whitelist access althought i can't assign a elastic IP to it. How can i assign it or a static public IP to a ALB?
Tim avatar
gp flag
Tim
I edited my answer - 2nd paragraph. Do you have a hard requirement for a static IP? Static IPs can limit your ability to provide high availability. ALB with DNS name is a better solution in most cases, for web app and API
Xeven avatar
in flag
Maybe a static IP isn't mandatory, because it is a web app which we only want to allow access to specific IPs. I'm so new in network, can you recommend some documentation or something about it? Anyway i will try it. Thanks Tim.
Tim avatar
gp flag
Tim
Application Load Balancer with a security group to provide a whitelist will be your best / easiest option by far. AWS documentation is excellent and there are plenty of resources / tutorials online. Have a look at my updated answer as well, around Cognito.
Xeven avatar
in flag
Im interested in AWS Cognito, it might simplify some steps. I need basic function this week so i will try first about ALB/NLB option and then integrate a good option to learn and know how to do it in the future. While i searched information i have seen this url in AWS https://aws.amazon.com/about-aws/whats-new/2021/09/application-load-balancer-aws-privatelink-static-ip-addresses-network-load-balancer/ Will it solve my problem too? Offtopic: Can you recommend good material which explain about AWS and network, it's intesting but i know very little about it. Thank you very much for your help
MLu avatar
id flag
MLu
@Tim come on, Global Accelerator is not a "kludgy workaround"! It's actually the correct answer when someone needs an ALB with static IPs ;)
Tim avatar
gp flag
Tim
@MLu ha, I haven't actually used that service yet so I don't know all that much about it other than what I had to learn for the various AWS certs :) I think the key here is understanding requirements and architecting for what is needed, rather than making the initial idea work. ALB with Cognito is probably best, ALB with SGs is the next step down, then maybe GA with ALB.
MLu avatar
id flag
MLu
@Tim indeed, and you’re absolutely correct. I was just commenting on that “kludgy workaround” statement w.r.t. GA - it’s actually an awesome service and not that expensive. Check out https://speedtest.globalaccelerator.aws/ ;)
Tim avatar
gp flag
Tim
@MLu that does look like a useful service and not a kludge, and even Wellington to Sydney benefits a bit. I hadn't used GA before, dozens of other services but not that one! It's not the right solution for this question, but it could be good for other solutions - particularly enterprise. Pricing is fairly reasonable for AWS ;)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.