Code Monkey home page Code Monkey logo

saml2aws's Introduction

saml2aws

GitHub Actions status Build status - Windows codecov

CLI tool which enables you to login and retrieve AWS temporary credentials using with ADFS or PingFederate Identity Providers.

This is based on python code from How to Implement a General Solution for Federated API/CLI Access Using SAML 2.0.

The process goes something like this:

  • Setup an account alias, either using the default or given a name
  • Prompt user for credentials
  • Log in to Identity Provider using form based authentication
  • Build a SAML assertion containing AWS roles
  • Optionally cache the SAML assertion (the cache is not encrypted)
  • Exchange the role and SAML assertion with AWS STS service to get a temporary set of credentials
  • Save these credentials to an aws profile named "saml"

Table of Contents

Requirements

Caveats

Aside from Okta, most of the providers in this project are using screen scraping to log users into SAML, this isn't ideal and hopefully vendors make this easier in the future. In addition to this there are some things you need to know:

  1. AWS defaults to session tokens being issued with a duration of up to 3600 seconds (1 hour), this can now be configured as per Enable Federated API Access to your AWS Resources for up to 12 hours Using IAM Roles and --session-duration flag.
  2. Every SAML provider is different, the login process, MFA support is pluggable and therefore some work may be needed to integrate with your identity server
  3. By default, the temporary security credentials returned do not support SigV4A. If you need SigV4A support then you must set the AWS_STS_REGIONAL_ENDPOINTS enviornment variable to regional when calling saml2aws so that aws-sdk-go uses a regional STS endpoint instead of the global one. See the note at the bottom of Signing AWS API requests and AWS STS Regionalized endpoints.

Install

macOS

If you're on macOS you can install saml2aws using homebrew!

brew install saml2aws
saml2aws --version

Windows

If you're on Windows you can install saml2aws using chocolatey!

choco install saml2aws
saml2aws --version

Linux

While brew is available for Linux you can also run the following without using a package manager.

Ubuntu

Some users of Ubuntu have reported issue with the Others Install instruction and reported the following to work (may required using sudo command like for the "mv" function)

CURRENT_VERSION=$(curl -Ls https://api.github.com/repos/Versent/saml2aws/releases/latest | grep 'tag_name' | cut -d'v' -f2 | cut -d'"' -f1)
wget https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws_${CURRENT_VERSION}_linux_amd64.tar.gz
tar -xzvf saml2aws_${CURRENT_VERSION}_linux_amd64.tar.gz
mv saml2aws /usr/local/bin/
chmod u+x /usr/local/bin/saml2aws
saml2aws --version

For U2F support, replace wget line above with wget https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws-u2f_${CURRENT_VERSION}_linux_amd64.tar.gz

Other

mkdir -p ~/.local/bin
CURRENT_VERSION=$(curl -Ls https://api.github.com/repos/Versent/saml2aws/releases/latest | grep 'tag_name' | cut -d'v' -f2 | cut -d'"' -f1)
wget -c "https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws_${CURRENT_VERSION}_linux_amd64.tar.gz" -O - | tar -xzv -C ~/.local/bin
chmod u+x ~/.local/bin/saml2aws
hash -r
saml2aws --version

If saml2aws --version does not work as intended, you may need to update your terminal configuration file (like ~/.bashrc, ~/.profile, ~/.zshrc) to include export PATH="$PATH:$HOME/.local/bin/" at the end of the file.

For U2F support, replace wget line above with wget -c "https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws-u2f_${CURRENT_VERSION}_linux_amd64.tar.gz" -O - | tar -xzv -C ~/.local/bin

Using Make

You will need Go Tools (you can check your package maintainer as well) installed and the Go Lint tool

Clone this repo to your $GOPATH/src directory

Now you can install by running

make
make install

Arch Linux and its derivatives

The saml2aws tool is available in AUR (saml2aws-bin), so you can install it using an available AUR helper:

  • Manjaro: $ pamac build saml2aws-bin

If you are on Void Linux you can use xbps to install the saml2aws package!

xbps-install saml2aws

Autocomplete

saml2aws can generate completion scripts.

Bash

Add the following line to your .bash_profile (or equivalent):

eval "$(saml2aws --completion-script-bash)"

Zsh

Add the following line to your .zshrc (or equivalent):

eval "$(saml2aws --completion-script-zsh)"

Dependency Setup

Install the AWS CLI see, in our case we are using homebrew on macOS.

brew install awscli

Usage

usage: saml2aws [<flags>] <command> [<args> ...]

A command line tool to help with SAML access to the AWS token service.

Flags:
      --help                   Show context-sensitive help (also try --help-long and --help-man).
      --version                Show application version.
      --verbose                Enable verbose logging
      --quiet                  silences logs
  -i, --provider=PROVIDER      This flag is obsolete. See: https://github.com/Versent/saml2aws#configuring-idp-accounts
      --config=CONFIG          Path/filename of saml2aws config file (env: SAML2AWS_CONFIGFILE)
  -a, --idp-account="default"  The name of the configured IDP account. (env: SAML2AWS_IDP_ACCOUNT)
      --idp-provider=IDP-PROVIDER
                               The configured IDP provider. (env: SAML2AWS_IDP_PROVIDER)
      --mfa=MFA                The name of the mfa. (env: SAML2AWS_MFA)
  -s, --skip-verify            Skip verification of server certificate. (env: SAML2AWS_SKIP_VERIFY)
      --url=URL                The URL of the SAML IDP server used to login. (env: SAML2AWS_URL)
      --username=USERNAME      The username used to login. (env: SAML2AWS_USERNAME)
      --password=PASSWORD      The password used to login. (env: SAML2AWS_PASSWORD)
      --mfa-token=MFA-TOKEN    The current MFA token (supported in Keycloak, ADFS, GoogleApps). (env: SAML2AWS_MFA_TOKEN)
      --role=ROLE              The ARN of the role to assume. (env: SAML2AWS_ROLE)
      --aws-urn=AWS-URN        The URN used by SAML when you login. (env: SAML2AWS_AWS_URN)
      --skip-prompt            Skip prompting for parameters during login.
      --session-duration=SESSION-DURATION
                               The duration of your AWS Session. (env: SAML2AWS_SESSION_DURATION)
      --disable-keychain       Do not use keychain at all. This will also disable Okta sessions & remembering MFA device. (env: SAML2AWS_DISABLE_KEYCHAIN)
  -r, --region=REGION          AWS region to use for API requests, e.g. us-east-1, us-gov-west-1, cn-north-1 (env: SAML2AWS_REGION)
      --prompter=PROMPTER      The prompter to use for user input (default, pinentry)

Commands:
  help [<command>...]
    Show help.


  configure [<flags>]
    Configure a new IDP account.

        --app-id=APP-ID            OneLogin app id required for SAML assertion. (env: ONELOGIN_APP_ID)
        --client-id=CLIENT-ID      OneLogin client id, used to generate API access token. (env: ONELOGIN_CLIENT_ID)
        --client-secret=CLIENT-SECRET
                                   OneLogin client secret, used to generate API access token. (env: ONELOGIN_CLIENT_SECRET)
        --subdomain=SUBDOMAIN      OneLogin subdomain of your company account. (env: ONELOGIN_SUBDOMAIN)
        --mfa-ip-address=MFA-IP-ADDRESS
                                   IP address whitelisting defined in OneLogin MFA policies. (env: ONELOGIN_MFA_IP_ADDRESS)
    -p, --profile=PROFILE          The AWS profile to save the temporary credentials. (env: SAML2AWS_PROFILE)
        --resource-id=RESOURCE-ID  F5APM SAML resource ID of your company account. (env: SAML2AWS_F5APM_RESOURCE_ID)
        --credentials-file=CREDENTIALS-FILE
                                   The file that will cache the credentials retrieved from AWS. When not specified, will use the default AWS credentials file location. (env: SAML2AWS_CREDENTIALS_FILE)
        --cache-saml               Caches the SAML response (env: SAML2AWS_CACHE_SAML)
        --cache-file=CACHE-FILE    The location of the SAML cache file (env: SAML2AWS_SAML_CACHE_FILE)
        --disable-sessions         Do not use Okta sessions. Uses Okta sessions by default. (env: SAML2AWS_OKTA_DISABLE_SESSIONS)
        --disable-remember-device  Do not remember Okta MFA device. Remembers MFA device by default. (env: SAML2AWS_OKTA_DISABLE_REMEMBER_DEVICE)

  login [<flags>]
    Login to a SAML 2.0 IDP and convert the SAML assertion to an STS token.

    -p, --profile=PROFILE        The AWS profile to save the temporary credentials. (env: SAML2AWS_PROFILE)
        --duo-mfa-option=DUO-MFA-OPTION
                                 The MFA option you want to use to authenticate with (supported providers: okta). (env: SAML2AWS_DUO_MFA_OPTION)
        --client-id=CLIENT-ID    OneLogin client id, used to generate API access token. (env: ONELOGIN_CLIENT_ID)
        --client-secret=CLIENT-SECRET
                                 OneLogin client secret, used to generate API access token. (env: ONELOGIN_CLIENT_SECRET)
        --mfa-ip-address=MFA-IP-ADDRESS
                                 IP address whitelisting defined in OneLogin MFA policies. (env: ONELOGIN_MFA_IP_ADDRESS)
        --force                  Refresh credentials even if not expired.
        --credential-process     Enables AWS Credential Process support by outputting credentials to STDOUT in a JSON message.
        --credentials-file=CREDENTIALS-FILE
                                 The file that will cache the credentials retrieved from AWS. When not specified, will use the default AWS credentials file location. (env: SAML2AWS_CREDENTIALS_FILE)
        --cache-saml             Caches the SAML response (env: SAML2AWS_CACHE_SAML)
        --cache-file=CACHE-FILE  The location of the SAML cache file (env: SAML2AWS_SAML_CACHE_FILE)
        --download-browser-driver  Automatically download browsers for Browser IDP. (env: SAML2AWS_AUTO_BROWSER_DOWNLOAD)
        --disable-sessions         Do not use Okta sessions. Uses Okta sessions by default. (env: SAML2AWS_OKTA_DISABLE_SESSIONS)
        --disable-remember-device  Do not remember Okta MFA device. Remembers MFA device by default. (env: SAML2AWS_OKTA_DISABLE_REMEMBER_DEVICE)

  exec [<flags>] [<command>...]
    Exec the supplied command with env vars from STS token.

    -p, --profile=PROFILE      The AWS profile to save the temporary credentials. (env: SAML2AWS_PROFILE)
        --exec-profile=EXEC-PROFILE
                               The AWS profile to utilize for command execution. Useful to allow the aws cli to perform secondary role assumption. (env: SAML2AWS_EXEC_PROFILE)
        --credentials-file=CREDENTIALS-FILE
                               The file that will cache the credentials retrieved from AWS. When not specified, will use the default AWS credentials file location. (env: SAML2AWS_CREDENTIALS_FILE)

  console [<flags>]
    Console will open the aws console after logging in.

        --exec-profile=EXEC-PROFILE
                               The AWS profile to utilize for console execution. (env: SAML2AWS_EXEC_PROFILE)
    -p, --profile=PROFILE      The AWS profile to save the temporary credentials. (env: SAML2AWS_PROFILE)
        --force                Refresh credentials even if not expired.
        --link                 Present link to AWS console instead of opening browser
        --credentials-file=CREDENTIALS-FILE
                               The file that will cache the credentials retrieved from AWS. When not specified, will use the default AWS credentials file location. (env: SAML2AWS_CREDENTIALS_FILE)

  list-roles
    List available role ARNs.
        --cache-saml             Caches the SAML response (env: SAML2AWS_CACHE_SAML)
        --cache-file=CACHE-FILE  The location of the SAML cache file (env: SAML2AWS_SAML_CACHE_FILE)


  script [<flags>]
    Emit a script that will export environment variables.

    -p, --profile=PROFILE      The AWS profile to save the temporary credentials. (env: SAML2AWS_PROFILE)
        --credentials-file=CREDENTIALS-FILE
                               The file that will cache the credentials retrieved from AWS. When not specified, will use the default AWS credentials file location. (env: SAML2AWS_CREDENTIALS_FILE)
        --shell=bash           Type of shell environment. Options include: bash, /bin/sh, powershell, fish, env


saml2aws script

If the script sub-command is called, saml2aws will output the following temporary security credentials:

export AWS_ACCESS_KEY_ID="ASIAI....UOCA"
export AWS_SECRET_ACCESS_KEY="DuH...G1d"
export AWS_SESSION_TOKEN="AQ...1BQ=="
export AWS_SECURITY_TOKEN="AQ...1BQ=="
export AWS_CREDENTIAL_EXPIRATION="2016-09-04T38:27:00Z00:00"
SAML2AWS_PROFILE=saml

Powershell, sh and fish shells are supported as well. Env is useful for all AWS SDK compatible tools that can source an env file. It is a powerful combo with docker and the --env-file parameter.

If you use eval $(saml2aws script) frequently, you may want to create a alias for it:

zsh:

alias s2a="function(){eval $( $(command saml2aws) script --shell=bash --profile=$@);}"

bash:

function s2a { eval $( $(which saml2aws) script --shell=bash --profile=$@); }

env:

docker run -ti --env-file <(saml2aws script --shell=env) amazon/aws-cli s3 ls

saml2aws exec

If the exec sub-command is called, saml2aws will execute the command given as an argument: By default saml2aws will execute the command with temp credentials generated via saml2aws login.

The --exec-profile flag allows for a command to execute using an aws profile which may have chained "assume role" actions. (via 'source_profile' in ~/.aws/config)

options:
--exec-profile           Execute the given command utilizing a specific profile from your ~/.aws/config file

Configuring IDP Accounts

This is the new way of adding IDP provider accounts, it enables you to have named accounts with whatever settings you like and supports having one default account which is used if you omit the account flag. This replaces the --provider flag and old configuration file in 1.x.

To add a default IdP account to saml2aws just run the following command and follow the prompts.

$ saml2aws configure
? Please choose a provider: Ping
? AWS Profile myaccount

? URL https://example.com
? Username [email protected]

? Password
No password supplied

account {
  URL: https://example.com
  Username: [email protected]
  Provider: Ping
  MFA: Auto
  SkipVerify: false
  AmazonWebservicesURN: urn:amazon:webservices
  SessionDuration: 3600
  Profile: myaccount
  Region: us-east-1
}

Configuration saved for IDP account: default

Then to login using this account.

saml2aws login

You can also add named accounts, below is an example where I am setting up an account under the wolfeidau alias, again just follow the prompts.

saml2aws configure -a wolfeidau

You can also configure the account alias without prompts.

saml2aws configure -a wolfeidau --idp-provider KeyCloak --username [email protected] -r cn-north-1  \
  --url https://keycloak.wolfe.id.au/auth/realms/master/protocol/saml/clients/amazon-aws --skip-prompt

Then your ready to use saml2aws.

Example

Log into a service (without MFA).

$ saml2aws login
Using IDP Account default to access Ping https://id.example.com
To use saved password just hit enter.
Username [[email protected]]:
Password: ************

Authenticating as [email protected] ...
Selected role: arn:aws:iam::123123123123:role/AWS-Admin-CloudOPSNonProd
Requesting AWS credentials using SAML assertion
Saving credentials
Logged in as: arn:aws:sts::123123123123:assumed-role/AWS-Admin-CloudOPSNonProd/[email protected]

Your new access key pair has been stored in the AWS configuration
Note that it will expire at 2016-09-19 15:59:49 +1000 AEST
To use this credential, call the AWS CLI with the --profile option (e.g. aws --profile saml ec2 describe-instances).

Log into a service (with MFA).

$ saml2aws login
Using IDP Account default to access Ping https://id.example.com
To use saved password just hit enter.
Username [[email protected]]:
Password: ************

Authenticating as [email protected] ...
Enter passcode: 123456

Selected role: arn:aws:iam::123123123123:role/AWS-Admin-CloudOPSNonProd
Requesting AWS credentials using SAML assertion
Saving credentials
Logged in as: arn:aws:sts::123123123123:assumed-role/AWS-Admin-CloudOPSNonProd/[email protected]

Your new access key pair has been stored in the AWS configuration
Note that it will expire at 2016-09-19 15:59:49 +1000 AEST
To use this credential, call the AWS CLI with the --profile option (e.g. aws --profile saml ec2 describe-instances --region us-east-1).

Advanced Configuration

Windows Subsystem Linux (WSL) Configuration

If you are using WSL1 or WSL2, you might get the following error when attempting to save the credentials into the keychain

 No such interface โ€œorg.freedesktop.DBus.Propertiesโ€ on object at path /

This happens because the preferred keyring back-end - uses the gnome-keyring by default - which requires X11 - and if you are not using Windows 11 with support for Linux GUI applications - this can be difficult without configuring a X11 forward.

There are 2 preferred approaches to workaround this issue:

Option 1: Disable Keychain

You can apply the --disable-keychain flag when using both the configure and login commands. Using this flag means that your credentials (such as your password to your IDP, or in the case of Okta the Okta Session Token) will not save to your keychain - and be skipped entierly. This means you will be required to enter your username and password each time you invoke the login command.

Option 2: Configure Pass to be the default keyring

There are a few steps involved with this option - however this option will save your credentials (such as your password to your IDP, and session tokens etc) into the pass[https://www.passwordstore.org/] keyring. The pass keyring is the standard Unix password manager. This option was heavily inspired by a similar issue in aws-vault

To configure pass to be the default keyring the following steps will need to be completed (assuming you are using Ubuntu 20.04 LTS):

  1. Install the pass backend and update gnupg, which encrypts passwords
sudo apt-get update && sudo apt-get install -y pass gnupg
  1. Generate a key with gpg (gnupg) and take note of your public key
gpg --gen-key

The output of the gpg command will output the something similar to the following:

public and secret key created and signed.

pub   rsa3072 2021-04-22 [SC] [expires: 2023-04-22]
      844E426A53A64C2A916CBD1F522014D5FDBF6E3D
uid                      Meir Gabay <[email protected]>
sub   rsa3072 2021-04-22 [E] [expires: 2023-04-22]
  1. Create a storage key in pass from the previously generated public (pub) key
pass init <GPG_PUBLIC_KEY>

during the init process you'll be requested to enter the passphrase provided in step 2

  1. Now, configure saml2aws to use the pass keyring. This can be done by setting the SAML2AWS_KEYRING_BACKEND environment variable to be pass. You'll need to also set the GPG_TTY to your current tty which means you can set the variable to "$( tty )"

which means the following can be added into your profile

export SAML2AWS_KEYRING_BACKEND=pass
export GPG_TTY="$( tty )"
  1. Profit! Now when you run login/configure commands - you'll be promoted once to enter your passphrase - and your credentials will be saved into your keyring!

Configuring Multiple Accounts

Configuring multiple accounts with custom role and profile in ~/.aws/config with goal being isolation between infra code when deploying to these environments. This setup assumes you're using separate roles and probably AWS accounts for dev and test and is designed to help operations staff avoid accidentally deploying to the wrong AWS account in complex environments. Note that this method configures SAML authentication to each AWS account directly (in this case different AWS accounts). In the example below, separate authentication values are configured for AWS accounts 'profile=customer-dev/awsAccount=was 121234567890' and 'profile=customer-test/awsAccount=121234567891'

Dev Account Setup

To setup the dev account run the following and enter URL, username and password, and assign a standard role to be automatically selected on login.

saml2aws configure -a customer-dev --role=arn:aws:iam::121234567890:role/customer-admin-role -p customer-dev

This will result in the following configuration in ~/.saml2aws.

[customer-dev]
url                     = https://id.customer.cloud
username                = [email protected]
provider                = Ping
mfa                     = Auto
skip_verify             = false
timeout                 = 0
aws_urn                 = urn:amazon:webservices
aws_session_duration    = 28800
aws_profile             = customer-dev
role_arn                = arn:aws:iam::121234567890:role/customer-admin-role
region                  = us-east-1

To use this you will need to export AWS_DEFAULT_PROFILE=customer-dev environment variable to target dev.

Test Account Setup

To setup the test account run the following and enter URL, username and password.

saml2aws configure -a customer-test --role=arn:aws:iam::121234567891:role/customer-admin-role -p customer-test

This results in the following configuration in ~/.saml2aws.

[customer-test]
url                     = https://id.customer.cloud
username                = [email protected]
provider                = Ping
mfa                     = Auto
skip_verify             = false
timeout                 = 0
aws_urn                 = urn:amazon:webservices
aws_session_duration    = 28800
aws_profile             = customer-test
role_arn                = arn:aws:iam::121234567891:role/customer-admin-role
region                  = us-east-1

To use this you will need to export AWS_DEFAULT_PROFILE=customer-test environment variable to target test.

Playwright Browser Drivers for Browser IDP

If you are using the Browser Identity Provider, on first invocation of saml2aws login you need to remember to install the browser drivers in order for playwright-go to work. Otherwise you will see the following error message:

Error authenticating to IDP.: could not start driver: fork/exec ... no such file or directory

To install the drivers, you can:

  • Pass --download-browser-driver to saml2aws login
  • Set in your shell environment SAML2AWS_AUTO_BROWSER_DOWNLOAD=true
  • Set download_browser_driver = true in your saml2aws config file, i.e. ~/.saml2aws

Advanced Configuration (Multiple AWS account access but SAML authenticate against a single 'SSO' AWS account)

Example: (Authenticate to my 'SSO' AWS account. With this setup, there is no need to authenticate again. We can now rely on IAM to assume role cross account)

~/.aws/credentials: #(these are generated by saml2aws login. Sets up SAML authentication into my AWS 'SSO' account)

[saml]
aws_access_key_id        = AAAAAAAAAAAAAAAAB
aws_secret_access_key    = duqhdZPRjEdZPRjE=dZPRjEhKjfB
aws_session_token        = #REMOVED#
aws_security_token       = #REMOVED#
x_principal_arn          = arn:aws:sts::000000000123:assumed-role/myInitialAccount
x_security_token_expires = 2019-08-19T15:00:56-06:00

(Use AWS profiles to assume an aws role cross-account) (Note that the "source_profile" is set to SAML which is my SSO AWS account since it is already authenticated)

~/.aws/config:

[profile roleIn2ndAwsAccount]
source_profile=saml
role_arn=arn:aws:iam::123456789012:role/OtherRoleInAnyFederatedAccount # Note the different account number here
role_session_name=myAccountName

[profile extraRroleIn2ndAwsAccount]
# this profile uses a _third_ level of role assumption
source_profile=roleIn2ndAwsAccount
role_arn=arn:aws:iam::123456789012:role/OtherRoleInAnyFederatedAccount

Running saml2aws without --exec-profile flag:

saml2aws exec aws sts get-caller-identity
{
    "UserId": "AROAYAROAYAROAYOO:myInitialAccount",
    "Account": "000000000123",
    "Arn": "arn:aws:sts::000000000123:assumed-role/myInitialAccount"  # This shows my 'SSO' account (SAML profile)
}

Running saml2aws with --exec-profile flag:

When using '--exec-profile' I can assume-role into a different AWS account without re-authenticating. Note that it does not re-authenticate since we are already authenticated via the SSO account.

saml2aws exec --exec-profile roleIn2ndAwsAccount aws sts get-caller-identity
{
    "UserId": "YOOYOOYOOYOOYOOA:/myAccountName",
    "Account": "123456789012",
    "Arn": "arn:aws:sts::123456789012:assumed-role/myAccountName"
}

As an example

saml2aws login

aws s3 ls --profile saml

An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied
# This is denied in this example because there are no S3 buckets in the 'SSO' AWS account

saml2aws exec --exec-profile roleIn2ndAwsAccount aws s3 ls  # Runs given CMD with environment configured from --exec-profile role

# If we check env variables we see that our environment is configured with temporary credentials for our 'assumed role'
env | grep AWS
AWS_SESSION_TTL=12h
AWS_FEDERATION_TOKEN_TTL=12h
AWS_ASSUME_ROLE_TTL=1h
AWS_ACCESS_KEY_ID=AAAAAAAASORTENED
AWS_SECRET_ACCESS_KEY=secretShortened+6jJ5SMqsM5CkYi3Gw7
AWS_SESSION_TOKEN=ShortenedTokenXXX=
AWS_SECURITY_TOKEN=ShortenedSecurityTokenXXX=
AWS_CREDENTIAL_EXPIRATION=2016-09-04T38:27:00Z00:00

# If we desire to execute multiple commands utilizing our assumed profile, we can obtain a new shell with Env variables configured for access

saml2aws exec --exec-profile roleIn2ndAwsAccount $SHELL  # Get a new shell with AWS env vars configured for 'assumed role' account access

# We are now able to execute AWS cli commands with our assume role permissions

# Note that we do not need a --profile flag because our environment variables were set up for this access when we obtained a new shell with the --exec-profile flag

aws s3 ls
2019-07-30 01:32:59 264998d7606497040-sampleBucket

aws iam list-groups
{
    "Groups": [
        {
            "Path": "/",
            "GroupName": "MyGroup",
            "GroupId": "AGAGTENTENTENGOCQFK",
            "Arn": "arn:aws:iam::123456789012:group/MyGroup",
            "CreateDate": "2019-05-13T16:12:19Z"
            ]
        }
}

Advanced Configuration - additional parameters

There are few additional parameters allowing to customise saml2aws configuration. Use following parameters in ~/.saml2aws file:

  • http_attempts_count - configures the number of attempts to send http requests in order to authorise with saml provider. Defaults to 1
  • http_retry_delay - configures the duration (in seconds) of timeout between attempts to send http requests to saml provider. Defaults to 1
  • region - configures which region endpoints to use, See Audience and partition
  • target_url - look for a target endpoint other than signin.aws.amazon.com/saml. The Okta, Pingfed, Pingone and Shibboleth ECP providers need to either explicitly send or look for this URL in a response in order to obtain or identify an appropriate authentication response. This can be overridden here if you wish to authenticate for something other than AWS.

Example: typical configuration with such parameters would look like follows:

[default]
url                     = https://id.customer.cloud
username                = [email protected]
provider                = Ping
mfa                     = Auto
skip_verify             = false
timeout                 = 0
aws_urn                 = urn:amazon:webservices
aws_session_duration    = 28800
aws_profile             = customer-dev
role_arn                = arn:aws:iam::121234567890:role/customer-admin-role
http_attempts_count     = 3
http_retry_delay        = 1
region                  = us-east-1

Building

macOS

To build this software on macOS, clone the repo to $GOPATH/src/github.com/versent/saml2aws and ensure you have $GOPATH/bin in your $PATH. You will also need GoReleaser installed.

make mod

Install the binary to $GOPATH/bin.

make install

Then to test the software just run.

make test

Before raising a PR please run the linter.

make lint-fix

Linux

To build this software on Debian/Ubuntu, you need to install a build dependency:

sudo apt install libudev-dev

You also need GoReleaser installed, and the binary (or a symlink) in bin/goreleaser.

ln -s $(command -v goreleaser) bin/goreleaser

Then you can build:

make build

Environment vars

The exec sub command will export the following environment variables.

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_SESSION_TOKEN
  • AWS_SECURITY_TOKEN
  • EC2_SECURITY_TOKEN
  • AWS_PROFILE
  • AWS_DEFAULT_PROFILE
  • AWS_CREDENTIAL_EXPIRATION

Note: That profile environment variables enable you to use exec with a script or command which requires an explicit profile.

Dependencies

This tool would not be possible without some great opensource libraries.

Releasing

  1. Create a git tag locally with git tag -as vX.X.X
  2. Run build with make build
  3. Test the newly created binary nested in the dist/ of the project root directory
  4. If testing pass, push the tag git push origin vX.X.X
  5. Make an announcement in "Discussions"

Debugging Issues with IDPs

There are two levels of debugging, first emits debug information and the URL / Method / Status line of requests.

saml2aws login --verbose

The second emits the content of requests and responses, this includes authentication related information so don't copy and paste it into chat or tickets!

DUMP_CONTENT=true saml2aws login --verbose

Using saml2aws as credential process

Credential Process is a convenient way of interfacing credential providers with the AWS Cli.

You can use saml2aws as a credential provider by simply configuring it and then adding a profile to the AWS configuration. saml2aws has a flag --credential-process generating an output with the right JSON format.

The AWS credential file (typically ~/.aws/credentials) has precedence over the credential_process provider. That means that if credentials are present in the file, the credential process will not trigger.

An example of the aws configuration (~/.aws/config):

[profile mybucket]
region = us-west-1
credential_process = saml2aws login --credential-process --role <ROLE> --profile mybucket

You can add this manually or via the awscli, i.e.

aws configure set credential_process "saml2aws login --credential-process --role <ROLE> --profile mybucket"

When using the aws cli with the mybucket profile, the authentication process will be run and the aws will then be executed based on the returned credentials.

Caching the saml2aws SAML assertion for immediate reuse

You can use the flag --cache-saml in order to cache the SAML assertion at authentication time. The SAML assertion cache has a very short validity (5 min) and can be used to authenticate to several roles with a single MFA validation.

there is a file per saml2aws profile, the cache directory is called saml2aws and is located in your .aws directory in your user homedir.

You can toggle --cache-saml during login or during list-roles, and you can set it once during configure and use it implicitly.

Okta Sessions

This requires the use of the keychain (local credentials store). If you disabled the keychain using --disable-keychain, Okta sessions will also be disabled.

Okta sessions are enabled by default. This will store the Okta session locally and save your device for MFA. This means that if the session has not yet expired, you will not be prompted for MFA.

  • To disable remembering the device, you can toggle --disable-remember-device during login or configure commands.
  • To disable using Okta sessions, you can toggle --disable-sessions during login or configure commands.
    • This will also disable the Okta MFA remember device feature

Use the --force flag during login command to prompt for AWS role selection.

If Okta sessions are disabled via any of the methods mentioned above, the login process will default to the standard authentication process (without using sessions).

Please note that your Okta session duration and MFA policies are governed by your Okta host organization.

License

This code is Copyright (c) 2018 Versent and released under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.

saml2aws's People

Contributors

acobaugh avatar alsmola avatar anton0 avatar briantist avatar chris-reeves avatar christianmeyer avatar ctennis avatar davidobrien1985 avatar dependabot[bot] avatar duckfez avatar elicopilot avatar gliptak avatar himanshu-neema avatar ilya-v-trofimov avatar kstkn avatar lizduty avatar logingood avatar mapkon avatar mcleane avatar munkyboy avatar muramasa64 avatar silver886 avatar six-arm avatar sledigabel avatar srizzling avatar tinaboyce avatar vacovsky avatar wlonkly avatar wolfeidau avatar xinkecf35 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  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

saml2aws's Issues

saml2aws exec without storing profile

It would be great to be able to use "saml2aws exec" without storing the credentials to the config but using only env.

So it would be possible to start multiple "saml2aws exec bash" with different roles.

ADFS2 can't find IDP authentication form submit URL

Trying to auth to ADFS v2 environment and getting the following using version 1.4.0. I don't control/have access to ADFS. Let me know if there is anything else I can try for you.

C:\Users\jbruett>saml2aws --profile ADFS2 login
Hostname []: adfs.******.com
Username []: jbruett
Password: ***********

ADFS https://adfs.******.com
Authenticating to ADFS...
main.go:66: error authenticating to adfs: unable to locate IDP authentication form submit URL

C:\Users\jbruett>saml2aws --profile ADFS2 login
Hostname []: adfs.****.com/adfs/ls/IdpInitiatedSignon.aspx
Username []: jbruett
Password: ***********

ADFS https://adfs.******.com/adfs/ls/IdpInitiatedSignon.aspx
Authenticating to ADFS...
main.go:66: error authenticating to adfs: unable to locate IDP authentication form submit URL

C:\Users\jbruett>saml2aws --profile ADFS2 login
Hostname []: adfs..com
Username []: jbruett@
.com
Password: ***********

ADFS https://adfs.******.com
Authenticating to ADFS...
main.go:66: error authenticating to adfs: unable to locate IDP authentication form submit URL

C:\Users\jbruett>saml2aws --profile ADFS2 login
Hostname []: adfs..com/adfs/ls/IdpInitiatedSignon.aspx
Username []: jbruett@
.com
Password: ***********

ADFS https://adfs.******.com/adfs/ls/IdpInitiatedSignon.aspx
Authenticating to ADFS...
main.go:66: error authenticating to adfs: unable to locate IDP authentication form submit URL

saml2aws -i Ping does a segmentation violation and fails

saml2aws -p saml -i Ping login

Ping https://xxxx.xxxx.xx
Authenticating to Ping...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x13e46ea]

goroutine 1 [running]:
github.com/versent/saml2aws.(*PingFedClient).Authenticate(0xc42000e1d8, 0xc420146a20, 0xc42000e1d8, 0x0, 0x0, 0x1a)
/Users/markw/Code/go/src/github.com/versent/saml2aws/pingfed.go:102 +0x4ca
github.com/versent/saml2aws/cmd/saml2aws/commands.Login(0x7fff5fbffc04, 0x4, 0x7fff5fbffc0c, 0x4, 0x14cd400, 0x5, 0x0)
/Users/markw/Code/go/src/github.com/versent/saml2aws/cmd/saml2aws/commands/login.go:46 +0x398
main.main()
/Users/markw/Code/go/src/github.com/versent/saml2aws/cmd/saml2aws/main.go:60 +0x29c

Okta login issue

I am able to login to the web app using this URL, but I am getting this error when using the script.


Authenticating as ...
time="2017-12-05T14:24:45-05:00" level=debug msg="building provider" command=login idpAccount="&{https://e.oktapreview.com/home/amazon_aws/0oab5djefnTb4cMht0h7/137 Okta Auto true 0 urn:amazon:webservices}"
Response did not contain a valid SAML assertion
Please check your username and password is correct

saml2aws exec not honouring command line login options when credential file has valid STS token

Please see console output below for steps to reproduce.
Points to note:

  • Login details redacted, but faithfully so as to still highlight the observed behaviour
  • ~/.aws/credential file was present (but empty) before first invocation of exec
  • second invocation of exec was done immediately after the first, so there was no chance of STS token expiry
  • the requested role of first invocation of exec is AcmeRole1, while for the second invocation it's AcmeRole2
  • both invocations of exec end up running as the same role, namely AcmeRole1
[centos@localhost ~]$ saml2aws -i KeyCloak --hostname="id.acme.com/auth/realms/acme/protocol/saml/clients/amazon-aws" --username="joe.bloggs" --password="${SAML2AWS_PASSWORD}" --role="arn:aws:iam::012345678910:role/AcmeRole1" --skip-prompt exec aws sts get-caller-identity

Authenticating as joe.bloggs to KeyCloak https://id.acme.com/auth/realms/acme/protocol/saml/clients/amazon-aws
Selected role: arn:aws:iam::012345678910:role/AcmeRole1
Requesting AWS credentials using SAML assertion
Logged in as: arn:aws:sts::012345678910:assumed-role/AcmeRole1/joe.bloggs
Your new access key pair has been stored in the AWS configuration
Note that it will expire at 2017-09-08 00:35:28 +1000 AEST
To use this credential, call the AWS CLI with the --profile option (e.g. aws --profile saml ec2 describe-instances).
Saving config: /home/centos/.aws2saml.config

{
    "Account": "012345678910", 
    "UserId": "ABCDEF123456GHIJKLMN0:joe.bloggs", 
    "Arn": "arn:aws:sts::012345678910:assumed-role/AcmeRole1/joe.bloggs"
}

[centos@localhost ~]$ saml2aws -i KeyCloak --hostname="id.acme.com/auth/realms/acme/protocol/saml/clients/amazon-aws" --username="joe.bloggs" --password="${SAML2AWS_PASSWORD}" --role="arn:aws:iam::012345678910:role/AcmeRole2" --skip-prompt exec aws sts get-caller-identity

Running command as: arn:aws:sts::012345678910:assumed-role/AcmeRole1/joe.bloggs

{
    "Account": "012345678910", 
    "UserId": "ABCDEF123456GHIJKLMN0:joe.bloggs", 
    "Arn": "arn:aws:sts::012345678910:assumed-role/AcmeRole1/joe.bloggs"
}

Expected behaviour is that the second (and any) invocation of exec would run under the requested role in the command line options (i.e. AcmeRole2 in the case of the second invocation above)

GovCloud Support

Would be great if this worked with us-gov-west-1, which has a different urn (amazon:webservices:govcloud) and uses a different sts endpoint. I tried changing the urn in the ADFS provider and re-building, but I was still directed to the public endpoints and got a role from the public side.

Can't login if user has only one IAM role

Users can't login to AWS if they are configured in the IdP with a single IAM role only.

If a user is configured with only a single IAM role in the IdP, saml2aws used to log the user in without prompting them to select a role. If they have more than one role, they are presented with a list of roles they must select from.

This was working in version 1.7.1 but with 1.8.1 this no longer works. If the user is configured with one role only, they are now prompted to select a role from the list but no list is printed. Entering 0 causes it to crash.

$ saml2aws login --provider=KeyCloak
Adding osx helper
Hostname [hostname.com.au/auth/realms/amp/protocol/saml/clients/amazon-aws]:
To use saved username and password just hit enter.
Username [user]:
Password: **********

Authenticating as user to KeyCloak https://hostname.com.au/auth/realms/amp/protocol/saml/clients/amazon-aws
Please choose the role you would like to assume:
Selection: 0
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/versent/saml2aws.PromptForAWSRoleSelection(0x477cdd8, 0x0, 0x0, 0x477cdd8, 0x0, 0x0)
	/Users/markw/Code/go/src/github.com/versent/saml2aws/input.go:88 +0x602
github.com/versent/saml2aws/cmd/saml2aws/commands.resolveRole(0xc42000e080, 0x1, 0x1, 0xc4204fc000, 0x29d4, 0xc4201461c0, 0x0, 0x0, 0xa0)
	/Users/markw/Code/go/src/github.com/versent/saml2aws/cmd/saml2aws/commands/login.go:220 +0x123
github.com/versent/saml2aws/cmd/saml2aws/commands.Login(0xc4201461c0, 0x5, 0x44d7ab7)
	/Users/markw/Code/go/src/github.com/versent/saml2aws/cmd/saml2aws/commands/login.go:103 +0x4cb
main.main()
	/Users/markw/Code/go/src/github.com/versent/saml2aws/cmd/saml2aws/main.go:73 +0x272

Version: saml2aws version 1.8.1
OS: macOS 10.12.5 (Sierra)
Provider: KeyCloak

login returns error "error loading saved password"

I'm seeing the following error when trying to login. I have previously been able to login.

Adding osx helper
One or more parameters passed to a function were not valid.
error loading saved password
github.com/versent/saml2aws/cmd/saml2aws/commands.resolveLoginDetails
	/Users/markw/Code/go/src/github.com/versent/saml2aws/cmd/saml2aws/commands/login.go:162
github.com/versent/saml2aws/cmd/saml2aws/commands.Login
	/Users/markw/Code/go/src/github.com/versent/saml2aws/cmd/saml2aws/commands/login.go:45
main.main
	/Users/markw/Code/go/src/github.com/versent/saml2aws/cmd/saml2aws/main.go:73
runtime.main
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/proc.go:185
runtime.goexit
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/asm_amd64.s:2197

Version info

โžœ  ~ saml2aws --version
Adding osx helper
1.8.2

Strange console output

saml2aws print a strange output about osx helpers for every command.

$ saml2aws --version
Adding osx helper
1.8.2

Can't read AWS env vars after exec sub command

The readme file says that the exec sub command exports the following environment variables -

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_SESSION_TOKEN
  • AWS_SECURITY_TOKEN
  • EC2_SECURITY_TOKEN

I'm having trouble seeing them.

saml2aws exec --provider=Ping -- echo AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID

returns

Running command as: arn:aws:sts::<blah>:assumed-role/admin/me
AWS_ACCESS_KEY_ID=

I was expecting to be able to see the value of the AWS_ACCESS_KEY_ID environment variable.

Let users enter the one time passcode for ping IdP if possible

Need to figure out if we can accept the passcode and send that to ping.

As reported by @ltrifonov and @rowanu

it fails often after a long inactivity, my android has some aggressive memory management and it kills something, perhaps the ping push listener. The only way to re-activate it is Disable swipe -> confirm, then Enable swipe -> confirm

PITA

saml2aws 2.0 configuration changes and refactor

I am currently working on a refactor of the providers, and a new configuration file.

The goals of this release are:

  1. Enable configurable MFA per provider, to support #50
  2. Refactor all the providers into their own package to enable a bit more protection, and the flexibility to do more in each.
  3. Allow any number of new parameters for providers instead of just skip-verify
  4. A general tidy based on feedback from https://goreportcard.com/report/github.com/versent/saml2aws

This work is ongoing in the master branch but given the breaking config change is last this should be OK.

New configuration will be located at ~/.saml2aws, rather than the current ~/.aws2saml and look something like:

[wolfeidau]
hostname = id.wolfe.id.au
username = [email protected]
provider = keycloak
mfa      = totp

[test123]
hostname = id.whatever.com
username = [email protected]
provider = keycloak
mfa      = sms

There will be a new configure command, similar to the AWS cli which will enable you to setup IDP accounts and give each a name.

Outstanding tasks:

  • Configuration refactor
  • Provider refactor
  • Use the provider flag to highlight configuration changes and point to readme.
  • Update readme
  • Implement timeouts for http client
  • Debug Logging
  • Pre release build

Modify credentials file instead of creating a new one

If the credentials file in the ~/.aws folder is a symlink to some other location, this link is broken after using saml2aws.

So instead of creating a new file, the script should modify the content of the existing one.

--role seems to be ignored

Works

  • Login works with saml2aws login
  • awscli works with multiple profiles defined in ~/.aws/config. For example this non-default profile can be used: aws -p dev ec2 describe-instances.

Does not work

  • Login and specify the same arn role as defined in ~/.aws/config for profile 'dev'. Error message:
Supplied RoleArn not found in saml assertion: <supplied arn role>
Failed to assume role, please check you are permitted to assume the given role for the AWS service

(1) As shown above, I am permitted to assume this role... Or is there a difference with logging in with a arn role specified via --role vs logging in and assuming that same arn role via aws -p?

  • Using the same arn role as defined in ~/.aws/config for profile 'dev' and then execute:
saml2aws exec --role '<arn role copied from aws config>' aws ec2 describe-instances
Running command as: arn:aws:sts::....:assumed-role/..../....

The Running command as: does not show the role specified by the --role parameter. It's even possible to add a bogus text value for the --role parameter, and it still executes with always the same role.

(2) How can I use exec with a different arn role?

Hard to identify Account from selection list if using standard role names

saml2AWS dosen't have the account friendly name as part of the role selection list. This can make it hard to select the role you require if standard role names have been used across your aws accounts.
eg

[ 0 ]:  arn:aws:iam::123123123123:role/admin
[ 1 ]:  arn:aws:iam::123123123123:role/developer
[ 2 ]:  arn:aws:iam::456456456456:role/admin
[ 3 ]:  arn:aws:iam::456456456456:role/developer
[ 4 ]:  arn:aws:iam::789789789789:role/admin

The AWS saml signin page will display the account alias as part of the role selection.

Select a role:
Account: example-cloudops (123123123123)
admin
developer
Account: example-digital-nonprod (456456456456)
admin
developer
Account: example-digital-prod (789789789789)
admin

SAML Role AttribueValue order imporant otherwise selection list dosen't include role

saml2AWS expects the SAML Role (https://aws.amazon.com/SAML/Attributes/Role) AttributeValue to be formated as saml-provider,role
eg arn:aws:iam::456456456456:saml-provider/example-idp,arn:aws:iam::456456456456:role/admin
otherwise if the order is reveresed the role selection list displays as follows:

Please choose the role you would like to assume:
[ 0 ]:  arn:aws:iam::123123123123:saml-provider/example-idp
[ 1 ]:  arn:aws:iam::123123123123:saml-provider/example-idp
[ 2 ]:  arn:aws:iam::123123123123:saml-provider/example-idp
[ 3 ]:  arn:aws:iam::123123123123:saml-provider/example-idp
[ 4 ]:  arn:aws:iam::123123123123:saml-provider/example-idp

AWS do not mandate an order for for the Role Attribute Value in the SAML assertion, as such identity providers can populate this attribute in any order and AWS will still be able to process the information. saml2AWS should follow the same behaviour.

Ability to configure session expiry time

Currently when authenticating, the resulting credentials are only valid for an hour. Is there a way to configure this value so that we could have credentials expire after 6 hours?

When we first configured access to our AWS console via ADFS we were able to set up a claim rule that specified how long the session should last (see this AWS blog post for more info). It would be great if saml2aws could use of this same claim rule.

Ability for multiple hostnames in .aws2saml.conf file

Would it be possible to create the option to have multiple hostnames for a single provider? Example if you have different roles and you wanted to switch between them with SAML2AWS you have to enter a different hostname in each time. If there was a way to read the config file with hostnames that you wanted to regularly use that would make things really easy for switch authenticating.

Additional attributes to associate with an IDP account (optionally)

Hi,

We have many clients so this new ability to save configurations per idp is awesome, but it still places the AWS session token into the default profile.

You can override it on the command line
~/go/bin/saml2aws --idp-account=somecustomer --profile somecustomer_saml login

But it would be good if profile could be saved into the idp configuration also, allowing.
~/go/bin/saml2aws --idp-account=somecustomer login

I understand this may not be needed by everyone so I think it should be optional.

saved username is not used

While the username is listed in the ~/.awas2saml.config file

Still getting prompted for username ( and not offered as a default value )

secondly, would like to skip prompt for hostname and username and only prompt for password.

using version 1.8.3

Write diagnostic output to stderr

Prompts and auth details should be written to stdout.

This is especially important when using the exec variant as I want to pipe the output of the subcommand ignoring the saml2aws output.

Cater for MFA status of MFA_ENROLL (Okta)

With Okta, if no factors have been enrolled, assertion is assumed and fails with error:
"Response did not contain a valid SAML assertion"

This is the status from the response

"status\":\"MFA_ENROLL\"

Maybe just need a nice message to the user to go to Okta and enroll some new MFA types

Output too verbose and misleading

The latest release has verbose output and behaves strangely when no username was saved before:

[hoegertn@MacBook-Pro Downloads]$ ./saml2aws login --role="arn:aws:iam::123456789012:role/ADFS-Test"
adding osx helper
LookupCredentials <ADFS-URL>
hostname <ADFS-URL>
Using saved username
Using saved password
savedUsername
Hostname [<ADFS-URL>]:
To use saved username and password just hit enter.
Username []:
Username []: someusername
Password: ********

Authenticating to ADFS with URL https://<ADFS-URL>
Selected role: arn:aws:iam::123456789012:role/ADFS-Test
Requesting AWS credentials using SAML assertion
Saving credentials
Logged in as: arn:aws:sts::123456789012:assumed-role/ADFS-Test/someusername

Your new access key pair has been stored in the AWS configuration
Note that it will expire at 2017-07-27 15:08:08 +0200 CEST
To use this credential, call the AWS CLI with the --profile option (e.g. aws --profile saml ec2 describe-instances).
Saving config: /Users/hoegertn/.aws2saml.config

Second try:

[hoegertn@MacBook-Pro Downloads]$ ./saml2aws login --role="arn:aws:iam::123456789012:role/ADFS-Test"
adding osx helper
LookupCredentials <ADFS-URL>
hostname <ADFS-URL>
Using saved username
Using saved password
savedUsername someusername
Hostname [<ADFS-URL>]:
To use saved username and password just hit enter.
Username [someusername]:
Password: ********

Authenticating to ADFS with URL https://<ADFS-URL>
Selected role: arn:aws:iam::123456789012:role/ADFS-Test
Requesting AWS credentials using SAML assertion
Saving credentials
Logged in as: arn:aws:sts::123456789012:assumed-role/ADFS-Test/someusername

Your new access key pair has been stored in the AWS configuration
Note that it will expire at 2017-07-27 15:08:24 +0200 CEST
To use this credential, call the AWS CLI with the --profile option (e.g. aws --profile saml ec2 describe-instances).
Saving config: /Users/hoegertn/.aws2saml.config
[hoegertn@MacBook-Pro Downloads]$

Additional line in output when prompted for Security Token

Hey guys, there's a minor display issue when a security token is requested:

Authenticating as fots ...

Security Token [000000]
: xxxxxx
Please choose the role you would like to assume:

Expected Result:

Authenticating as fots ...

Security Token [000000]: xxxxxx
Please choose the role you would like to assume:

Cheers
Fotis

saml2aws login fails when $HOME/.aws/credentials missing

saml2aws login fails with the following error when $HOME/.aws/credentials file is missing.

lstat /home/sjcho/.aws/credentials: no such file or directory
unable to resolve symlink
github.com/versent/saml2aws/pkg/awsconfig.(*CredentialsProvider).filename
        /opt/saml2aws/src/github.com/versent/saml2aws/pkg/awsconfig/awsconfig.go:144
github.com/versent/saml2aws/pkg/awsconfig.(*CredentialsProvider).Save
        /opt/saml2aws/src/github.com/versent/saml2aws/pkg/awsconfig/awsconfig.go:64
github.com/versent/saml2aws/cmd/saml2aws/commands.Login
        /opt/saml2aws/src/github.com/versent/saml2aws/cmd/saml2aws/commands/login.go:146
main.main
        /opt/saml2aws/src/github.com/versent/saml2aws/cmd/saml2aws/main.go:76
runtime.main
        /snap/go/922/src/runtime/proc.go:185
runtime.goexit
        /snap/go/922/src/runtime/asm_amd64.s:2337
error saving credentials
github.com/versent/saml2aws/cmd/saml2aws/commands.Login
        /opt/saml2aws/src/github.com/versent/saml2aws/cmd/saml2aws/commands/login.go:148
main.main
        /opt/saml2aws/src/github.com/versent/saml2aws/cmd/saml2aws/main.go:76
runtime.main
        /snap/go/922/src/runtime/proc.go:185
runtime.goexit
        /snap/go/922/src/runtime/asm_amd64.s:2337

The command works fine when I create an empty credentials file before running the command.

Saml2AWS for Windows behind a corporate proxy

Hello,

I tried to use Saml2AWS in Windows but I get an exception

Issue

Following error I get:

Authenticating as xxx@xxx ...
Post https://signin.aws.amazon.com/saml: Proxy Authorization Required
error retrieving AWS login form
github.com/versent/saml2aws.ParseAWSAccounts

Tests
I added HTTP_PROXY as systemvariable with the companies proxy like "http://Address:Port

Additional Note
When I use VirtualBox/Ubuntu/CNTLM on the same machine in the same network -> it works.

Question:
Does any one of you have further ideas how to get this accomplished ?

Built executeable fails when trying to run it in windows

Hello,

I`m trying to build the current master because I need to use a specific pull request in both
Ubuntu and Windows.

  1. I executed glide install and I correctly set the $GOPATH
    => works

  2. I tried to build it for both x86 and x64 with these commands:

env GOOS=windows GOARCH=amd64 go build -o saml2aws.exe
env GOOS=windows GOARCH=386 go build -o saml2aws.exe

and was able to build the file but it doesnt work when I execute these files. **It tells me its incompatbile with this windows version**
I have windows 7 but I think that not the issue.
Any clue what the issue might be ?

Okta provider empty SAML Assertion

We are using Okta+DUO for AWS authentication. I cannot get Okta provider to work. SAML Assertion is always empty. I got it to work by sending another get request to Okta APP to actually get SAML Assertion value (Code below). For now I just patch it and recompile so we can start using this awesome tool.

I am wondering if I am missing something to get Okta+DUO to work without code changes below?

If fix below is necessary then what is the proper way to setup extra config per provider? (Like for fix below it will need Okta APP parameter.)

Repo with the patch:
https://github.com/richardheath/saml2aws/blob/master/pkg/provider/okta/okta.go

I hardcoded the Okta APP since I am not sure how to properly make this a config option:

req, err = http.NewRequest("GET", oktaEntryURL+"/home/amazon_aws/0oagi9d4ouv6LpCWS0x7/272", nil)
if err != nil {
	return samlAssertion, errors.Wrap(err, "error building app request")
}

q = req.URL.Query()
q.Add("RelayState", "/")
q.Add("sessionToken", oktaSessionToken)
req.URL.RawQuery = q.Encode()

req.Header.Add("Accept", "*/*")
res, err = oc.client.Do(req)
if err != nil {
	return samlAssertion, errors.Wrap(err, "error retrieving app response")
}

SMS MFA Support

My normal browser displays a page like this:

For security reasons, we require additional information to verify your account ([email protected])

We've sent a text message with a verification code.

+xx xxx xxx1234
Verification code

saml2aws fails with this error on mfa enabled accounts:

Response did not contain a valid SAML assertion
Please check your username and password is correct

KeyCloak MFA support

When attempting to login with saml2aws using KeyCloak IdP get error
"Response did not contain a valid SAML assertion" when MFA is enabled.

saml2aws exec does not work if not logged in

$ saml2aws exec bash
Adding osx helper
NoCredentialProviders: no valid providers in chain. Deprecated.
	For verbose messaging see aws.Config.CredentialsChainVerboseErrors
error validating token
github.com/versent/saml2aws/cmd/saml2aws/commands.Exec
	/Users/markw/Code/go/src/github.com/versent/saml2aws/cmd/saml2aws/commands/exec.go:26
main.main
	/Users/markw/Code/go/src/github.com/versent/saml2aws/cmd/saml2aws/main.go:75
runtime.main
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/proc.go:185
runtime.goexit
	/usr/local/Cellar/go/1.8.1/libexec/src/runtime/asm_amd64.s:2197

It happens in the checkToken function. It should handle more AWS errors by going to login.

Unable to authenticate to Okta + Duo when new Okta Sign-In Page enabled

When enabling the new Okta Sign-In Page saml2aws borks with the following error
Authenticating to Okta... main.go:66: error authenticating to adfs: unable to locate IDP authentication form submit URL

Okta have changed the way they initiate a login with the new Okta Sign-In page, It appears the JavaScript signin widget now calls the Okta Auth api which then initiates the Duo Web Widget when duo is enabled.

saml2aws needs to use the okta auth api instead of the previous simulation via the web page.

The --skip-prompt option should prompt for a password if not specified with --password

It is undesirable to use the --password option due to safety. but -skip-prompt is at least useful to skip the Username prompt. However, this is what happens:

fots > ~ $ saml2aws --skip-prompt -a fots login
Using IDP Account amp to access KeyCloak https://...
Authenticating as fots ...
Empty password
error validating login details
github.com/versent/saml2aws/cmd/saml2aws/commands.Login
        /Users/markw/go/src/github.com/versent/saml2aws/cmd/saml2aws/commands/login.go:65
main.main
        /Users/markw/go/src/github.com/versent/saml2aws/cmd/saml2aws/main.go:95
runtime.main
        /usr/local/Cellar/go/1.9.2/libexec/src/runtime/proc.go:195
runtime.goexit
        /usr/local/Cellar/go/1.9.2/libexec/src/runtime/asm_amd64.s:2337

This works as expected for the MFA token input with the --skip-prompt option:

fots > ~ $ saml2aws --skip-prompt --password=pass123 -a fots login
Using IDP Account amp to access KeyCloak https://...
Authenticating as fots ...

Security Token [000000]
:

Cheers
Fotis

login args

Can I pass in host and username via args?

saml2aws login -h hostname -u username

32bit windows

Hi,
is it possible to add a 32bit windows version to the releases area?
Thanks

no buildable Go source files osxkeychain

How to reproduce.
OS: Ubuntu 16.04.1 LTS
How: initiate make command.
Output:

1 errors occurred:
--> darwin/amd64 error: exit status 1
Stderr: go build github.com/versent/saml2aws/helper/osxkeychain: no buildable Go source files in /home/debojit/gocode/src/github.com/versent/saml2aws/helper/osxkeychain

Makefile:29: recipe for target 'compile' failed
make: *** [compile] Error 1

saml2aws login without storing account

It would be good to be able to run saml2aws login without having to always have accounts preconfigured (in the ~/.saml2aws config file via saml2aws configure).

Given all the account details required by saml2aws configure can be passed as command line flags to saml2aws login, it would be good to have the option to skip the saml2aws configure step

This is probably going to also be a pre-requisite for #55

Windows cannot save credentials to missing .aws folder

The AWS cli does not create the C:\Users{username}.aws folder in Windows. Running saml2aws results in the following error if the folder doesn't exist.

Saving credentials
main.go:66: error saving credentials: open C:\Users{username}.aws\credentials: The system cannot find the path specified.

Manually creating the folder fixes the issue. Perhaps we could have a check for the folder and create it if it's missing.

Enable Session Duration

AWS supports an optional request parameter to prolong a SessionDuration

The default session support is few hours... It would be nice to enhance the app... Do you have any idea how to implement such improvement in your app?

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.