gpt4 book ai didi

amazon-web-services - 阅读文档时遇到的 AWS PrivateLink + CloudFormation 设置问题

转载 作者:行者123 更新时间:2023-12-03 07:12:06 26 4
gpt4 key购买 nike

我在做什么

我正在尝试这样做:

Launch tasks in a private subnet and make sure you have AWS PrivateLink endpoints configured in your VPC, for the services you need (ECR for image pull authentication, S3 for image layers, and AWS Secrets Manager for secrets).

我对此的理解是,AWS 服务充当“VPC 端点服务”,我所需要做的就是设置一个“接口(interface) VPC 端点”,使我的服务成为“服务使用者”,如下所述:https://docs.aws.amazon.com/vpc/latest/privatelink/vpce-interface.html

我尝试在 CloudFormation 中实现这一点,但阅读文档后我遇到了一些问题。

我的问题

问题 1

documentation 解释了如何创建接口(interface) VPC 终端节点,这非常棒。但它还说:“要为接口(interface)端点打开私有(private) DNS,请选中“启用 DNS 名称”复选框。”和“此选项默认打开”

但是在这里:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpcendpoint.html#cfn-ec2-vpcendpoint-privatednsenabled

它说:“默认值:假”。是哪个?

问题 2

我需要启用 3 个服务名称。那么...我需要重复3次吗?我的 YAML 重复 AWS::EC2::VPCEndpoint 3 次,如下所示。这真的正确吗?看起来太长/冗长了。

privateVPCEndpoint1:
Type: AWS::EC2::VPCEndpoint
Properties:
ServiceName: !Sub com.amazonaws.${AWS::Region}.ecr.dkr
PrivateDnsEnabled: True
# "If this parameter is not specified, we attach a default policy that allows full access to the service."
# PolicyDocument:
SecurityGroupIds:
- !Ref ECSSecurityGroupDownloadRedisContainer
SubnetIds:
- !Ref privateSubnet1
- !Ref privateSubnet2
VpcEndpointType: Interface
VpcId: !Ref VPC
privateVPCEndpoint2:
Type: AWS::EC2::VPCEndpoint
Properties:
ServiceName: !Sub com.amazonaws.${AWS::Region}.ecr.api
PrivateDnsEnabled: True
SecurityGroupIds:
- !Ref ECSSecurityGroupDownloadRedisContainer
SubnetIds:
- !Ref privateSubnet1
- !Ref privateSubnet2
VpcEndpointType: Interface
VpcId: !Ref VPC
privateVPCEndpoint3:
Type: AWS::EC2::VPCEndpoint
Properties:
ServiceName: !Sub com.amazonaws.${AWS::Region}.ecr.s3
PrivateDnsEnabled: True
SecurityGroupIds:
- !Ref ECSSecurityGroupDownloadRedisContainer
SubnetIds:
- !Ref privateSubnet1
- !Ref privateSubnet2
VpcEndpointType: Interface
VpcId: !Ref VPC

问题 3

For Security group, select the security groups to associate with the endpoint network interfaces.

我是否使用通过 NetworkConfiguration/AwsvpcConfiguration/SecurityGroups 附加到我的 ECS 服务的 ECSSecurityGroupDownloadRedisContainer 安全组?如果是,我是否需要关联 ECSSecurityGroupDownloadRedisContainer(允许 443 上的流量)和 ECSSecurityGroupRedis(允许 6379 上的流量)?我认为答案是肯定的 + 只有 ECSSecurityGroupDownloadRedisContainer 但我真的不知道。

问题 4

下载容器后,我能否以某种方式禁用端口 443 上对 ECS 的访问?我只需要访问Redis的6379;对我来说,其他任何事情似乎都是安全责任。

背景:我为什么要这样做

我尝试创建 ECS 集群 + 服务 + 任务,但收到错误:

(CannotPullContainerError:检查图像已重试 5 次:无法解析引用“docker.io/library/redis:latest”:无法执行请求:Head https://registry-1。 docker.io/v2/library/redis/manifests/latest:调用 tcp 34.231.251.252:443:i/o 超时)

研究让我看到了这篇文章:Aws ecs fargate ResourceInitializationError: unable to pull secrets or registry auth

今年 3 月份 AWS 员工 nathan peck 给出的权威答案:https://stackoverflow.com/a/66802973

他们提出了以下三种解决方案之一:

  • 使用公共(public) IP 地址将任务启动到公共(public)子网中,以便它们可以使用互联网网关与 ECR 和其他支持服务进行通信
  • 在私有(private)子网中启动任务,该子网具有配置为通过公有子网中的 NAT 网关路由出站流量的 VPC 路由表。这样 NAT 网关就可以代表任务打开与 ECR 的连接。
  • 在私有(private)子网中启动任务,并确保您在 VPC 中配置了 AWS PrivateLink 终端节点,以提供您所需的服务(用于镜像拉取身份验证的 ECR、用于镜像层的 S3 以及用于 key 的 AWS Secrets Manager)。

如您所知,redis 在端口 6379 上运行,而不是端口 443。我对这些解决方案的想法:

  • 选项 1 非常危险!我永远不应该被迫将我的数据库实例暴露给公共(public)互联网。所以就这样了。
  • 选项 2 是我开始实现的,然后我意识到这涉及公开并允许我的子网 + 路由表 + 等中端口 443 上的流量。当我只想使用端口 443 @ 容器启动。
  • 选项 3 似乎是正确的选择。

这就是我的旅程。

最佳答案

我让这个工作了。一些答案如下。

对于问题 1:

The documentation explains how to create the Interface VPC Endpoints, which is great. But it also says: "To turn on private DNS for the interface endpoint, for Enable DNS Name, select the check box." and "This option is turned on by default"

But over here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpcendpoint.html#cfn-ec2-vpcendpoint-privatednsenabled

It says: "Default: false". Which is it?

我不知道答案。我所知道的是,您绝对应该打开私有(private) DNS。而默认 DNS 类似于: ec2.us-east-1.amazonaws.com ;特定于端点的区域或区域 DNS 主机名更长且更复杂。更多信息:https://docs.aws.amazon.com/vpc/latest/privatelink/vpce-interface.html#access-service-though-endpoint

对于问题 2:不!我只需要重复两次。工作答案:

privateVPCEndpoint1:
Type: AWS::EC2::VPCEndpoint
Properties:
ServiceName: !Sub com.amazonaws.${AWS::Region}.ecr.dkr
PrivateDnsEnabled: True
# "If this parameter is not specified, we attach a default policy that allows full access to the service."
# PolicyDocument:
# Version: 2012-10-17
# Statement:
# - Effect: Allow
# Principal: '*'
# Action:
# - ''
# Resource:
# - ''
SecurityGroupIds:
- !Ref ECSSecurityGroupDownloadRedisContainer
SubnetIds:
- !Ref privateSubnet1
- !Ref privateSubnet2
VpcEndpointType: Interface
VpcId: !Ref VPC
privateVPCEndpoint2:
Type: AWS::EC2::VPCEndpoint
Properties:
ServiceName: !Sub com.amazonaws.${AWS::Region}.ecr.api
PrivateDnsEnabled: True
SecurityGroupIds:
- !Ref ECSSecurityGroupDownloadRedisContainer
SubnetIds:
- !Ref privateSubnet1
- !Ref privateSubnet2
VpcEndpointType: Interface
VpcId: !Ref VPC

对于问题 3:

这正是你应该做的,我似乎是正确的。

对于问题 4:

没有。如果现有容器出现故障,那么我将不得不启动一个新容器。发生这种情况时,我需要访问端口 443。您无法像这样切换防火墙/安全组的访问级别。

关于amazon-web-services - 阅读文档时遇到的 AWS PrivateLink + CloudFormation 设置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68685640/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com