Basically, this policy is for AWS Transfer Family. I need to deny all access to a specific folder inside the S3 bucket. I tried the below policy, but still I was able to list the contents of the folder. But it was denied for PUT and DELETE operations.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:ListBucketVersions",
"s3:GetBucketAcl"
],
"Resource": [
"arn:aws:s3:::${bucket_name}"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:GetObjectAcl",
"s3:GetObjectVersionTagging",
"s3:GetObjectVersionAcl",
"s3:GetObjectVersion"
],
"Resource": [
"arn:aws:s3:::${bucket_name}/*"
]
},
{
"Effect": "Deny",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::${bucket_name}/app/restricted",
"arn:aws:s3:::${bucket_name}/app/restricted/*"
]
}
]
}
Expected:
aws s3 ls s3://sample_bucket/app/restricted/data
- Access Denied
Behaviour:
aws s3 ls s3://sample_bucket/app/restricted/data
- Listing all the contents of the folder
The
ListBucket
operation (which lists objects within a bucket) is a bucket-level permission, so it ignores the path in the suppliedResource
.Instead, you can specify the path in a
Condition
parameter.From Amazon S3 Bucket: Deny List, Read, Write to specific folder - Stack Overflow:
This will
Deny
listing the contents of the bucket when the prefix isapp/restricted/*
. Add this statement to your existing policy, since it specifically applies toListBucket
. Keep your existingDeny
statement since it applies to other operations, such asGetObject
andPutObject
(which do accept paths in theresource
).