Access Denied when IAM policy give access (Read/Write/Listing) to only a prefix area
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the restricted-prefix behavior with s3fs.S3FileSystem and fs.ls, using the IAM policy and versions shown in the issue. Compare the generated S3 listing request for paths with and without the trailing slash, then trace the relevant s3fs listing entry point. Done means identifying whether the denied request is expected or a s3fs bug and demonstrating the result with a focused regression check.
Written by the indexing model from the issue text.
Description
Say I have the following IAM policy for a user named "test-user" (as a Python dict instead of JSON, for concision):
{'Version': '2012-10-17',
'Statement': [{'Effect': 'Allow',
'Action': ['s3:PutObject', 's3:GetObject', 's3:DeleteObject'],
'Resource': ['arn:aws:s3:::my_bucket/some/prefix/${aws:username}/*']},
{'Effect': 'Allow',
'Action': 's3:ListBucket',
'Resource': 'arn:aws:s3:::my_bucket',
'Condition': {'StringLike': {'s3:prefix': ['some/prefix/${aws:username}/*']}}}]}
This works just fine:
import boto3
prefix = 'some/prefix/test-user'
prefix_slash = f'{prefix}/'
# valid path
boto3.client('s3').list_objects_v2(Bucket='my_bucket', Prefix=prefix_slash)
# should be unreadable
try:
boto3.client('s3').list_objects_v2(Bucket='my_bucket', Prefix=prefix)
assert RuntimeError(f'{prefix} (no slash) was expected to fail')
except ClientError:
pass
But the following code gives me Access Denied:
import s3fs
fs = s3fs.S3FileSystem(client_kwargs={'region_name': 'us-east-1'})
topdir = 'my_bucket/some/prefix/test-user'
fs.ls(f'{topdir}/')
If, however, I change the listing permission in IAM so the whole bucket can be listed:
[..., {'Effect': 'Allow',
'Action': 's3:ListBucket',
'Resource': 'arn:aws:s3:::my_bucket'}
]
Then it instantly works.
Another puzzling thing is, if I change the IAM permission back, the code above keeps working, even after starting a new Python interpreter.
Versions
import s3fs
import botocore
>>> {m.__name__: m.__version__ for m in [s3fs, botocore]}
{'s3fs': '2023.4.0', 'botocore': '1.29.76'}
- Dominant language
- Python
- Stars
- 1k
- Forks
- 305
- Avg merge
- 22h 37m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fsspec/s3fs
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 50/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100