This is possible thanks to the use of Bucket policies , which allows you to determine access rights for Amazon S3 resources - there are a couple of Examples of examples for Amazon S3 business strategies that illustrate functionality, and among them you will find an example of restricting access to certain IP addresses:
This statement grants permissions to any user to perform any S3 action on objects in the specified bucket. However, the request should come from the range of IP addresses specified in the condition.
Depending on the specifics of your use case, the bucket policy for this may look like this:
{ "Version": "2008-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:*", "Resource": "arn:aws:s3:::bucket/*", "Condition" : { "IpAddress" : { "aws:SourceIp": "192.168.143.0/24" }, "NotIpAddress" : { "aws:SourceIp": "192.168.143.188/32" } } } ] }
As shown, the aws:sourceIp
for the IPAddress
and NotIpAddress
is expressed in CIDR notation , which allows for flexibility in compiling the desired volume.
Finally, you might want to check out the recommended AWS Policy Generator , select the S3 Bucket Policy type and examine the available actions and conditions for creating more targeted policies for your use case in the end - the documentation for the Condition explains this in detail.
source share