question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

boto3 way to introspect AWS configuration to determine if `mfa_serial` is used in profile

See original GitHub issue

context:

  • we have several accounts
    • one’s $HOME/.aws/credentials usually contains a few accounts IE:
[default]
aws_access_key_id...
aws_secret_access_key...

[org1-admin]
aws_access_key_id...
aws_secret_access_key...
mfa_serial...

[org2-admin]
aws_access_key_id...
aws_secret_access_key...

[org3-admin]
aws_access_key_id...
aws_secret_access_key...
...
  • one of these accounts (org1-admin as noted by the presence of mfa_serial) uses sub-accounts so there’s a config
    • The contents of the $HOME/.aws/config defines profiles under one of the aforementioned specified accounts:
[profile gen3-prod]
role_arn = ...
source_profile = org3-admin

[profile gen3-preprod]
role_arn = ...
source_profile = org3-admin

[profile gen3-dev]
role_arn = ...
source_profile = org3-admin

So the problem:

We have an inventory CLI tool which needs to do resource querying. The problem is that MFA was recently set to forced for only one of the main accounts org1-admin. The CLI tool needs to be able to ask the CLI admin for their MFA token if the CLI tool is querying against org1-admin resources and then assume an sts role just for that account. That’s fine. The problem is that there is no reason for the script to attempt to query for MFA until it’s necessary (when it needs to seek resources from org1-admin).

Since boto doesn’t seem to be intelligent enough to notice when an account requires MFA for authorization, I need to code this in. My main problem is that I’m not really sure how to introspect the boto3 object to see if mfa_serial exists.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
notjamescommented, Jun 25, 2021

Let me give this a try tonight and I’ll comment on my success. Thank you!

This works the way I need it to. Thank you!!

1reaction
notjamescommented, Jun 23, 2021

Let me give this a try tonight and I’ll comment on my success. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

boto3 introspect user aws configuration to determine ...
There doesn't seem to be a good way to introspect the AWS configuration (CLI) to determine if a profile requires an MFA token...
Read more >
Configuration — Boto3 Docs 1.26.33 documentation - AWS
The default profile to use, if any. If no value is specified, Boto3 attempts to search the shared credentials file and the config...
Read more >
Tool to create ephemeral awscli/boto config/credentials files ...
Tool to create ephemeral awscli/boto config/credentials files for creating a long lasting (36 hour) cached MFA and child assumed role - GET-STS-SESSION.md.
Read more >
Configure AWS CLI profiles for Boto3 and the Amazon Braket ...
The Amazon Braket SDK relies upon the default AWS CLI credentials, unless you explicitly specify otherwise. We recommend that you keep the default...
Read more >
Configure credentials & Using AWS CLI profiles with Boto3
I do not need to tell you what can happen next. That is why I will recommend not use this way of setting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found