-
Notifications
You must be signed in to change notification settings - Fork 1.2k
s3:ListAllMyBuckets
or s3:CreateBucket
permission required for Session with default bucket
#2910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For anyone running into the same issue, a simple but hacky workaround is to override the sessions
|
s3:ListAllMyBuckets
permission required for Session with default bucket
s3:ListAllMyBuckets
permission required for Session with default buckets3:ListAllMyBuckets
or s3:CreateBucket
permission required for Session with default bucket
Facing the exact same issue when overriding the default_bucket on a Session object. This is completely counterintuitive and against least-privilege principles. |
this issue is extremely underrated. shows how many follow least-privilege principles vs using |
Thanks for all the info, Sagemaker team is looking into this issue and we would try to resolve this issue soon. |
The issue should be fixed now. Please use recent sagemaker-python-sdk >= v2.96.0 |
Describe the bug
When I create a Session like this:
Session(default_bucket=my_bucket)
, the library conveniently creates the bucket if it doesn't already exists. To check whether the bucket exists is based on getting the creation date of the bucket which is an operation that requires the IAM permissions3:ListAllMyBuckets
. This permission shouldn't be necessary and is often not allowed in environments following the least privileges principle.To reproduce
Create a Session with a
default_bucket
that already exists. Creating any Sagemaker processing job will fail if the used IAM role does not haves3:ListAllMyBuckets
ands3:CreateBucket
permission.Expected behavior
I should be able to create a Sagemaker processing job without having to assign
s3:ListAllMyBuckets
ors3:CreateBucket
to my IAM role.System information
A description of your system. Please provide:
Additional context
This code in the function
_create_s3_bucket_if_it_does_not_exist
insession.py
creates the bucket if it doesn't already exists:bucket.creation_date
(surprisingly) uses an API call likeaws s3 list-buckets
to get the creation date of the default bucket. The API call requiress3:ListAllMyBuckets
permission. Weirdly, if the caller doesn't have this permission, the API doesn't fail but just returnsNone
. In this case, we enter the if clause although the bucket may already exist.s3.create_bucket
obviously requires thes3:CreateBucket
permission. If the caller has this permission and the bucket already exists, the API raises a ClientError with error_codeBucketAlreadyOwnedByYou
, which will allow this code to pass.However, if the
s3:CreateBucket
permission isn't granted, this code fails with a permission denied ClientError.Therefore, the caller needs either
s3:ListAllMyBuckets
ors3:CreateBucket
in order for this code to work. Both shouldn't be needed for this operation.The head_bucket operation would be more suitable to be used instead of
bucket.creation_date
here because it's both faster and doesn't need the mentioned permissions. This would also allow the if clauseif error_code == "BucketAlreadyOwnedByYou":
to be removed.If you agree with me, I can help implementing a change. Please let me know! :)
Cheers
The text was updated successfully, but these errors were encountered: