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

Updated tool to read/write from AWS profile configurations. #7

Merged
merged 8 commits into from
Jul 12, 2017

Conversation

stevemac007
Copy link
Contributor

This PR resolves #5 by storing details in a profile in credentials and config.

$ aws-google-auth -p cevo-demo
Google username: email.address@goes.here
Google idp: abcdef
Google sp: 12345
Password: 
[  1] arn:aws:iam::54321342:role/Dev-Administrator
[  2] arn:aws:iam::12345678:role/Demo-Administrator
[  3] arn:aws:iam::98765432:role/Prod-Administrator
Type the number (1 - 3) of the role to assume: 2
Assuming arn:aws:iam::12345678:role/Demo-Administrator

That then results in:

[profile cevo-demo]
region = ap-southeast-2
output = json
google_config.role_arn = arn:aws:iam::12345678:role/Demo-Administrator
google_config.provider = arn:aws:iam::12345678:saml-provider/GoogleApps
google_config.google_idp_id = abcdef
google_config.google_sp_id = 12345
google_config.google_username = email.address@goes.here
google_config.duration = 3600

So when you run aws-google-auth -p cevo-demo again it auto-fills it all and looks like:

$ aws-google-auth -p cevo-demo
Google username: email.address@goes.here
Password: 
Assuming arn:aws:iam::12345678:role/Demo-Administrator

With much thanks to https://github.com/venth/aws-adfs for inspiration and chunks of code.

@@ -76,9 +76,6 @@ If you have more than one role available to you, you'll be prompted to
choose the role from a list; otherwise, if your credentials are correct,
you'll just see the AWS keys printed on stdout.

You should ``eval`` the ``export`` statements that come out, because
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking for advice on how to update the README to reflect the new features.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about rewriting the Usage section of the README. Something along the lines of:

  • Usage
    • Configuration via environment variables (setting GOOGLE_USERNAME etc)
    • Writing to a profile configuration (which arguments to use)
    • Using credentials in environment variables only (leaving off profile argument)
    • Running from a Docker image
    • Running from a locally-installed Python package

and then, I can merge this into the bash_wrapper branch and update the section on "environment variables only"

if args.username is None:
args.username = raw_input("Google username: ")

if args.idp_id is None or args.sp_id is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added raw_input lookups for these values (below) if not resolved from the stored config file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

if args.duration > 3600:
print "Duration must be less than or equal to 3600"
duration = 3600

config = prepare.get_prepared_config(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks up the config parameters from the ~/.aws/config file, overwridden from cli parameters or ENV variables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice


print "export AWS_ACCESS_KEY_ID='{}'".format(token['Credentials']['AccessKeyId'])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly we could keep this as a flag or when no --profile is specified??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If --profile is specified, don't do this bit; otherwise, of course, write the profile.

@nonspecialist
Copy link
Contributor

For now, don't worry about the use case when writing to a profile if using the Docker image -- I'll take care of that in feature/shell-eval (which should probably be renamed to feature/shell-wrapper) by mounting a volume at runtime; then the profile code doesn't have to change.

Copy link
Contributor

@nonspecialist nonspecialist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments in the PR, mostly on the README.

Can you also bump version to 0.0.7 in setup.py and in aws_google_auth/__init__.py?

@stevemac007
Copy link
Contributor Author

Updates as requested

@nonspecialist nonspecialist merged commit 345088c into master Jul 12, 2017
@nonspecialist nonspecialist deleted the add-aws-profile-support branch July 12, 2017 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to save credentials into ~/.aws/credentials file
2 participants