Description
If an OSS bucket must be used only from approved networks, check the source IP that OSS sees. For internet requests through NAT, this can be the public egress IP.
Potential impact
A missing acs:SourceIp condition can allow valid credentials to be used from other networks. Anonymous access still depends on the permissions granted.
Remediation
Use IpAddress on an allow rule or NotIpAddress on a deny rule, according to your policy. A conditional allow can coexist with other grants. Check approved and blocked clients, service calls and an administrative recovery path.
Examples
Replace 203.0.113.0/24 with your actual approved range. The second rule denies only the listed actions outside that range. Requests inside it still need permission. Keep the Terraform resource address for an existing bucket.
Allow without a source-IP condition
resource "alicloud_oss_bucket" "bucket_policy" {
bucket = "bucket-170309-policy"
acl = "private"
policy = <<POLICY
{"Statement":
[{"Action":
["oss:PutObject", "oss:GetObject", "oss:DeleteBucket"],
"Effect":"Allow",
"Principal":["*"],
"Resource":
["acs:oss:*:*:bucket-170309-policy",
"acs:oss:*:*:bucket-170309-policy/*"]}],
"Version":"1"}
POLICY
}
Deny requests outside the approved range
resource "alicloud_oss_bucket" "restricted_bucket" {
bucket = "bucket-170309-policy"
policy = <<POLICY
{
"Version": "1",
"Statement":
[
{
"Effect": "Deny",
"Action":
[
"oss:RestoreObject",
"oss:ListObjects",
"oss:AbortMultipartUpload",
"oss:PutObjectAcl",
"oss:GetObjectAcl",
"oss:ListParts",
"oss:DeleteObject",
"oss:PutObject",
"oss:GetObject"
],
"Principal":
[
"*"
],
"Resource":
[
"acs:oss:*:*:bucket-170309-policy",
"acs:oss:*:*:bucket-170309-policy/*"
],
"Condition":
{
"NotIpAddress":
{
"acs:SourceIp": "203.0.113.0/24"
}
}
}
]
}
POLICY
}