gpt4 book ai didi

amazon-web-services - AWS 云信息 : Setting up more than 1 condition for IpAddress

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

我正在使用 AWS SAM,我用它来部署 lambda 并与 API 网关端点集成。

对于API网关,我有类似的东西:

Api:
Type: AWS::Serverless::Api
Properties:
Cors:
AllowHeaders: "'Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,X-Api-Key,X-Requested-With'"
AllowMethods: "'GET,HEAD,POST'"
AllowOrigin: "'*'"
DefinitionBody:
swagger: 2.0
info:
version: 1.0
title: !Sub MyAPIGateway-${EnvironmentName}
paths:
/{proxy+}: # https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
x-amazon-apigateway-any-method:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations
x-amazon-apigateway-policy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal: "*"
Action: execute-api:Invoke
Resource: execute-api:/*/*/*
Condition:
IpAddress:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: s3://foo/bar/latest/cidr.yaml

将 s3://foo/bar/latest/cidr.yaml 视为包含所有白名单 IP 的文件,我无权更新或编辑它,因为它由安全。

假设在这些 CIDR block 之上,我想添加一些 NAT IP,在 Condition 下我可以添加一些内容,以便在 IpAddress 元素下我有另一个条目并对其中的 NAT IP 进行硬编码,以便在 CloudFormation 运行时将两者合并到包含两者 IP 的单个资源策略中?

现在,我部署并手动转到 API Gateway Web 控制台下的资源策略,添加我的 NAT IP,保存并重新部署。

我希望避免继续进行此手动更新。

顺便说一句,我可以拥有自己的 yaml 文件,其中包含所有内容,但我不想克隆 s3://foo/bar/latest/cidr.yaml 文件并添加我的 NAT IP 到它并在我的 CloudFormation 配置中使用克隆的文件,因为如果主文件中发生某些变化,我必须过于频繁地更新克隆的副本,因为安全可能是添加/删除 CIDR block 。

最佳答案

由于 Statement 是一个列表,我添加了另一个条目来包含 NAT IP,并且它有效。

类似于:

Statement:
- Effect: Allow
Principal: "*"
Action: execute-api:Invoke
Resource: execute-api:/*/*/*
Condition:
IpAddress:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: s3://foo/bar/latest/cidr.yaml
- Effect: Allow
Principal: "*"
Resource: execute-api:/*/*/*
Condition:
IpAddress:
aws:SourceIp:
- "myNatIp1/32"
- "myNatIp2/32"
- "myNatIp3/32"
Action: execute-api:Invoke

谢谢!

关于amazon-web-services - AWS 云信息 : Setting up more than 1 condition for IpAddress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66231410/

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