-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
--duration
option to create time-limited credentials (using sts.assume_role()
)
#27
Comments
I'm going to add this to the existing |
sts.assume_role()
)--duration
option to create time-limited credentials (using sts.assume_role()
)
def ensure_s3_role_exists(iam, sts):
role_name = "s3-credentials.AmazonS3FullAccess"
account_id = sts.get_caller_identity()["Account"]
try:
role = iam.get_role(RoleName=role_name)
return role["Role"]["Arn"]
except iam.exceptions.NoSuchEntityException:
create_role_response = iam.create_role(
Description="Role used by the s3-credentials tool to create time-limited credentials that are restricted to specific buckets",
RoleName=role_name,
AssumeRolePolicyDocument=json.dumps(
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::{}:root".format(account_id)
},
"Action": "sts:AssumeRole",
"Condition": {},
}
],
}
),
)
# Attach AmazonS3FullAccess to it - note that even though we use full access
# on the role itself any time we call sts.assume_role() we attach an additional
# policy to ensure reduced access for the temporary credentials
iam.attach_role_policy(
RoleName="s3-credentials.AmazonS3FullAccess",
PolicyArn="arn:aws:iam::aws:policy/AmazonS3FullAccess",
)
return create_role_response["Role"]["Arn"] |
I'm going to change how policies work a little bit. The existing code attaches one policy per bucket to the created user: s3-credentials/s3_credentials/cli.py Lines 211 to 232 in 6e56b1b
With This will likely change the way |
As such, further work on this issue is blocked on the redesigned policies from #15. |
Tested my prototype with a 15 minute duration, when I tried to make a call more than fifteen minutes later I got:
|
See #26 for the research. It looks like the way to do this is:
arn:aws:iam::aws:policy/AmazonS3FullAccess
exists - if it does not, create it. It needs to have a known name - I propose usings3-credentials.AmazonS3FullAccess
here, and also populating theDescription
field. The role needs to be assumable by the current account, seeAssumeRolePolicyDocument
example in Research creating expiring credentials usingsts.assume_role()
#26 (comment)sts.assume_role()
against that role, passing in as a policy the same inline policy document used for non-expiring credentials, using the code inpolicies.py
.AccessKeyId
,SecretAccessKey
AND theSessionToken
- all three are needed to make authenticated calls.The text was updated successfully, but these errors were encountered: