问题描述
在Bucket Policy中指定acs:SourceIp作为Condition时,需要同时指定acs:SourceVpc。
问题原因
用户发起了PutBucketPolicy请求,在提交的Bucket Policy中使用了acs:SourceIp作为某条授权策略的Condition,但是该授权策略没有指定acs:SourceVpc。
问题示例
PUT /?policy HTTP/1.0
Authorization:OSS LTAI4FixJvEPgvZ6g5cC****:al2vHOlTWQdQtM6oqJAEZh7d****
Content-Md5: eB5eJF1ptWaXm4bijSPyxw==
Date: Tue, 10 Feb 2026 08:48:18 GMT
Host: example-bucket.oss-cn-shanghai.aliyuncs.com
{
"Statement": [
{
"Action": [
"oss:GetObject",
],
"Condition": {
"IpAddress": {
"acs:SourceIp": [
"10.10.10.10"
]
}
},
"Effect": "Allow",
"Principal": [
"*"
],
"Resource": [
"acs:oss:*:1234567890123456:examplebucket/*"
]
}
],
"Version": "1"
}在请求提供的Bucket Policy中,通过acs:SourceIp限制了请求的源IP必须是10.10.10.10才能命中该条授权策略,但是却没有限制请求来源的VPC,导致PutBucketPolicy请求被拒绝。
解决方案
当您需要在Bucket Policy中限制来源IP时,除了通过acs:SourceIp限制IP或IP网段之外,还需要通过acs:SourceVpc限制请求来源的VPC。具体配置说明如下:
如果您希望限制访问来源为某个公网地址或者公网网段,则可以通过
StringNotLike限制请求不来自VPC。例如以下Policy示例允许地址段来自140.xx.xx.0/16,且不来自VPC的请求匿名访问Bucket中的文件。{ "Statement": [ { "Action": [ "oss:GetObject" ], "Condition": { "IpAddress": { "acs:SourceIp": [ "140.xx.xx.0/16" ] }, "StringNotLike": { "acs:SourceVpc": "vpc-*" } }, "Effect": "Allow", "Principal": [ "*" ], "Resource": [ "acs:oss:*:1234567890123456:examplebucket/*" ] } ], "Version": "1" }如果您希望限制访问来源为某个VPC中的部分IP地址,则可以通过
StringEquals限制请求来自特定的VPC。{ "Statement": [ { "Action": [ "oss:GetObject" ], "Condition": { "IpAddress": { "acs:SourceIp": [ "192.168.100.1", "192.168.100.2" ] }, "StringEquals": { "acs:SourceVpc": "vpc-1a2b3c4d5exxxxxxxx" } }, "Effect": "Allow", "Principal": [ "*" ], "Resource": [ "acs:oss:*:1234567890123456:examplebucket/*" ] } ], "Version": "1" }
相关文档
该文章对您有帮助吗?