在策略文档中为REST API配置iPaddress条件的正确方法是正确的?
我正在尝试仅允许特定的IP地址访问我的API Gateway REST API,而无需成功。
我配置了以下资源策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:eu-west-1:my-account-id:rest-api-id/*/*/*",
"Condition": {
"IpAddress": {
"aws.SourceIp": "MY.IP.MY.IP/32"
}
}
}
]
}
但是,当我使用Postman发送请求时,我会收到403。
如果我设置“ aws.sourceip”:“ 0.0.0.0/0”,我也会收到403。
如果我从策略中删除条件,则可以工作(我没有收到403),所以我想iPadress条件出了问题。
我有一个与REST API集成的C#lambda函数,其中我使用以下代码将sourceip
登录到CloudWatch:
context.Logger.LogInformation($"SourceIp: {request.RequestContext.Identity.SourceIp}");
它记录以下内容:
2022-07-01T06:38:32.634Z 0DC80274-BBBB-494C-BA73-541F053BA5A2 IFONE INFO SOUNCE SOUNTERIP: my.ip.my.ip
我想念什么?如何正确编写该政策?
I'm trying to allow only specific IP addresses to access my API Gateway REST API without success.
I configured the following resource policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:eu-west-1:my-account-id:rest-api-id/*/*/*",
"Condition": {
"IpAddress": {
"aws.SourceIp": "MY.IP.MY.IP/32"
}
}
}
]
}
But when I send a request using Postman I receive 403 forbidden.
If I set "aws.SourceIp": "0.0.0.0/0" I receive 403 as well.
If I remove the condition from the policy then it works (I don't receive 403), so I guess something is wrong with IpAdress condition.
I have a C# lambda function integrated with the REST API where I log the SourceIp
to CloudWatch using the following code:
context.Logger.LogInformation(quot;SourceIp: {request.RequestContext.Identity.SourceIp}");
It logs the following:
2022-07-01T06:38:32.634Z 0dc80274-bbbb-494c-ba73-541f053ba5a2 info SourceIp:
MY.IP.MY.IP
What am I missing? How to properly write the policy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将
更改为“ aws.sourceip”
为“ aws:sourceip”
和解决问题。对不起,错字。I changed
"aws.SourceIp"
to"aws:SourceIp"
and problem solved. Sorry for the typo.