Skip to content
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

Is "Condition": {} really necessary? #66

Closed
simonw opened this issue Jan 20, 2022 · 3 comments
Closed

Is "Condition": {} really necessary? #66

simonw opened this issue Jan 20, 2022 · 3 comments
Labels

Comments

@simonw
Copy link
Owner

simonw commented Jan 20, 2022

Here:

AssumeRolePolicyDocument=json.dumps(
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::{}:root".format(account_id)
},
"Action": "sts:AssumeRole",
"Condition": {},
}
],

@simonw
Copy link
Owner Author

simonw commented Jan 20, 2022

I'll try creating a role in a Jupyter notebook without it.

@simonw
Copy link
Owner Author

simonw commented Jan 20, 2022

import boto3, json

iam = boto3.client("iam")
sts = boto3.client("sts")

iam.create_role(
    Description=(
        "Testing create_role without Condition"
    ),
    RoleName="testing-create-role-without-condition",
    AssumeRolePolicyDocument=json.dumps(
        {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Effect": "Allow",
                    "Principal": {
                        "AWS": "arn:aws:iam::{}:root".format(sts.get_caller_identity()["Account"])
                    },
                    "Action": "sts:AssumeRole",
                }
            ],
        }
    ),
)

returns:

{'Role': {'Path': '/',
  'RoleName': 'testing-create-role-without-condition',
  'RoleId': 'AROAWXFXAIOZA3ST3RHAX',
  'Arn': 'arn:aws:iam::462092780466:role/testing-create-role-without-condition',
  'CreateDate': datetime.datetime(2022, 1, 20, 1, 48, 28, tzinfo=tzutc()),
  'AssumeRolePolicyDocument': {'Version': '2012-10-17',
   'Statement': [{'Effect': 'Allow',
     'Principal': {'AWS': 'arn:aws:iam::462092780466:root'},
     'Action': 'sts:AssumeRole'}]}},
 'ResponseMetadata': {'RequestId': '8ab5e0cc-adae-46a8-82c9-cfc6d4d7f49b',
  'HTTPStatusCode': 200,
  'HTTPHeaders': {'x-amzn-requestid': '8ab5e0cc-adae-46a8-82c9-cfc6d4d7f49b',
   'content-type': 'text/xml',
   'content-length': '844',
   'date': 'Thu, 20 Jan 2022 01:48:27 GMT'},
  'RetryAttempts': 0}}

So this works fine.

@simonw simonw closed this as completed in f4fa0a3 Jan 20, 2022
@simonw
Copy link
Owner Author

simonw commented Jan 20, 2022

I deleted the role I created like this:

iam.delete_role(
    RoleName='testing-create-role-without-condition'
)

That worked the first time. I tried running it a second time out of curiosity and it gave me an error because the role was already deleted.

simonw added a commit that referenced this issue Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant