|
| 1 | +# aws-cli-auth |
| 2 | + |
| 3 | +CLI tool for retrieving AWS temporary credentials using OIDC or SAML providers. |
| 4 | + |
| 5 | +Firstly, this package currently deals with SAML only (OIDC to come), however if you have an OIDC IdP provider set up to AWS you can use this [package](https://github.com/openstandia/aws-cli-oidc) and likewise this [package](https://github.com/Versent/saml2aws) for standard SAML AWS integrations. |
| 6 | + |
| 7 | +If, however, you need to support a non standard user journeys enforced by your IdP i.e. a sub company selection within your organization portal, or a selection screen for different MFA providers - PingID or RSA HardToken etc.... you cannot reliably automate the flow or it would have to be too specific. |
| 8 | + |
| 9 | +As such this approach uses [go-rod](https://github.com/go-rod/rod) library to uniformly allow the user to complete any and all auth steps and selections in a managed browser session up to the point of where the SAMLResponse were to be sent to AWS ACS service `https://signin.aws.amazon.com/saml`. Capturing this via hijack request and posting to AWS STS service to exchange this for the temporary credentials. |
| 10 | + |
| 11 | +The advantage of using SAML is that real users can gain access to the AWS Console UI or programatically and audited as the same person in cloudtrail. |
| 12 | + |
| 13 | +By default the tool creates the session name - which can be audited including the persons username from the localhost. |
| 14 | + |
| 15 | +## Known Issues |
| 16 | + |
| 17 | +- Even though a datadir is created to store the chromium session data it is advised to still open settings and save the username/password manually the first time you are presented with the login screen. |
| 18 | + |
| 19 | +## Install |
| 20 | + |
| 21 | +Download from [Releases page](https://github.com/dnitsch/aws-cli-auth/releases). |
| 22 | + |
| 23 | +MacOS |
| 24 | + |
| 25 | +```bash |
| 26 | +curl -L https://github.com/dnitsch/aws-cli-auth/releases/download/v0.1.0/aws-cli-auth-darwin-amd64 -o aws-cli-auth |
| 27 | +chmod +x aws-cli-auth |
| 28 | +sudo mv aws-cli-auth /usr/local/bin |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +```bash |
| 34 | +CLI tool for retrieving AWS temporary credentials using OIDC or SAML providers. |
| 35 | +Stores them under the $HOME/.aws/credentials file under a specified path |
| 36 | + |
| 37 | +Usage: |
| 38 | + aws-cli-auth [command] |
| 39 | + |
| 40 | +Available Commands: |
| 41 | + completion Generate the autocompletion script for the specified shell |
| 42 | + help Help about any command |
| 43 | + saml Get AWS credentials and out to stdout |
| 44 | + |
| 45 | +Flags: |
| 46 | + --cfg-section string config section name in the yaml config file |
| 47 | + -h, --help help for aws-cli-auth |
| 48 | + -r, --role string Set the role you want to assume when SAML or OIDC process completes |
| 49 | + -s, --store-profile By default the credentials are returned to stdout to be used by the credential_process |
| 50 | + |
| 51 | +Use "aws-cli-auth [command] --help" for more information about a command. |
| 52 | +``` |
| 53 | + |
| 54 | +### SAML |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +```bash |
| 59 | +Get AWS credentials and out to stdout through your SAML provider authentication. |
| 60 | + |
| 61 | +Usage: |
| 62 | + aws-cli-auth saml <SAML ProviderUrl> [flags] |
| 63 | + |
| 64 | +Flags: |
| 65 | + -a, --acsurl string Override the default ACS Url, used for checkin the post of the SAMLResponse (default "https://signin.aws.amazon.com/saml") |
| 66 | + -h, --help help for saml |
| 67 | + -d, --max-duration int Override default max session duration, in seconds, of the role session [900-43200] (default 900) |
| 68 | + --principal string Principal Arn of the SAML IdP in AWS |
| 69 | + -p, --provider string Saml Entity StartSSO Url |
| 70 | + |
| 71 | +Global Flags: |
| 72 | + --cfg-section string config section name in the yaml config file |
| 73 | + -r, --role string Set the role you want to assume when SAML or OIDC process completes |
| 74 | + -s, --store-profile By default the credentials are returned to stdout to be used by the credential_process |
| 75 | +``` |
| 76 | + |
| 77 | +Example: |
| 78 | + |
| 79 | +```bash |
| 80 | +aws-cli-auth saml --cfg-section nonprod_saml_admin -p "https://your-idp.com/idp/foo?PARTNER=urn:amazon:webservices" --principal "arn:aws:iam::XXXXXXXXXX:saml-provider/IDP_ENTITY_ID" -r "arn:aws:iam::XXXXXXXXXX:role/Developer" -d 3600 -s |
| 81 | +``` |
| 82 | + |
| 83 | +The PartnerId in most IdPs is usually `urn:amazon:webservices` - but you can change this for anything you stored it as. |
| 84 | + |
| 85 | +If successful will store the creds under the specified config section in credentials profile as per below example |
| 86 | + |
| 87 | +```ini |
| 88 | +[default] |
| 89 | +aws_access_key_id = XXXXX |
| 90 | +aws_secret_access_key = YYYYYYYYY |
| 91 | + |
| 92 | +[another_profile] |
| 93 | +aws_access_key_id = XXXXX |
| 94 | +aws_secret_access_key = YYYYYYYYY |
| 95 | + |
| 96 | +[nonprod_saml_admin] |
| 97 | +aws_access_key_id = XXXXXX |
| 98 | +aws_secret_access_key = YYYYYYYYY |
| 99 | +aws_session_token = ZZZZZZZZZZZZZZZZZZZZ |
| 100 | +``` |
| 101 | + |
| 102 | +To give it a quick test. |
| 103 | + |
| 104 | +```bash |
| 105 | +aws sts get-caller-identity --profile=nonprod_saml_admin |
| 106 | +``` |
| 107 | + |
| 108 | +<!-- ### Integrate aws-cli |
| 109 | +
|
| 110 | +[Sourcing credentials with an external process](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sourcing-external.html) describes how to integrate aws-cli with external tool. |
| 111 | +You can use `aws-cli-auth` as the external process. Add the following lines to your `.aws/config` file. |
| 112 | +
|
| 113 | +``` |
| 114 | +[profile ] |
| 115 | +credential_process=aws-cli-auth get-cred -p myop -r arn:aws:iam::123456789012:role/developer -j -s -d 43200 |
| 116 | +``` |
| 117 | +
|
| 118 | +Caution: The AWS temporary credentials will be saved into your OS secret store by using `-s` option to reduce authentication each time you use `aws-cli` tool. |
| 119 | +
|
| 120 | +## Licence |
| 121 | +
|
| 122 | +Licensed under the [MIT](/LICENSE) license. --> |
| 123 | + |
| 124 | +## Acknowldgements |
| 125 | + - [Hiroyuki Wada](https://github.com/wadahiro) [package](https://github.com/openstandia/aws-cli-oidc) |
| 126 | + - [Mark Wolfe](https://github.com/wolfeidau) [package](https://github.com/Versent/saml2aws) |
0 commit comments