Git Product home page Git Product logo

gimme-aws-creds's Introduction

Gimme AWS Creds

gimme-aws-creds is a CLI that utilizes an Okta IdP via SAML to acquire temporary AWS credentials via AWS STS.

Okta is a SAML identity provider (IdP), that can be easily set-up to do SSO to your AWS console. Okta does offer an OSS java CLI tool to obtain temporary AWS credentials, but I found it needs more information than the average Okta user would have and doesn't scale well if have more than one Okta App.

With gimme-aws-creds all you need to know is your username, password, Okta url and MFA token, if MFA is enabled. gimme-aws-creds gives you the option to select which Okta AWS application and role you want credentials for. Alternatively, you can pre-configure the app and role name by passing -c or editing the config file. This is all covered in the usage section.

Disclaimer

Okta is a registered trademark of Okta, Inc. and this tool has no affiliation with or sponsorship by Okta, Inc.

Prerequisites

Okta SAML integration to AWS using the AWS App

Python 3.7+

A Note on Python 3.10+ Compatibility on Windows

gimme-aws-creds depends on the ctap-keyring-device library for WebAuthn support. All of the released versions of ctap-keyring-device require winRT on Windows, which only works on Python 3.9 and lower and is no longer maintained. Until a version of ctap-keyring-device that supports winSDK (the replacement for winRT) is released to PyPi, or some other solution is found, WebAuthn support will not be available for people running Python 3.10+ on Windows.

Optional

Gimme-creds-lambda can be used as a proxy to the Okta APIs needed by gimme-aws-creds. This removes the requirement of an Okta API key. Gimme-aws-creds authenticates to gimme-creds-lambda using OpenID Connect and the lambda handles all interactions with the Okta APIs. Alternately, you can set the OKTA_API_KEY environment variable and the gimme_creds_server configuration value to 'internal' to call the Okta APIs directly from gimme-aws-creds.

Installation

This is a Python 3 project.

Install/Upgrade from PyPi:

pip3 install --upgrade gimme-aws-creds

OR

Install/Upgrade the latest gimme-aws-creds package direct from GitHub:

pip3 install --upgrade git+git://github.com/Nike-Inc/gimme-aws-creds.git

OR

Install the gimme-aws-creds package if you have already cloned the source:

python -m pip install .

OR

Use homebrew

brew install gimme-aws-creds

OR

Use with nix flakes

# flake.nix
# Use by running `nix develop`
{
  description = "Shell example";

  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  inputs.gimme-aws-creds.url = "github:Nike-Inc/gimme-aws-creds";

  outputs = {
    self,
    nixpkgs,
    flake-utils,
    gimme-aws-creds,
    ...
  } @ inputs:
    flake-utils.lib.eachDefaultSystem
    (
      system: let
        pkgs = nixpkgs.legacyPackages.${system};
      in {
        devShells.default = pkgs.mkShell {
          packages = [pkgs.bash gimme-aws-creds.defaultPackage.${system}];
        };
      }
    );
}

OR

Use with original nix

# shell.nix
# Use by running `nix-shell`
{pkgs ? import <nixpkgs> {}, ...}:
with pkgs; let
  gimme-src = fetchgit {
    name = "gimme-aws-creds";
    url = "https://github.com/Nike-Inc/gimme-aws-creds";
    branchName = "master";
    sha256 = "<replace>"; #nix-prefetch-url --unpack https://github.com/Nike-Inc/gimme-aws-creds/archive/master.tar.gz
  };

  gimme-aws-creds = import gimme-src;
in
  mkShell rec {
    name = "gimme-aws-creds";

    buildInputs = [
      bash
      (gimme-aws-creds.default)
    ];
  }

OR

Build the docker image locally:

docker build -t gimme-aws-creds .

To make it easier you can also create an alias for the gimme-aws-creds command with docker:

# make sure you have the "~/.okta_aws_login_config" locally first!
touch ~/.okta_aws_login_config && \
alias gimme-aws-creds="docker run -it --rm \
  -v ~/.aws/credentials:/root/.aws/credentials \
  -v ~/.okta_aws_login_config:/root/.okta_aws_login_config \
  gimme-aws-creds"

With this config, you will be able to run further commands seamlessly!

Command Auto Completion

If you are using Bash or Zsh, you can add autocompletion for the gimme-aws-creds commandline options and profile names. To add the autocomplete config, add the following to the end of your .bashrc or .zshrc:

.bashrc

INSTALL_DIR=$(dirname $(which gimme-aws-creds))
source ${INSTALL_DIR}/gimme-aws-creds-autocomplete.sh"

.zshrc

INSTALL_DIR=$(dirname $(which gimme-aws-creds))
autoload bashcompinit
bashcompinit
source ${INSTALL_DIR}/gimme-aws-creds-autocomplete.sh

Using gimme-aws-creds with Okta Identity Engine

There are two options for using gimme-aws-creds with an OIE domain:

  • Device Authorization Flow
  • Forcing the use of the Okta Classic login flow

Okta Identity Engine and Device Authorization Flow

This is the recommended method for authentication with OIE. It matches the flow used by Okta's AWS client. When using gimme-aws-creds with the Device Authorization flow, you will authenticate using your browser. Storing credentials in keychain or passing MFA codes through the command-line is NOT POSSIBLE.

To use gimme-aws-creds with an Okta Identity Engine (OIE) domain, you must create a new OIDC Native Application and connect it to your AWS integration app(s).

The OIDC Native Application requires Grant Types Authorization Code, Device Authorization , and Token Exchange. These settings are in the Okta Admin UI at Applications > [the OIDC app] > General Settings > Grant type.

The pairing with the AWS Federation Application is achieved in the Fed app's Sign On Settings. These settings are in the Okta Admin UI at Applications > [the AWS Fed app] > Sign On. Make sure to set the Allowed Web SSO Client value to the Client ID of the OIDC Native Application. Repeat that setting for each AWS application you want to access with gimme-aws-creds.

Finally, set the Client ID in gimme-aws-creds (gimme-aws-creds --action-configure or update the client_id parameter in your config file)

Make sure to use the same authentication policy for both the AWS Federation Application and the OIDC application ( or at least use equivalent policy rules for both). If not, you'll receive a 400 Bad Request response when requesting the Web SSO token.

Forcing the use of the Okta Classic login flow

The login flow used in Okta Classic currently still works with Okta Identity Engine domains, BUT there are a couple caveats:

  • The Okta classic flow passes the stateToken parameter when requesting "step-up" authentication. This capability was removed in OIE, so if the authentication policy on your AWS app(s) requires MFA but the Global Session Policy does not (or if a higher level of MFA factor is required to access AWS), you cannot authenticate using the classic login flow.
  • MFA using Okta Verify is only supported on mobile devices. Okta Verify on macOS/Windows is not supported.
  • Passwordless authentication and endpoint security checks are not supported.

Configuration

To set-up the configuration run:

gimme-aws-creds --action-configure

You can also set up different Okta configuration profiles, this is useful if you have multiple Okta accounts or environments you need credentials for. You can use the configuration wizard or run:

gimme-aws-creds --action-configure --profile profileName

A configuration wizard will prompt you to enter the necessary configuration parameters for the tool to run, the only one that is required is the okta_org_url. The configuration file is written to ~/.okta_aws_login_config, but you can change the location with the environment variable OKTA_CONFIG.

  • conf_profile - This sets the Okta configuration profile name, the default is DEFAULT.
  • okta_org_url - This is your Okta organization url, which is typically something like https://companyname.okta.com.
  • okta_auth_server - Okta API Authorization Server used for OpenID Connect authentication for gimme-creds-lambda
  • client_id - OAuth client ID for user authentication in Okta Identity Engine and gimme-creds-lambda in Okta "classic"
  • gimme_creds_server
    • URL for gimme-creds-lambda
    • 'internal' for direct interaction with the Okta APIs (OKTA_API_KEY environment variable required)
    • 'appurl' to set an aws application link url. This setting removes the need of an OKTA API key.
  • write_aws_creds - True or False - If True, the AWS credentials will be written to ~/.aws/credentials otherwise it will be written to stdout.
  • cred_profile - If writing to the AWS cred file, this sets the name of the AWS credential profile.
    • The reserved word role will use the name component of the role arn as the profile name. i.e. arn:aws:iam::123456789012:role/okta-1234-role becomes section [okta-1234-role] in the aws credentials file
    • The reserved word acc will use the account number (or alias if resolve_aws_alias is set to y) as the profile name. i.e. arn:aws:iam::123456789012:role/okta-1234-role becomes section [arn:aws:iam::123456789012] or if resolve_aws_alias [okta-1234-role] in the aws credentials file.
    • The reserved word acc-role will use the name component of the role arn prepended with account number (or alias if resolve_aws_alias is set to y) to avoid collisions, i.e. arn:aws:iam::123456789012:role/okta-1234-role becomes section [123456789012-okta-1234-role], or if resolve_aws_alias [okta-1234-role] in the aws credentials file
    • If set to default then the temp creds will be stored in the default profile
    • Note: if there are multiple roles, and default is selected it will be overwritten multiple times and last role wins. The same happens when role is selected and you have many accounts with the same role names. Consider using acc-role if this happens.
  • aws_appname - This is optional. The Okta AWS App name, which has the role you want to assume.
  • aws_rolename - This is optional. The ARN of the role you want temporary AWS credentials for. The reserved word 'all' can be used to get and store credentials for every role the user is permissioned for.
  • aws_default_duration = This is optional. Lifetime for temporary credentials, in seconds. Defaults to 1 hour (3600)
  • app_url - If using 'appurl' setting for gimme_creds_server, this sets the url to the aws application configured in Okta. It is typically something like https://something.okta[preview].com/home/amazon_aws/app_instance_id/something
  • okta_username - use this username to authenticate
  • enable_keychain - enable the use of the system keychain to store the user's password
  • preferred_mfa_type - automatically select a particular device when prompted for MFA:
    • push - Okta Verify App push or DUO push (depends on okta supplied provider type)
    • token:software:totp - OTP using the Okta Verify App
    • token:hardware - OTP using hardware like Yubikey
    • call - OTP via Voice call
    • sms - OTP via SMS message
    • email - OTP via email
    • web - DUO uses localhost webbrowser to support push|call|passcode
    • passcode - DUO uses OKTA_MFA_CODE or --mfa-code if set, or prompts user for passcode(OTP).
    • claims_provider - DUO Universal Prompt
  • preferred_mfa_provider - (optional) automatically select a particular provider when prompted for MFA:
    • GOOGLE
    • OKTA
    • DUO
  • duo_universal_factor - (optional) Configure which type of factor to use with Duo Universal Prompt. Must be one of (case-sensitive):
    • Duo Push (default)
    • Passcode
    • Phone Call
  • resolve_aws_alias - y or n. If yes, gimme-aws-creds will try to resolve AWS account ids with respective alias names (default: n). This option can also be set interactively in the command line using -r or --resolve parameter
  • include_path - (optional) Includes full role path to the role name in AWS credential profile name. (default: n). If y: <acct>-/some/path/administrator. If n: <acct>-administrator
  • remember_device - y or n. If yes, the MFA device will be remembered by Okta service for a limited time. This option can also be set interactively in the command line using -m or --remember-device
  • output_format - json , export or windows, determines default credential output format, can be also specified by --output-format FORMAT and -o FORMAT.
  • open-browser - Open the device authentication link in the default web browser automatically (Okta Identity Engine domains only)
  • force-classic - Force the use of the Okta Classic login process (Okta Identity Engine domains only)

Configuration File

The config file follows a configfile format. By default, it is located in $HOME/.okta_aws_login_config

Example file:

[myprofile]
client_id = myclient_id

Configurations can inherit from other configurations to share common configuration parameters.

[my-base-profile]
client_id = myclient_id
[myprofile]
inherits = my-base-profile
aws_rolename = my-role

Usage

If you are not using gimme-creds-lambda nor using appurl settings, make sure you set the OKTA_API_KEY environment variable.

After running --action-configure, just run gimme-aws-creds. You will be prompted for the necessary information.

$ ./gimme-aws-creds
Username: [email protected]
Password for [email protected]:
Authentication Success! Calling Gimme-Creds Server...
Pick an app:
[ 0 ] AWS Test Account
[ 1 ] AWS Prod Account
Selection: 1
Pick a role:
[ 0 ]: OktaAWSAdminRole
[ 1 ]: OktaAWSReadOnlyRole
Selection: 1
Multi-factor Authentication required.
Pick a factor:
[ 0 ] Okta Verify App: SmartPhone_IPhone: iPhone
[ 1 ] token:software:totp: [email protected]
Selection: 0
Okta Verify push sent...
export AWS_ACCESS_KEY_ID=AQWERTYUIOP
export AWS_SECRET_ACCESS_KEY=T!#$JFLOJlsoddop1029405-P

You can automate the environment variable creation by running $(gimme-aws-creds) on linux or gimme-aws-creds | iex using Windows Powershell

You can run a specific configuration profile with the --profile parameter:

./gimme-aws-creds --profile profileName

The username and password you are prompted for are the ones you login to Okta with. You can predefine your username by setting the OKTA_USERNAME environment variable or using the -u username parameter.

If you have not configured an Okta App or Role, you will prompted to select one.

If all goes well you will get your temporary AWS access, secret key and token, these will either be written to stdout or ~/.aws/credentials.

You can always run gimme-aws-creds --help for all the available options.

Alternatively, you can overwrite values in the config section with environment variables for instances where say you may want to change the duration of your token. A list of values of to change with environment variables are:

  • AWS_DEFAULT_DURATION - corresponds to aws_default_duration configuration
  • AWS_SHARED_CREDENTIALS_FILE - file to write credentials to, points to ~/.aws/credentials by default
  • GIMME_AWS_CREDS_CLIENT_ID - corresponds to client_id configuration
  • GIMME_AWS_CREDS_CRED_PROFILE - corresponds to cred_profile configuration
  • GIMME_AWS_CREDS_OUTPUT_FORMAT - corresponds to output_format configuration and --output-format CLI option
  • OKTA_AUTH_SERVER - corresponds to okta_auth_server configuration
  • OKTA_DEVICE_TOKEN - corresponds to device_token configuration, can be used in CI
  • OKTA_MFA_CODE - corresponds to --mfa-code CLI option
  • OKTA_PASSWORD - provides password during authentication, can be used in CI
  • OKTA_USERNAME - corresponds to okta_username configuration and --username CLI option
  • AWS_STS_REGION - force the use of the STS in a specific region (us-east-1, eu-north-1, etc.)

Example: GIMME_AWS_CREDS_CLIENT_ID='foobar' AWS_DEFAULT_DURATION=12345 gimme-aws-creds

For changing variables outside of this, you'd need to create a separate profile altogether with gimme-aws-creds --action-configure --profile profileName

Viewing Profiles

gimme-aws-creds --action-list-profiles will go to your okta config file and print out all profiles created and their settings.

Viewing roles

gimme-aws-creds --action-list-roles will print all available roles to STDOUT without retrieving their credentials.

Credential expiration time

Writing to the AWS credentials file will include the x_security_token_expires value in RFC3339 format. This allows tools to validate if the credentials are expiring or are expiring soon and warn the user or trigger a refresh.

Generate credentials as json

gimme-aws-creds -o json will print out credentials in JSON format - 1 entry per line

Store credentials from json

gimme-aws-creds --action-store-json-creds will store JSON formatted credentials from stdin to aws credentials file, eg: gimme-aws-creds -o json | gimme-aws-creds --action-store-json-creds. Data can be modified by scripts on the way.

Usage in python code

Configuration and interactions can be configured using gimme_aws_creds.ui, UserInterfaces support all kind of interactions within library including: asking for input, sys.argv and os.environ overrides.

import sys
import gimme_aws_creds.main
import gimme_aws_creds.ui

account_ids = sys.argv[1:] or [
  '123456789012',
  '120123456789',
]

pattern = "|".join(sorted(set(account_ids)))
pattern = '/:({}):/'.format(pattern)
ui = gimme_aws_creds.ui.CLIUserInterface(argv=[sys.argv[0], '--roles', pattern])
creds = gimme_aws_creds.main.GimmeAWSCreds(ui=ui)

# Print out all selected roles:
for role in creds.aws_selected_roles:
    print(role)

# Generate credentials overriding profile name with `okta-<account_id>`
for data in creds.iter_selected_aws_credentials():
    arn = data['role']['arn']
    account_id = None
    for piece in arn.split(':'):
        if len(piece) == 12 and piece.isdigit():
            account_id = piece
            break

    if account_id is None:
        raise ValueError("Didn't find aws_account_id (12 digits) in {}".format(arn))

    data['profile']['name'] = 'okta-{}'.format(account_id)
    creds.write_aws_creds_from_data(data)

MFA security keys support

gimme-aws-creds works both on FIDO1 enabled org and WebAuthN enabled org

Note that FIDO1 will probably be deprecated in the near future as standards moves forward to WebAuthN

WebAuthN support is available for usb security keys (gimme-aws-creds relies on the yubico fido2 lib).

To use your local machine as an authenticator, along with Touch ID or Windows Hello, if available, you must register a new authenticator via gimme-aws-creds, using:

gimme-aws-creds --action-setup-fido-authenticator

Then, you can choose the newly registered authenticator from the factors list.

Running Tests

You can run all the unit tests using pytest. Most of the tests are mocked.

pytest -vv tests

Maintenance

This project is maintained by Eric Pierce

Thanks and Credit

I came across okta_aws_login written by Joe Keegan, when I was searching for a CLI tool that generates AWS tokens via Okta. Unfortunately it hasn't been updated since 2015 and didn't seem to work with the current Okta version. But there was still some great code I was able to reuse under the MIT license for gimme-aws-creds. I have noted in the comments where I used his code, to make sure he receives proper credit.

Etc

okta-aws-cli

okta-aws-cli-assume-role

AWS - How to Implement Federated API and CLI Access Using SAML 2.0 and AD FS

License

Gimme AWS Creds is released under the Apache License, Version 2.0

gimme-aws-creds's People

Contributors

10c0 avatar 1jsebastian avatar anners avatar aogail avatar bwynsm avatar chrissnell avatar corbanr avatar cornickj avatar cturner-confluent avatar dany74q avatar dogonthehorizon avatar edubxb avatar eedgar avatar elijah-roberts avatar elishagreenwald avatar epierce avatar g0ddard avatar jcreyf avatar joepurdy avatar jrduncans avatar kabakakao avatar longbowrocks avatar mdu42 avatar migueleliasweb avatar mjreed-wbd avatar nazarewk avatar pvsec avatar sector95 avatar smcavallo avatar tylersouthwick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gimme-aws-creds's Issues

As first time, running gimme-aws-creds returns a error

After use the gimme-aws-creds as first time,

complete the verification with Okta:

Multi-factor Authentication required.
Okta Verify App: SmartPhone_Android: Moto E (4) Plus selected
Okta Verify push sent...
done

And pick a role:

Pick a role any role:
[0] arn:aws:iam::<ID>:role/<ROLE_NAME>
[1] arn:aws:iam::<ID>:role/<ROLE_NAME>
Selection: 1

returns this error:

  File "/usr/local/bin/gimme-aws-creds", line 17, in <module>
    GimmeAWSCreds().run()
  File "/usr/local/lib/python3.7/site-packages/gimme_aws_creds/main.py", line 453, in run
    aws_creds = self._get_sts_creds(aws_partition, saml_data['SAMLResponse'], role.idp, role.role, config.aws_default_duration)
  File "/usr/local/lib/python3.7/site-packages/gimme_aws_creds/main.py", line 135, in _get_sts_creds
    client = boto3.client('sts')
  File "/usr/local/lib/python3.7/site-packages/boto3/__init__.py", line 91, in client
    return _get_default_session().client(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/boto3/__init__.py", line 80, in _get_default_session
    setup_default_session()
  File "/usr/local/lib/python3.7/site-packages/boto3/__init__.py", line 34, in setup_default_session
    DEFAULT_SESSION = Session(**kwargs)
  File "/usr/local/lib/python3.7/site-packages/boto3/session.py", line 80, in __init__
    self._setup_loader()
  File "/usr/local/lib/python3.7/site-packages/boto3/session.py", line 120, in _setup_loader
    self._loader = self._session.get_component('data_loader')
  File "/usr/local/lib/python3.7/site-packages/botocore/session.py", line 679, in get_component
    return self._components.get_component(name)
  File "/usr/local/lib/python3.7/site-packages/botocore/session.py", line 902, in get_component
    self._components[name] = factory()
  File "/usr/local/lib/python3.7/site-packages/botocore/session.py", line 150, in <lambda>
    lambda:  create_loader(self.get_config_variable('data_path')))
  File "/usr/local/lib/python3.7/site-packages/botocore/session.py", line 233, in get_config_variable
    logical_name)
  File "/usr/local/lib/python3.7/site-packages/botocore/configprovider.py", line 226, in get_config_variable
    return provider.provide()
  File "/usr/local/lib/python3.7/site-packages/botocore/configprovider.py", line 323, in provide
    value = provider.provide()
  File "/usr/local/lib/python3.7/site-packages/botocore/configprovider.py", line 382, in provide
    config = self._session.get_scoped_config()
  File "/usr/local/lib/python3.7/site-packages/botocore/session.py", line 334, in get_scoped_config
    raise ProfileNotFound(profile=profile_name)
botocore.exceptions.ProfileNotFound: The config profile (<PROFILE_NAME>) could not be found

My solution was just create in
~/.aws/credentials a new PROFILE_NAME (empty ) like:

[default]
aws_access_key_id = blabla
aws_secret_access_key = blabla

[PROFILE_NAME]

And works! ๐Ÿ˜„ But I think should be something that gimme-aws-creds should do or returns a better exception. ๐Ÿ‘

Its retaliated with #93

profile name uses hyphens, credentials file written with underscores

I have an AWS_PROFILE=one-prod-two, but the gimmie-aws-creds V1.0.13 writes it as one_prod_two in the credentials file. I had to add a one_prod_two entry to my config file, and change my AWS_PROFILE to one_prod_two ino rder to get the CLI to work after running gimmie-aws-creds.

However, if I request credentials for one_prod_two, I get a "not found" message
$ gimme-aws-creds -p one_prod_two Configuration profile not found! Use the --configure flag to generate the profile.

Also, we have one-nonprod-two, and it just works as expected.

Can't have more than one profile? Keeps overwriting.

When I do gimme-aws-creds --configure --profile Environment1 that works fine. if I repeat the command with Environment2, the old Enviroment1 entry is now gone from the .okta_aws_login_config file.

Am I doing something wrong or is this a bug? The same happens when you do --register_device --profile Environment1. I tried editing the file by hand, and it works for logging into each environment, after I concatenated the two separate files I saved to the side. But again if I do any register or config commands it wipes the file.

I am using the appurl mode if this matters.

Thank you.

Invalid URL No schema supplied

I get the below error while trying to run the script:

Traceback (most recent call last):
  File "/usr/local/bin/gimme-aws-creds", line 4, in <module>
    __import__('pkg_resources').run_script('gimme-aws-creds==0.1.3', 'gimme-aws-creds')
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 739, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1501, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds-0.1.3-py3.6.egg/EGG-INFO/scripts/gimme-aws-creds", line 175, in <module>
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds-0.1.3-py3.6.egg/EGG-INFO/scripts/gimme-aws-creds", line 113, in run
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds-0.1.3-py3.6.egg/gimme_aws_creds/config.py", line 97, in get_okta_api_key
  File "/usr/local/lib/python3.6/site-packages/cerberus_python_client-0.3-py3.6.egg/cerberus/client.py", line 39, in __init__
  File "/usr/local/lib/python3.6/site-packages/cerberus_python_client-0.3-py3.6.egg/cerberus/client.py", line 47, in set_token
  File "/usr/local/lib/python3.6/site-packages/cerberus_python_client-0.3-py3.6.egg/cerberus/user_auth.py", line 40, in get_token
  File "/usr/local/lib/python3.6/site-packages/cerberus_python_client-0.3-py3.6.egg/cerberus/user_auth.py", line 31, in get_auth
  File "/usr/local/lib/python3.6/site-packages/requests-2.14.2-py3.6.egg/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests-2.14.2-py3.6.egg/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests-2.14.2-py3.6.egg/requests/sessions.py", line 504, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python3.6/site-packages/requests-2.14.2-py3.6.egg/requests/sessions.py", line 436, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/local/lib/python3.6/site-packages/requests-2.14.2-py3.6.egg/requests/models.py", line 302, in prepare
    self.prepare_url(url, params)
  File "/usr/local/lib/python3.6/site-packages/requests-2.14.2-py3.6.egg/requests/models.py", line 382, in prepare_url
    raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL '/v2/auth/user': No schema supplied. Perhaps you meant http:///v2/auth/user?

Given below is how my config file looks:

[DEFAULT]
idp_entry_url =
write_aws_creds = True
cred_profile = default
aws_appname = ''
aws_rolename = ''
cerberus_url =

Could you kindly let me know what is going wrong. Thanks.

Unable to increase the exipry time of aws keys to 12 hours.

Hi There,

I was informed that aws keys will expire after 12 hours of creation. I tried different options: 1. use default value, 2. add "aws_default_duration = 43200" in .okta_aws_login_config.

My aws keys are expiring every hour. Can you please help me what configuration do I have to change to make sure keys are active for 12 hours from the time of creation.

Thanks,
Gaurav

Using gimme-aws-creds without a section for a profile errors out

I reinstalled the latest version of gimme-aws-creds and found that there are some odd error conditions that I couldn't get around until I manually added a section to my ~/.aws/credentials that was:

[cloud-admin]
aws_access_key_id = 
aws_secret_access_key = 

When the section was missing I got this:

RobWeaver:.aws robweaver$ gimme-aws-creds --version
gimme-aws-creds 1.0.13
RobWeaver:.aws robweaver$ gimme-aws-creds
Using password from keyring for robweaver
Multi-factor Authentication required.
Pick a factor:
[ 0 ] token:software:totp( GOOGLE ) : [email protected]
Unknown MFA type: web
[ 2 ] sms: +1 XXX-XXX-4762
Selection: 0
Enter verification code: 618167
Authentication Success! Getting AWS Accounts
Pick a role:
[0] arn:aws:iam::252989011795:role/cloud-admin
Selection: 0
Traceback (most recent call last):
  File "/usr/local/bin/gimme-aws-creds", line 17, in <module>
    GimmeAWSCreds().run()
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/main.py", line 433, in run
    aws_creds = self._get_sts_creds(aws_partition, saml_data['SAMLResponse'], role.idp, role.role, config.aws_default_duration)
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/main.py", line 133, in _get_sts_creds
    client = boto3.client('sts')
  File "/usr/local/lib/python3.6/site-packages/boto3/__init__.py", line 83, in client
    return _get_default_session().client(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/boto3/session.py", line 263, in client
    aws_session_token=aws_session_token, config=config)
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 850, in create_client
    credentials = self.get_credentials()
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 474, in get_credentials
    'credential_provider').load_credentials()
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1662, in load_credentials
    creds = provider.load()
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1213, in load
    return self._load_creds_via_assume_role(self._profile_name)
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1219, in _load_creds_via_assume_role
    role_config = self._get_role_config(profile_name)
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1297, in _get_role_config
    self._validate_source_profile(profile_name, source_profile)
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1328, in _validate_source_profile
    source_profile_name, parent_profile_name)
botocore.exceptions.InvalidConfigError: The source_profile "cloud-admin" referenced in the profile "default" does not exist.

When I add the section without the empty values, I get:

RobWeaver:.aws robweaver$ gimme-aws-creds
Using password from keyring for robweaver
Multi-factor Authentication required.
Pick a factor:
[ 0 ] token:software:totp( GOOGLE ) : [email protected]
Unknown MFA type: web
[ 2 ] sms: +1 XXX-XXX-4762
Selection: 0
Enter verification code: 094751
Authentication Success! Getting AWS Accounts
Pick a role:
[0] arn:aws:iam::252989011795:role/cloud-admin
Selection: 0
Traceback (most recent call last):
  File "/usr/local/bin/gimme-aws-creds", line 17, in <module>
    GimmeAWSCreds().run()
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/main.py", line 433, in run
    aws_creds = self._get_sts_creds(aws_partition, saml_data['SAMLResponse'], role.idp, role.role, config.aws_default_duration)
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/main.py", line 133, in _get_sts_creds
    client = boto3.client('sts')
  File "/usr/local/lib/python3.6/site-packages/boto3/__init__.py", line 83, in client
    return _get_default_session().client(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/boto3/session.py", line 263, in client
    aws_session_token=aws_session_token, config=config)
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 850, in create_client
    credentials = self.get_credentials()
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 474, in get_credentials
    'credential_provider').load_credentials()
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1662, in load_credentials
    creds = provider.load()
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1213, in load
    return self._load_creds_via_assume_role(self._profile_name)
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1219, in _load_creds_via_assume_role
    role_config = self._get_role_config(profile_name)
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1297, in _get_role_config
    self._validate_source_profile(profile_name, source_profile)
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1340, in _validate_source_profile
    source_profile_name)
botocore.exceptions.InvalidConfigError: The source_profile "cloud-admin" must specify either static credentials or an assume role configuration

And finally when I add the key id part:

RobWeaver:.aws robweaver$ gimme-aws-creds
Using password from keyring for robweaver
Multi-factor Authentication required.
Pick a factor:
[ 0 ] token:software:totp( GOOGLE ) : [email protected]
Unknown MFA type: web
[ 2 ] sms: +1 XXX-XXX-4762
Selection: 0
Enter verification code: 348592
Authentication Success! Getting AWS Accounts
Pick a role:
[0] arn:aws:iam::252989011795:role/cloud-admin
Selection: 0
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1396, in _resolve_static_credentials_from_profile
    secret_key=profile['aws_secret_access_key'],
KeyError: 'aws_secret_access_key'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/gimme-aws-creds", line 17, in <module>
    GimmeAWSCreds().run()
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/main.py", line 433, in run
    aws_creds = self._get_sts_creds(aws_partition, saml_data['SAMLResponse'], role.idp, role.role, config.aws_default_duration)
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/main.py", line 133, in _get_sts_creds
    client = boto3.client('sts')
  File "/usr/local/lib/python3.6/site-packages/boto3/__init__.py", line 83, in client
    return _get_default_session().client(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/boto3/session.py", line 263, in client
    aws_session_token=aws_session_token, config=config)
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 850, in create_client
    credentials = self.get_credentials()
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 474, in get_credentials
    'credential_provider').load_credentials()
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1662, in load_credentials
    creds = provider.load()
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1213, in load
    return self._load_creds_via_assume_role(self._profile_name)
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1221, in _load_creds_via_assume_role
    role_config, profile_name
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1381, in _resolve_source_credentials
    return self._resolve_credentials_from_profile(source_profile)
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1388, in _resolve_credentials_from_profile
    return self._resolve_static_credentials_from_profile(profile)
  File "/usr/local/lib/python3.6/site-packages/botocore/credentials.py", line 1401, in _resolve_static_credentials_from_profile
    provider=self.METHOD, cred_var=str(e))
botocore.exceptions.PartialCredentialsError: Partial credentials found in assume-role, missing: 'aws_secret_access_key'

And when I add the last line for the secret:

RobWeaver:.aws robweaver$ gimme-aws-creds
Using password from keyring for robweaver
Multi-factor Authentication required.
Pick a factor:
[ 0 ] token:software:totp( GOOGLE ) : [email protected]
Unknown MFA type: web
[ 2 ] sms: +1 XXX-XXX-4762
Selection: 0
Enter verification code: 004090
Authentication Success! Getting AWS Accounts
Pick a role:
[0] arn:aws:iam::252989011795:role/cloud-admin
Selection: 0
writing role arn:aws:iam::252989011795:role/cloud-admin to /Users/robweaver/.aws/credentials

Improper Credential Name When Grabbing Creds for AWS China Accounts

Currently if you grab creds for any of the aws china accounts using a profile you've configured, the creds get stored in your .aws/credentials file as an arn instead of just the profile name.

This is because the name is set by removing the first portion of the role but is only hardcoded for "arn:aws:..." where aws china roles look like "arn:aws-cn:..."

Note: I already fixed this issue and am in the process of submitting a PR, currently going through the contributing guidelines

gimme-aws-creds v1.1.0 runtime error after picking role

~ $ gimme-aws-creds
Using password from keyring for [email protected]
Multi-factor Authentication required.
Pick a factor:
[ 0 ] token:software:totp( GOOGLE ) : [email protected]
[ 1 ] sms: +1 XXX-XXX-0000
Selection: 0
Enter verification code: 382471
Authentication Success! Calling Gimme-Creds Server...
Pick an app:
[0] CDT-NPlus-Prod (*redacted*)
[1] CDT-NPlus-Test (*redacted*)
Selection: 0
Pick a role:
[0] arn:aws:iam::*redacted*:role/OktaPoweruserRole
[1] arn:aws:iam::*redacted*:role/OktaReadonlyRole
Selection: 1
Traceback (most recent call last):
  File "/usr/local/bin/gimme-aws-creds", line 17, in <module>
    GimmeAWSCreds().run()
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/main.py", line 453, in run
    aws_creds = self._get_sts_creds(aws_partition, saml_data['SAMLResponse'], role.idp, role.role, config.aws_default_duration)
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/main.py", line 135, in _get_sts_creds
    client = boto3.client('sts')
  File "/usr/local/lib/python3.6/site-packages/boto3/__init__.py", line 91, in client
    return _get_default_session().client(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/boto3/__init__.py", line 80, in _get_default_session
    setup_default_session()
  File "/usr/local/lib/python3.6/site-packages/boto3/__init__.py", line 34, in setup_default_session
    DEFAULT_SESSION = Session(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/boto3/session.py", line 80, in __init__
    self._setup_loader()
  File "/usr/local/lib/python3.6/site-packages/boto3/session.py", line 120, in _setup_loader
    self._loader = self._session.get_component('data_loader')
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 729, in get_component
    return self._components.get_component(name)
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 946, in get_component
    self._components[name] = factory()
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 186, in <lambda>
    lambda:  create_loader(self.get_config_variable('data_path')))
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 281, in get_config_variable
    elif self._found_in_config_file(methods, var_config):
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 308, in _found_in_config_file
    return var_config[0] in self.get_scoped_config()
  File "/usr/local/lib/python3.6/site-packages/botocore/session.py", line 385, in get_scoped_config
    raise ProfileNotFound(profile=profile_name)
botocore.exceptions.ProfileNotFound: The config profile (DEFAULT) could not be found

.okta_aws_login_config:

[DEFAULT]
okta_org_url = https://nike.okta.com
okta_auth_server = *redacted*
client_id = *redacted*
gimme_creds_server = https://api.sec.nikecloud.com/gimmecreds/accounts
aws_appname = 
aws_rolename = 
write_aws_creds = True
cred_profile = default
okta_username = [email protected]
app_url = 
resolve_aws_alias = False
preferred_mfa_type = 
aws_default_duration = 3600
device_token = *redacted*

.aws/ hasn't been created yet

Error while executing gimme-aws-creds

I am using Ubuntu 16.04 with Python3.
After running gimme-aws-creds , I am prompted for password and after which the verification code is sent to my number but right after that I am getting the following issue.
What could be the problem behind this?

Traceback (most recent call last):
  File "/usr/local/bin/gimme-aws-creds", line 4, in <module>
    __import__('pkg_resources').run_script('gimme-aws-creds==1.1.1', 'gimme-aws-creds')
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 719, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1511, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/local/lib/python3.5/dist-packages/gimme_aws_creds-1.1.1-py3.5.egg/EGG-INFO/scripts/gimme-aws-creds", line 17, in <module>
  File "/usr/local/lib/python3.5/dist-packages/gimme_aws_creds-1.1.1-py3.5.egg/gimme_aws_creds/main.py", line 442, in run
 File "/usr/local/lib/python3.5/dist-packages/gimme_aws_creds-1.1.1-py3.5.egg/gimme_aws_creds/okta.py", line 448, in get_saml_response
  File "/usr/local/lib/python3.5/dist-packages/gimme_aws_creds-1.1.1-py3.5.egg/gimme_aws_creds/okta.py", line 97, in stepup_auth
AttributeError: 'NoneType' object has no attribute 'get'

Store Username and Factor Option in Configuration

In an effort to make the workflow as quick and simple as possible, we should allow the user to store their username, and multi-factor of choice as part of the configuration. This will allow really painless refreshing/changing of credentials.

For example:

$ gimme-aws-creds.py --profile lab
Using password from keyring for <user>
Authentication Success!  Calling Gimme-Creds Server...
Multi-factor Authentication required.
Okta Verify push sent...
writing role <role> to <credfile>

The only interaction here would be with the MFA factor.

multi-role account credentials file not updated with --profile flag

v1.1.1

For multi-role accounts, and possibly for single accounts, when using the profile flag the profile name is not written to the credentials file. Rather the name of the role/namespace for the account is written.

Intended behavior:

Profile name should be written to ~/.aws/credentials in the form of

[aws-sbx-profile1]
aws_access_key_id = BLAHBLAH1
aws_secret_access_key = BLAHBLAH2
aws_session_token = SOMELARGETOKEN
aws_security_token = ANOTHERLARGETOKEN

To reproduce

$ rm ~/.aws/credentials
$ gimme-aws-creds -p aws-sbx-profile1
Using password from keyring for [email protected]
Multi-factor Authentication required.
Okta Verify App: SmartPhone_IPhone: This Guy's iPhone selected
Okta Verify push sent...
Authentication Success! Calling Gimme-Creds Server...
Pick an app:
[0] AWS-Non0 (acct#0)
[1] AWS-PRD1 (acct#1)
[2] AWS-SBX2 (acct#2)
Selection: 2
writing role arn:aws:iam::acct#2:role/role1_from_namespace to /Users/this_guy/.aws/credentials
writing role arn:aws:iam::acct#2:role/role2_from_namespace to /Users/this_guy/.aws/credentials

$cat ~/.aws/credentials

[role1_from_namespace] <-- should be [aws-sbx-profile1]
aws_access_key_id = BLAHBLAH1
aws_secret_access_key = BLAHBLAH2
aws_session_token = SOMELARGETOKEN
aws_security_token = ANOTHERLARGETOKEN

[role2_from_namespace]
aws_access_key_id = BLAHBLAH1
aws_secret_access_key = BLAHBLAH2
aws_session_token = SOMELARGETOKEN
aws_security_token = ANOTHERLARGETOKEN

Re opening the case 64

Good Morning

I already set Maximum CLI/API session duration to 12 hours (43,200 seconds) for the role and after that, I set aws_default_duration to 43200 in my local. But my keys are still expiring after an hour.

KeyError: 'idp_entry_url'

Hi,
I am trying to use your tool
and getting the following error:

Traceback (most recent call last):
File "/usr/local/bin/gimme-aws-creds", line 4, in
import('pkg_resources').run_script('gimme-aws-creds==0.1.3', 'gimme-aws-creds')
File "/usr/local/lib/python3.6/site-packages/pkg_resources/init.py", line 739, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/local/lib/python3.6/site-packages/pkg_resources/init.py", line 1501, in run_script
exec(script_code, namespace, namespace)
File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds-0.1.3-py3.6.egg/EGG-INFO/scripts/gimme-aws-creds", line 175, in
File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds-0.1.3-py3.6.egg/EGG-INFO/scripts/gimme-aws-creds", line 107, in run
KeyError: 'idp_entry_url'

Is this tool a wrapper for the Okta aws cli tool (which I found very problematic) which means I need the cli tool working first, or replaces it completely?

Thanks,
Tal

Does not give selections for MFA

With the latest release and a fresh install the tool does not provide a list of MFA options but leaves an empty selection despite multiple setup.

Multi-factor Authentication required.
Pick a factor:
Selection: 0
Traceback (most recent call last):
  File "/usr/local/bin/gimme-aws-creds", line 17, in <module>
    GimmeAWSCreds().run()
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/main.py", line 441, in run
    saml_data = okta.get_saml_response(aws_app['links']['appLink'])
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/okta.py", line 426, in get_saml_response
    api_response = self.stepup_auth(url, state_token)
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/okta.py", line 85, in stepup_auth
    flow_state['stateToken'], flow_state['apiResponse'])
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/okta.py", line 260, in _next_login_step
    return self._login_multi_factor(state_token, login_data)
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/okta.py", line 361, in _login_multi_factor
    factor = self._choose_factor(login_data['_embedded']['factors'])
  File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/okta.py", line 516, in _choose_factor
    return factors[int(selection)]
IndexError: list index out of range

Fresh python3 install via homebrew..

List of Python packages installed.

Package              Version  
-------------------- ---------
argcomplete          1.8.2    
asn1crypto           0.24.0   
azure-common         1.1.8    
azure-nspkg          2.0.0    
azure-storage-blob   0.37.1   
azure-storage-common 0.37.1   
azure-storage-file   0.37.0   
azure-storage-nspkg  3.0.0    
beautifulsoup4       4.6.0    
bitstring            3.1.5    
blobxfer             1.1.0    
boto3                1.7.25   
botocore             1.10.25  
certifi              2018.1.18
cffi                 1.11.4   
chardet              3.0.4    
click                6.7      
configparser         3.5.0    
cryptography         2.1.4    
decorator            4.0.11   
docutils             0.14     
editor               0.1.0    
future               0.16.0   
futures              3.1.1    
gimme-aws-creds      1.0.13   
idna                 2.6      
jmespath             0.9.3    
jsonpath-rw          1.4.0    
keyring              10.6.0   
okta                 0.0.4    
pip                  10.0.1   
ply                  3.10     
prettytable          0.7.2    
pycparser            2.18     
python-dateutil      2.6.1    
PyYAML               3.12     
requests             2.18.4   
ruamel.yaml          0.15.35  
s3transfer           0.1.13   
setuptools           39.0.1   
six                  1.10.0   
urllib3              1.22     
wheel                0.31.0   

Use a single okta app and not need okta API keys.

Currently, an OKTA api key is need which may not be available to use. Ideally, support to not require an API KEY and just read the SAML response for roles would be fine. There is a drawback where you won't have a resolved AWS account id to alias as that information isn't provided. Some other method to handle that would need to be done.

MFA issue

Hi Team,
I have user he got MFA setup for this account in OKTA, however when he run gimme-aws-creds command to generate credentials it doesn't ask for MFA and after selecting the AWS roles it just through this exception
screen shot 2018-04-19 at 4 28 40 pm

Make the configure option non-interactive

Add support of environment variables and/or command line arguments to set all configuration options so that the tool can be used in an automated environment.
Have the script look for the below variables and have it auto-generate the configuration section in ~/.okta_aws_login_config if not there yet and if it has everything it needs to do so. Then also have it generate the AWS credentials with these arguments in the same run.

This should allow for a much higher level of automation.

export AWS_APPNAME="..."
export AWS_ROLENAME="arn:aws:iam::..."
export CLIENT_ID="..."
export CRED_PROFILE="..."
export GIMME_CREDS_SERVER="https://..."
export OKTA_AUTH_SERVER="..."
export OKTA_ORG_URL="https://..."
export OKTA_USERNAME="..."
export WRITE_AWS_CREDS="True|False"

ModuleNotFoundError: No module named 'gimme_aws_creds'

Error while executing "gimme-aws-creds"

Traceback (most recent call last):
File "/root/gimme-aws-creds-1.0.13/bin/gimme-aws-creds", line 13, in
from gimme_aws_creds.main import GimmeAWSCreds
ModuleNotFoundError: No module named 'gimme_aws_creds'

not able to see credentials

have installed latest version of gimme-aws-creds.

using python version - Python 3.5.0

not seeing credentials being generated in .aws/credentials. In config file I have "write_aws_creds = True"

If I set it to false I don't see credentials on stdout

No device token in configuration

I'm having trouble getting this to run in my Windows 7 environment with Python 3.6. I'm following guidelines from our organisation, which say to do

python gimme-aws-creds --configure

to set it up. This seems to work ok. I can see a file called .okta_aws_login_config has been created with the details I entered.

However when I try to run it (again as per our guidelines):

python gimme-aws-creds --profile STS

(where STS is the name I gave the profile) then I get the following error:

No device token in configuration. Try running --register_device again.

I have no idea what to do next.

gimme-aws-creds gives error

APFJGTF18C63AD:gimme-aws-creds asaran$ gimme-aws-creds
Okta username must be an email address.

We are expected to see the prompt for email address, but instead of asking for the email, it is giving me the errorin okta.py . line #510.

unable to pipe output because questions are printed to stdout

So there is an option to write to your disk, but I would rather these creds be as ephemeral as possible. The tool is already nice enough to print them with export so that you can copy/paste them, but it would be even easier if we could

gimme-aws-creds | sh

And have it work. The issue is that currently the questions are printed to stdout, which screws with the pipe. If they were printed to stderr instead, the above command would work.

Profiles

There is no command to list all profiles . I couldn't find it in the help section

Does it work on Linux

Cannot get it work on Ubuntu 16.04 LTS neither on cygwin
But works fine from Windows 10 cmd.

Error :
me@my-ubu1604lts:~/gimme-aws-creds/bin$ ./gimme-aws-creds
Traceback (most recent call last):
File "./gimme-aws-creds", line 13, in
from gimme_aws_creds.main import GimmeAWSCreds
ImportError: No module named 'gimme_aws_creds'

Move GimmeAWSCreds class to allow Testing

bin/gimme-aws-creds needs to be refactored to move the GimmeAWSCreds class into another file within the gimme_aws_creds package to allow testing of the functions within the GimmeAWSCreds class. This is due to the fact that the hyphens in bin/gimme-aws-creds does not allow you to import the module for testing.

This work is being done in the no-role-handling branch.

Getting the following error

Hi Team,
I am getting the following error when approving from okta

Okta Verify push sent...
Traceback (most recent call last):
File "gimme-aws-creds.py", line 17, in
GimmeAWSCreds().run()
File "c:\MyProgs\myvenv\lib\site-packages\gimme_aws_creds\main.py", line 432, in run
scopes=['openid']
File "c:\MyProgs\myvenv\lib\site-packages\gimme_aws_creds\okta.py", line 220, in auth_oauth
url_parse_results = urlparse(response.headers['Location'])
File "c:\MyProgs\myvenv\lib\site-packages\requests\structures.py", line 52, in getitem
return self._store[key.lower()][1]
KeyError: 'location'

Ability to specify a specific TOPT instance for preferred_mfa_type

When using both Okta and conventional TOTP for MFA, there becomes two instances of token:software:totp:

Pick a factor:
[ 0 ] token:software:totp( GOOGLE ) : [email protected]
[ 1 ] token:software:totp( OKTA ) : [email protected]

You can eliminate the Okta Verify / push by using preferred_mfa_type = token:software:totp, but you cannot specify the instance of TOTP. Could selection of a specific TOTP instance be added to avoid this prompt each time when running for a given profile?

gimme-aws-creds overwrites config file everytime

Running gimme-aws-creds --configure -p <profile> overwrites the entire configuration file. This wipes out the default and other profiles you may have had. I also noticed that when I updated to the latest version, it had wiped out my previous config file.

Seems like the functionality changed with the latest release. Previously, if you ran the --configure with a different profile name, it would be appended to the existing configuration file. Now that is no longer the case and any run on --configure wipes out the entire file.

Could we get the old functionality back where the new configuration would be appended instead of the entire file being overwritten?

Credentials are not being written to cred file when there is only 1 role assigned

Hi,

If a user has only 1 role assigned in okta integration gimme-aws-creds successfully authenticate with PW and MFA and then exits with code 0 without writing to creds file.
If the user has at least 2 roles assigned in okta then the selection menu is displayed and everything is working
That is with the fresh installation (pip install git+git://github.com/Nike-Inc/gimme-aws-creds.git)

`
[xxx@gandalf:~]$ gimme-aws-creds
Password for xxx:
Authentication Success! Getting AWS Accounts
Multi-factor Authentication required.
token:software:totp( GOOGLE ) : [email protected] selected
Enter verification code: 610660

[xxx@gandalf:~]$ ls -la .aws/
total 12
drwxrwxr-x. 2 xxx xxx 39 Jun 21 09:16 .
drwx------. 27 xxx xxx 4096 Jun 29 10:29 ..
-rw-------. 1 xxx xxx 43 Jun 21 09:16 config
-rw-------. 1 xxx xxx 56 Jun 21 09:16 credentials

[xxx@gandalf:~]$ more .aws/config
[default]
region = eu-west-1
output = text

[xxx@gandalf:~]$ more .aws/credentials
[default]
aws_access_key_id =
aws_secret_access_key =

[xxx@gandalf:~]$ more .okta_aws_login_config
[DEFAULT]
okta_username = xxx
okta_org_url = https://yyy.okta.com
preferred_mfa_type = token:software:totp
write_aws_creds = True
cred_profile = default
gimme_creds_server = appurl
app_url = https://yyy.okta.com/home/amazon_aws/zzzzzzzzzzzzzzzz/zzz
resolve_aws_alias = True
aws_default_duration = 28800
`

I believe this is not a config issue

kind regards
Sebastian

version

add the ability to run --version so people can tell easily what version they are using.

Multiple profiles processed for single run

In DSM we are using up to 5 different AWS accounts, and some Terraform configurations access multiple accounts; currently this means we have to run gimme-aws-creds once for each profile.

Would it be possible to add support for a single Okta auth to populate multiple profiles?

DUO factor is not listed

Hi,

I have configured gimme-aws-creds as follows:

[DEFAULT]
okta_username = xxxxxx
okta_org_url = https://xxxxx.okta.com
gimme_creds_server = appurl
app_url = https://xxxxx.okta.com/home/amazon_aws/xxxxxxxxxxxxxxxxxxxx/xxx

when I run the software i get:
Password for xxxxxxxx:
Authentication Success! Getting AWS Accounts
Multi-factor Authentication required.
Pick a factor:
Selection: 0
Traceback (most recent call last):
File "/home/xxxxxxxx/.local/bin/gimme-aws-creds", line 17, in
GimmeAWSCreds().run()
File "/home/xxxxxxxx/.local/lib/python3.5/site-packages/gimme_aws_creds/main.py", line 434, in run
saml_data = okta.get_saml_response(aws_app['links']['appLink'])
File "/home/xxxxxxxx/.local/lib/python3.5/site-packages/gimme_aws_creds/okta.py", line 426, in get_saml_response
api_response = self.stepup_auth(url, state_token)
File "/home/xxxxxxxx/.local/lib/python3.5/site-packages/gimme_aws_creds/okta.py", line 85, in stepup_auth
flow_state['stateToken'], flow_state['apiResponse'])
File "/home/xxxxxxxx/.local/lib/python3.5/site-packages/gimme_aws_creds/okta.py", line 260, in _next_login_step
return self._login_multi_factor(state_token, login_data)
File "/home/xxxxxxxx/.local/lib/python3.5/site-packages/gimme_aws_creds/okta.py", line 361, in _login_multi_factor
factor = self._choose_factor(login_data['_embedded']['factors'])
File "/home/xxxxxxxx/.local/lib/python3.5/site-packages/gimme_aws_creds/okta.py", line 516, in _choose_factor
return factors[int(selection)]
IndexError: list index out of range

It seems it authenticate properly but the factor list is empty but I have DUO properly configured and AWS console access through Okta requires DUO MFA and that works properly (all methods - push, text, call and code)

kind regards
Sebastian

Breaks for multi-aws-account single okta application setup.

Problem Statement

Overview

The Okta setup documentation now has guidance on how to configure a single Okta application to refer to multiple downstream AWS accounts (http://saml-doc.okta.com/SAML_Docs/How-to-Configure-SAML-2.0-for-Amazon-Web-Service#scenarioB). This breaks the cli / api assumptions made in gimme-aws-creds in 2 key areas - the role name and the identityProviderArn. I am trying to work out how to best implement a fix.

Incorrect role name

First a quick example -

[root@fe1728b00c12 okta-src]# gimme-aws-creds -u [email protected]
Password for [email protected]:
Authentication Success! Getting AWS Accountsdone

Pick an app:
[ 0 ] FOOBAR AWS Accounts
Selection: 0
Pick a role:
[ 0 ] [foobarcontractors] -- okta-xonk-admin
[ 1 ] [foobar-it] -- okta-it-admin
Selection: 0
Traceback (most recent call last):
<snip>
  File "/usr/lib/python3.4/site-packages/botocore/client.py", line 599, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the AssumeRoleWithSAML operation: Request ARN is invalid

Note that [foobarcontractors] and [foobar-it] are independent aws accounts with separate account ids. These are not 2 roles within a single AWS account, rather they are 2 accounts with 1 saml role each.

I added a quick debug print to see what we are getting during the _get_sts_creds function -

print("Attempting STS with Role={}, Principal={}, Duration={}".format(self.role_arn,self.idp_arn,duration))

yields

Attempting STS with Role=arn:aws:iam::130894992587:role/[foobarcontractors] -- okta-xonk-admin, Principal=arn:aws:iam::123456789012:saml-provider/Okta, Duration=3600

Clearly this is broken due to the account string prefix. So a quick and dirty fix would be a simple re.sub to kill the [foobarcontractors] -- prefix before calling the role. This leads to the next issue -

Incorrect AWS Account ID

This one is a bit more thorny and will require some more digging. In _get_aws_account_info we enumerate the API call - {{url}}/api/v1/apps?filter=user.id+eq+"##USERID##"&expand=user/##USERID##. Inside the returned json, there is a single value for final_result[0]['settings']['app']['identityProviderArn'] = arn:aws:iam::123456789012:saml-provider/[Userdefinedstring]. Sadly this is AWS account id specific. As such, even if we correctly regex sub the role-name above, the identityProviderArn will have the incorrect account id and the derived role arn account number will be incorrect and the SAML assertion will fail. So we need to find some other way to infer aws account id.

If we just use the Okta website we can see the AWS account ids (note I had to censor the details of account numbers, hopefully doesn't affect clarity) -

okta saml

However, these account ID values don't exist in any of the datastructures we have in gimme-aws-creds currently.


Possible solutions

So, for the AWS Account ids I have a range of options:

Role name hints

To prefix this, I hate this idea, but through documentation you could require that users provide the target AWS account ID somewhere within the role name string. i.e. [foobar-it] -- okta-it-admin becomes [foobar-it] -- 123456789012-okta-it-admin. We could use this hint to locate aws account id if found.

Give up on multi-account and just document the limitation

I am actually kind of ok on this, but it is a bit unsatisfying. It is a similar amount of work to create a new Okta application as it is to tie multiple AWS accounts under a single application. As such we could just document the limitation and require single AWS accounts under each Okta application, with as many roles for that account as you like. We then will have the correct identity provider in the final_result for each application.

Option X

So for this, we would need to go digging. I don't know where to find the account number information displayed on the graphical saml page - but it has to be somewhere. I think based on the successful auth we should be able to curl and parse the saml page to get the roles and account ids for example.

Any thoughts on the above, and relative interest in making the script work vs just documenting lack of support for multi-account setups?

"CookieConflictError" when requesting renewing keys from Docker Container

Hi folks!

I'm getting this error when renewing keys.

$ gimme-aws-creds
Password for (ommited): 
Traceback (most recent call last):
  File "/usr/local/bin/gimme-aws-creds", line 7, in <module>
    exec(compile(f.read(), __file__, 'exec'))
  File "/opt/gimme-aws-creds/bin/gimme-aws-creds", line 17, in <module>
    GimmeAWSCreds().run()
  File "/opt/gimme-aws-creds/gimme_aws_creds/main.py", line 401, in run
    auth_result = okta.auth_session()
  File "/opt/gimme-aws-creds/gimme_aws_creds/okta.py", line 155, in auth_session
    return {"username": login_response['_embedded']['user']['profile']['login'], "session": response.cookies['sid'], "device_token": self._http_client.cookies['DT']}
  File "/usr/local/lib/python3.7/site-packages/requests-2.19.1-py3.7.egg/requests/cookies.py", line 328, in __getitem__
    return self._find_no_duplicates(name)
  File "/usr/local/lib/python3.7/site-packages/requests-2.19.1-py3.7.egg/requests/cookies.py", line 394, in _find_no_duplicates
    raise CookieConflictError('There are multiple cookies with name, %r' % (name))
requests.cookies.CookieConflictError: There are multiple cookies with name, 'DT'

Given the stacktrace, I followed the rabbit down the hole.

The method self._http_client.cookies['DT'] is failing to correctly return the value. As a simple test I tried accessing the cookie directly from the response and the expected value was actually there and without any duplicates.

So instead of:

return {
            "username": login_response['_embedded']['user']['profile']['login'],
            "session": response.cookies['sid'],
            "device_token": self._http_client.cookies['DT']
        }

I've changed to:

return {
            "username": login_response['_embedded']['user']['profile']['login'],
            "session": response.cookies['sid'],
            "device_token": response.cookies['DT']
        }

The only difference here is that instead of using the CookieJar from self._http_client.cookies = jar (gimme_aws_creds/okta.py:72) I've used the cookies references directly from the response.

I'm not sure why this error appears only when using the cookiejar from self._http_client.cookies = jar but I think it's safe to say using the response cookies is somewhat ok in this case. Tests are passing.

How to simulate the error?

Run the Docker container (as in the docs), punch the password and this error (sometimes) will arise. For me it only happens when you have already the device token set in your ~/.okta_aws_login_config.

  1. Run the container with --entrypoint sh
  2. Run inside the container's shell:
$ pip install -r requirements_dev.txt
$ python setup.py develop
$ gimme-aws-creds

Reading the cookie fails?

Seen this problem before?

Email address: [email protected]
Using password from keyring for [email protected]
Password for [email protected]:
Do you want to save this password in the keyring? (y/n)n
Traceback (most recent call last):
File "/usr/local/bin/gimme-aws-creds", line 17, in
GimmeAWSCreds().run()
File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/main.py", line 375, in run
auth_result = okta.auth_session()
File "/usr/local/lib/python3.6/site-packages/gimme_aws_creds/okta.py", line 138, in auth_session
return {"username": login_response['_embedded']['user']['profile']['login'], "session": response.cookies['sid']}
File "/usr/local/lib/python3.6/site-packages/requests/cookies.py", line 329, in getitem
return self._find_no_duplicates(name)
File "/usr/local/lib/python3.6/site-packages/requests/cookies.py", line 400, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='sid', domain=None, path=None"

Give ability to map aws account id to an alias - (pending on issue 26)

Provided work is done on issue 26, then the next step would be to have the ability to have an account id->alias mapping so you aren't stuck with . 1234567890:SomeRole . This is incredibly useful if you happen to have the same role across multiple accounts so you aren't necessarily guessing which account you're assuming role into. Mapping could be either part of config and really just needs to be key:value, but ability to specify an external file independent of config would be excellent as well. (I hope to get working on 26 and this one)

"Selection" breaks pipe to shell

At one point gimme-aws-creds | sh worked, but now because Selection: 1 appears before the export statements, this pipe produces an error.

gimme-aws-creds freezes after entering the user name

The process freezes entirely without any console output.
I am on Windows 10 in a conda environment. Same configuration works for my colleagues on a Mac.

Any ideas?
I there any way to approach this without opening the code?

Thanks

Ability to Create Configuration Profiles

Users want to be able to create configuration profiles for gimme-creds so they can quickly switch between role and account configurations to update their credentials.

gimme-aws-creds --profile <ProfileName>

[DEFAULT]
cerberus_url = https://cerberus.example.com
cred_profile = role
write_aws_creds = True
idp_entry_url = https://example.idp.com
aws_appname = App1
aws_rolename = Role1

[ProfileName]
cerberus_url = https://cerberus.example.com
cred_profile = role
write_aws_creds = True
idp_entry_url = https://example.idp.com
aws_appname = App2
aws_rolename = Role2

Accounts in AWS-China not supported

AWS China and AWS GovCloud use separate API endpoints from the rest of AWS, including the STS endpoint for requesting temporary credentials. boto3.client defaults to the standard endpoints, but can accept a region parameter to switch to one of the alternatives.

There needs to be a way to define the region on a per-account basis - you may have a user with access to accounts in China and other AWS regions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.