简体   繁体   English

AWS 负载均衡器到 EC2 实例防火墙规则

[英]AWS Load Balancer to EC2 instance firewall rules

I have an AWS EC2 load balancer that is in two availability zones.我有一个位于两个可用区的 AWS EC2 负载均衡器。 I am using the load balancer to front an apache server on an ec2 instance and I am using Cognito for authentication to the application.我正在使用负载平衡器在 ec2 实例上前置 apache 服务器,并且我正在使用 Cognito 对应用程序进行身份验证。

For now, I have identified the private IP addresses of the load balancer network interfaces and created firewall rules on my backend ec2 instance to only allow traffic from the load balancer's private IP addresses.目前,我已经确定了负载均衡器网络接口的私有 IP 地址,并在后端 ec2 实例上创建了防火墙规则,以仅允许来自负载均衡器私有 IP 地址的流量。 However those private IP addresses are constantly changing.但是,这些私有 IP 地址在不断变化。

What is the best practice for setting up firewall rules on my backend ec2 instance to only allowed HTTP requests which are essentially proxied by the load balancer and then authenticated by Cognito?在我的后端 ec2 实例上设置防火墙规则以仅允许基本上由负载均衡器代理然后由 Cognito 进行身份验证的 HTTP 请求的最佳实践是什么?

It is not really clear for me if by firewall you understand Security Groups, because in AWS Security Groups are considered to be stateful firewalls.我不太清楚防火墙是否理解安全组,因为在 AWS 中安全组被认为是有状态的防火墙。

You would not want to directly reference the IP address of the load balancers (I assume you are using Application Load Balancer), because that might change.您不希望直接引用负载均衡器的 IP 地址(我假设您使用的是应用程序负载均衡器),因为这可能会发生变化。 The solution is to have a Security Group assigned to the load balancer and another one the EC2 instance running the application.解决方案是将一个安全组分配给负载均衡器,并将另一个安全组分配给运行应用程序的 EC2 实例。 The Security Group from the EC2 instance can allow traffic on port 80 from the Security Group attached to the load balancer. EC2 实例的安全组可以允许来自连接到负载均衡器的安全组的端口 80 上的流量。

Since you are using Cognito, the authentication should happen before the load balancer, as it is described in the docs .由于您使用的是 Cognito,身份验证应该在负载均衡器之前进行,如文档中所述。 Essentially your clients request a token from Cognito which can be used to authenticate them in your application.本质上,您的客户从 Cognito 请求一个令牌,该令牌可用于在您的应用程序中对其进行身份验证。 You may allow outgoing traffic from your VPC/EC2 instance to Cognito using a NAT or and interface endpoint.您可以使用 NAT 或接口端点允许从您的 VPC/EC2 实例到 Cognito 的传出流量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM