仅通过CloudFront访问ElasticBeanstalk

问题描述 投票:3回答:3

我目前的设置包括CloudFront和Elastic Beanstalk。如何配置相应LoadBalancer的安全组,以便只有来自CloudFront的请求才能通过LoadBalancer?

amazon-web-services elastic-beanstalk amazon-cloudfront
3个回答
1
投票

这可以通过使用云前端IP地址设置安全组并将EC2实例限制到该安全组来完成。由于Cloudfront IP一直在变化,this will be updated with a Lambda Function

Full Directions Are Here,但这里是悬崖笔记:

  1. AWS控制台 - > EC2 - >安全组
  2. 在与EB实例相同的VPC中创建安全组,确保创建以下标记: AutoUpdate:true 名称:cloudfront 协议:http(或者可以是https,或者如果您修改脚本,则可以是自定义的)。
  3. 使用以下内容创建IAM策略:

{“Version”:“2012-10-17”,“Statement”:[{“Effect”:“Allow”,“Action”:[“logs:CreateLogGroup”,“logs:CreateLogStream”,“logs:PutLogEvents”] ,“资源”:“arn:aws:logs :::”},{“效果”:“允许”,“操作”:[“ec2:DescribeSecurityGroups”,“ec2:AuthorizeSecurityGroupIngress”,“ec2:RevokeSecurityGroupIngress”], “资源”:“”}}}

  1. 在IAM中,使用上述策略创建角色
  2. 创建一个Lambda函数based on this source code,并为其指定在步骤#5中创建的角色。
  3. Use the sample at the bottom of the source code to test the function
  4. 当它因为您提取的JSON与测试请求中的哈希不匹配而失败时,请从错误消息中获取其期望的哈希值,并将该测试样本中的md5值替换为该值。
  5. 重新运行测试。这次它会成功。

注意:看一下您创建的组,现在他们已经填充了一大堆CloudFront IP条目。

  1. AWS控制台 - > Elastic Beanstalk - >应用程序 - >环境 - >配置 - >实例 - 更新组以包括您创建的组的组ID。

Lambda函数将使您的IP列表保持同步。


0
投票

您可以在Elastic BeanStalk上放置IAM角色,以仅允许来自CloudFront的传入消息。或者您只能允许从某个端口访问ELB实例,然后将CloudFront过滤到该端口。例如,Port 443HTTPS,通过Port 443授予CloudFront访问ELB,然后在您的Security-Group上,只允许CloudFront访问它的IP对实例的入站访问。

检查this


0
投票

您可以创建仅允许CloudFront并使其自动更新的安全组。您还可以在发行版和Elastic Beanstalk环境之间添加自定义标头(预共享密钥)。

  1. https://github.com/awslabs/aws-cloudfront-samples
  2. https://aws.amazon.com/about-aws/whats-new/2015/12/now-add-or-modify-request-headers-forwarded-from-amazon-cloudfront-to-origin/
© www.soinside.com 2019 - 2024. All rights reserved.