I have a situation where I need to restrict s3 bucket to deny all other ips except the list of ips provided but also allow access for snowflake. Since the list of possible ip addresses used by snowflake in a region is a lot - https://ip-ranges.amazonaws.com/ip-ranges.json, I was trying to see if I can provide an 'Allow' based on the snowflake role created for snowflake s3 stage. The policy I tried looks like below.
{
"Version": "2012-10-17",
"Id": "SourceIP",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::11111111111:role/snowflake-role"
},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::s3-bucket"
},
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:role/snowflake-role"
},
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::s3-bucket/*"
},
{
"Sid": "SourceIP",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::s3-bucket",
"arn:aws:s3:::s3-bucket/*"
],
"Condition": {
"NotIpAddress": {
"aws:SourceIp": [
"10.10.100.10",
"10.10.100.11",
"10.10.100.12",
"10.10.100.13"
]
}
}
}
]
}
This works perfectly on blocking other ip addresses but Snowflake cannot access. Since 'Deny' possibly denied all the ip addresses irrespective of above 'Allow' statement for snowflake, I tried Allow ip address as below.
{
"Version": "2012-10-17",
"Id": "SourceIP",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::11111111111:role/snowflake-role"
},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::s3-bucket"
},
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:role/snowflake-role"
},
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::s3-bucket/*"
},
{
"Sid": "SourceIP",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::s3-bucket",
"arn:aws:s3:::s3-bucket/*"
],
"Condition": {
"IpAddress": {
"aws:SourceIp": [
"10.10.100.10",
"10.10.100.11",
"10.10.100.12",
"10.10.100.13"
]
}
}
}
]
}
Now snowflake can access but ip restriction doesnt work. All ips can access the bucket. Can someone help me with my scenario?