我有一个EC2服务器,它通过Internet上的API命中了“ n ”号,还有一组用户通过API命中了“ m ”个API。仅对于那些数量众多的 n 个API,我仅需要此EC2服务器即可访问它,而无需其他用户。
在设置资源策略以将EC2列入白名单以访问“ n ” API的同时,其他“ m ” API路径也受到限制。
请注意,所有请求都是GET for n。
/
|--m
|--square GET
|--triangle POST
L--circle GET, POST
|--n
|--red GET
|--green GET
|--trees GET
L--pear GET
L--blue GET
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:xx-direction-1:123456789101:abcdefghij/alpha/GET/m/*",
"Condition": {
"IpAddress": {
"aws:SourceIp": "100.200.100.200/32"
}
}
}
]
}
当我通过curl
访问' m '路径时,当它命中' n 'API时,会收到与用户相同的json。就是
{“ message”:“用户:匿名无权执行: execute-api:在资源上调用:arn:aws:execute-api:...
答案 0 :(得分:0)
可以这么说,这里的问题是什么,但很简单。诀窍是在相同的API路径上允许和拒绝,解决方案使我想起了电子产品的NAND门和NOR门类型所使用的逻辑。
注意,Condition
要求NotIpAddress
的情况。
{
"Effect": "Deny",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:xx-direction-1:123456789101:abcdefghij/alpha/GET/m/*",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": "100.200.100.200/32"
}
}
}
在这里更改Condition
,这是我错过的那个。
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:xx-direction-1:123456789101:abcdefghij/alpha/GET/m/*",
"Condition": {
"IpAddress": {
"aws:SourceIp": "100.200.100.200/32"
}
}
}
没有提到IP地址条件,这是因为“公共”!
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:ap-south-1:480833364711:q9omcoj8ba/alpha/GET/*"
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:xx-direction-1:123456789101:abcdefghij/alpha/GET/m/*",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": "100.200.100.200/32"
}
}
},
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:xx-direction-1:123456789101:abcdefghij/alpha/GET/m/*",
"Condition": {
"IpAddress": {
"aws:SourceIp": "100.200.100.200/32"
}
}
},
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:ap-south-1:480833364711:q9omcoj8ba/alpha/GET/*"
}
]
}
这就像一种魅力!