I'm attempting to restrict S3 bucket access to EC2 instances that are within a few different subnets:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Principal": {"AWS": "*"},
"Resource": [
"arn:aws:s3:::test.bucket",
"arn:aws:s3:::test.bucket/*"
],
"Condition": {
"IpAddress": {
"aws:SourceIp": [
"192.168.129.64/27",
"192.168.129.96/27",
"192.168.128.64/26"
]
}
}
},
{
"Effect": "Deny",
"Action": "s3:*",
"Principal": {"AWS": "*"},
"Resource": [
"arn:aws:s3:::test.bucket",
"arn:aws:s3:::test.bucket/*"
],
"Condition": {
"NotIpAddress": {
"aws:SourceIp": [
"192.168.129.64/27",
"192.168.129.96/27",
"192.168.128.64/26"
]
}
}
}
]
}
I know that there are other problems regarding the specificity of this policy, but I've tried to make it as bare-bones as possible except for the conditions. Unfortunately, trying a simple aws s3 ls s3://test.bucket
from an ec2 instance with the IP address of 192.168.129.100
fails with an access denied. This policy has effectively locked me out of the bucket.
I don't know what I'm missing. I've even tried prepending ForAnyValue
and ForAllValues
to the IpAddress
and NotIpAddress
conditions.