Git Product home page Git Product logo

pyokta-aws-cli-assume-role's Introduction

pyokta-aws-cli-assume-role

pypi version pypi downloads source build License: GPL v3


Okta-AWS auth tool for humans

If you login to AWS via Okta SAML federation and assume an IAM role, this tool will help you easily achieve pragmatic access to AWS via the aws cli and SDKs. Also helpful for running terraform/terragrunt, packer, and credstash with iam roles.

Replaces okta-aws-cli-assume-role

NOTICE: This project is still in rapid development phase. You can subscribe to new release notifications via github. Upgrade to the most recent release via pip install --upgrade --no-cache-dir pyokta-aws-cli-assume-role.

Table of Contents

Support

  • MFA: SMS
  • MFA: Okta mobile app
  • All major operating systems (Linux, Windows, Mac).

Please create an issue for bugs or feature requests (if not already mentioned in roadmap or other issues).

Why a new tool?

Benefits over existing tool

  • No PATH changes or overriding aws executables - you're still using native awscli.
  • Supports multiple tenants.
  • One consistent config file for all tenants.
  • Env var changes are 100% optional.
  • Cleaner https error output.
  • Easy to install.
  • JVM not required.

Existing tool features missing in this tool

These features are planned to be supported in the near future. See roadmap.

  • Interactively select from multiple mfa options.
  • Set desired mfa option via cli args, env vars, or config file.
  • Support Okta mobile app mfa (currently only sms is verified to work).
  • Cross-OS compatibility
  • Okta token caching/refresh.

Getting Started

Requirements

  • python 3.5+
  • pip
  • awscli: pip install --upgrade awscli

Install

pip install --upgrade --no-cache-dir pyokta-aws-cli-assume-role


To check the install and output the current version, run: pyokta-aws --version

Configure

Configuration can be input via cli args, env vars, or the pyokta-aws config file described above. Configuration takes presidence as follows: cli args > env vars > config file. For all supported args and env vars, run pyokta-aws --help and pyokta-aws [COMMAND] --help.

Interactive

Run pyokta-aws configure for interactive configuration (WIP).

Config file

Default configuration file location is ~/.pyokta_aws/config.

Example config file:

[my-aws-profile]
region = us-east-1
okta_org = example.okta.com
okta_aws_app_url = https://example.okta.com/home/amazon_aws/123456789
aws_role_to_assume = arn:aws:iam::987654321:role/AWSAdmin
aws_idp = arn:aws:iam::987654321:saml-provider/Okta
username = johnsmith
sts_duration = 14400
mfa_choice = sms
  • region: Target AWS region. (Will override default region in target aws cli profile)
  • okta_org: Base domain for okta org.
  • okta_aws_app_url: Okta app url (can be found by hovering over aws app chiclet).
  • aws_role_to_assume: Found in AWS console under IAM > Roles > <role_id>. Look for ARN.
  • aws_idp: Found in AWS console under IAM > Identity Providers > <provider_id>. Look for ARN.
  • username: (optional) Okta username.
  • password: (optional) it is recommended to omit or leave it blank and enter it interactively.
  • sts_duration: (optional) Duration (in seconds) to keep token alive. Max duration found in IAM > Identity Providers > <provider_id>.
  • mfa_choice: (optional) If you have multiple MFA factors registered, you can skip interactive factor selection by setting preferred mfa choice. Current options are sms and app (i.e. Okta mobile app).

Usage

To authenticate via okta and assume an aws profile, run:

pyokta-aws auth --profile <aws_profile>


For all supported auth args, run pyokta-aws auth --help.

For all supported commands, run pyokta-aws --help.

How it works

The main pyokta-aws auth command authenticates with Okta and aquires a temporary set of credentials from AWS STS. These credentials get written to your local aws credentials file. This allows the aws cli and other tools like terraform/terragrunt, packer, and credstash to run as expected without needing to override the awscli executable or export environment variables.

Before auth happens, your local aws cli config profile is updated via the profile and region set in the pyokta-aws config. Treat your pyokta-aws config file as the single source of truth for aws cli config when authenticating with Okta.

Roadmap

  • pypi package
  • cli and settings loaders
  • support multi-tenant settings
  • ci (testing) ๐Ÿ‘ท
  • okta auth
  • okta 2fa (sms)
  • get saml from okta app
  • aws auth via okta auth
  • aws config if not previously setup
  • basic documentation ๐Ÿ“
  • support multiple 2fa methods
  • interactive initial config ๐Ÿšธ
  • readthedocs ๐Ÿ“
  • many more tests
  • windows support ๐Ÿ
  • ci/cd (deploy to pypi)?
  • aws role list selection in interactive mode ๐Ÿšธ
  • okta 2fa (okta mobile app)
  • push notification 2fa
  • use context managers to auto-cancel okta verifications on cancel
  • okta token cache/refresh to speedup multiple logins ๐Ÿšธ

๐Ÿถ

pyokta-aws-cli-assume-role's People

Contributors

jlecount avatar mijdavis2 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

jlecount cargaona

pyokta-aws-cli-assume-role's Issues

Unable to authenticate: problem with Role ARN?

I've submitted an issue before; I am now with a different employer and experiencing a different issue. I have installed the utility as directed and created the config file (see --verbose output below), but I am unable to authenticate due to an apparent issue with the Role ARN. Note that I am working in gov-cloud (not the public AWS cloud) and that services are sometimes absent or behave differently. Have you been able to test in the gov-cloud? Does the stack trace below indicate to you what might be wrong? As before, I have redacted certain information in the trace to preserve anonymity.

[me]>pyokta-aws auth --verbose -p rdt-admin
Loading settings from config file "[me]/.pyokta_aws/config"...
Using the following settings...
profile...........: rdt-admin
region............: us-gov-west-1
okta_org..........: [redacted].okta.com
okta_aws_app_url..: https://[okta-org]/home/amazon_aws/0oa46z3dyPZgL5uA24h6/272
aws_role_to_assume: arn:aws:iam::arn:aws-us-gov:iam::[aws-acct-id]:role/AdministratorViaOkta
aws_idp...........: arn:aws:iam::arn:aws-us-gov:iam::[aws-acct-id]:saml-provider/BraxtonOkta
username..........: [email protected]
password..........: <redacted>
sts_duration......: 28800
mfa_choice........: app
config_file.......: [me]/.pyokta_aws/config
verbose...........: True
interactive.......: True
Okta username: [email protected]
Enter Okta mobile app code: [auth-code]
Traceback (most recent call last):
  File "%LOCALAPPDATA%\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "%LOCALAPPDATA%\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "%LOCALAPPDATA%\Programs\Python\Python39\Scripts\pyokta-aws.exe\__main__.py", line 7, in <module>
  File "%LOCALAPPDATA%\programs\python\python39\lib\site-packages\pyokta_aws\__main__.py", line 26, in main
    return dispatch(sys.argv[1:])
  File "%LOCALAPPDATA%\programs\python\python39\lib\site-packages\pyokta_aws\cli.py", line 69, in dispatch
    return main(args.args)
  File "%LOCALAPPDATA%\programs\python\python39\lib\site-packages\pyokta_aws\commands\auth.py", line 99, in main
    return authenticate(auth_settings)
  File "%LOCALAPPDATA%\programs\python\python39\lib\site-packages\pyokta_aws\commands\auth.py", line 71, in authenticate
    resp = aws_auth_with_saml(
  File "%LOCALAPPDATA%\programs\python\python39\lib\site-packages\pyokta_aws\commands\auth.py", line 34, in aws_auth_with_saml
    return client.assume_role_with_saml(**data)
  File "%LOCALAPPDATA%\programs\python\python39\lib\site-packages\botocore\client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "%LOCALAPPDATA%\programs\python\python39\lib\site-packages\botocore\client.py", line 676, 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

[me]>

The documentation in the README seems to differ somewhat from the output of pyokta-aws -h, but I have tried numerous variations on the format of the Role ARN without success. Any suggestions will be welcome.

Seeing the below on Python 3.5

Ubuntu 18.04, python 3.5.2 - seems like a syntax error:

pyokta-aws auth --verbose --profile test -c ~/.pyokta_aws/config
Traceback (most recent call last):
File "/usr/local/bin/pyokta-aws", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/pyokta_aws/main.py", line 26, in main
return dispatch(sys.argv[1:])
File "/usr/local/lib/python3.5/dist-packages/pyokta_aws/cli.py", line 67, in dispatch
main = registered_commands[args.command].load()
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/init.py", line 2443, in load
return self.resolve()
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/init.py", line 2449, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/local/lib/python3.5/dist-packages/pyokta_aws/commands/auth.py", line 23, in
from pyokta_aws.okta.api import Api as OktaApi
File "/usr/local/lib/python3.5/dist-packages/pyokta_aws/okta/api.py", line 40
self.okta: OktaEndpoints = OktaEndpoints(okta_org, app_url)
^
SyntaxError: invalid syntax

I have the config file setup in the directory - not sure if this project is being maintained.

Unhandled error when NOT using MFA

Install the code and create config file as prescribed in README. mfa_choice is omitted from profile in config and is not enabled on AWS role or login. Attempt to auth to that profile yields:

Traceback (most recent call last):
  File "%LOCALAPPDATA%\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "%LOCALAPPDATA%\programs\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "%LOCALAPPDATA%\Programs\Python\Python37\Scripts\pyokta-aws.exe\__main__.py", line 9, in <module>
  File "%LOCALAPPDATA%\programs\python\python37\lib\site-packages\pyokta_aws\__main__.py", line 26, in main
    return dispatch(sys.argv[1:])
  File "%LOCALAPPDATA%\programs\python\python37\lib\site-packages\pyokta_aws\cli.py", line 69, in dispatch
    return main(args.args)
  File "%LOCALAPPDATA%\programs\python\python37\lib\site-packages\pyokta_aws\commands\auth.py", line 99, in main
    return authenticate(auth_settings)
  File "%LOCALAPPDATA%\programs\python\python37\lib\site-packages\pyokta_aws\commands\auth.py", line 70, in authenticate
    saml = okta.get_saml_via_auth()
  File "%LOCALAPPDATA%\programs\python\python37\lib\site-packages\pyokta_aws\okta\api.py", line 151, in get_saml_via_auth
    token = self._verify_via_mfa(resp.json())
  File "%LOCALAPPDATA%\programs\python\python37\lib\site-packages\pyokta_aws\okta\api.py", line 128, in _verify_via_mfa
    "Don't know how to handle status '{}'".format(data.get('status')))
Exception: Something went wrong.
Don't know how to handle status 'SUCCESS'

I have replaced the actual path in each line with the variable %LOCALAPPDATA% to keep things generic 8-) I've been playing around in the code and it appears that it tries to check MFA methods even when the option is omitted in the profile, plus there is that return value of "SUCCESS" that _verify_via_mfa is not expecting. Is this a bug, or am I doing something wrong?

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.