Skip to main content

Utilities to make AWS SSO easier

Project description

aws-sso-util

Making life with AWS SSO a little easier

AWS SSO has some rough edges, and aws-sso-util is here to smooth them out, hopefully temporarily until AWS makes it better.

aws-sso-util contains utilities for the following:

  • Configuring .aws/config
  • Logging in/out
  • AWS SDK support
  • Looking up identifiers
  • CloudFormation
  • Python library for AWS SSO authentication

aws-sso-util supersedes aws-sso-credential-process, which is still available in its original form here. Read the updated docs for aws-sso-util credential-process here.

Quickstart

  1. Make sure you've installed the AWS CLI v2 (which has AWS SSO support).

  2. I recommend you install pipx, which installs the tool in an isolated virtualenv while linking the script you need.

Mac:

brew install pipx
pipx ensurepath

Other:

python3 -m pip install --user pipx
python3 -m pipx ensurepath
  1. Install
pipx install aws-sso-util
  1. Learn
aws-sso-util --help
  1. Autocomplete

aws-sso-util uses click, which supports autocompletion. The details of enabling shell completion with click vary by shell (instructions here), but here is an example that updates the completion in the background.

AWS_SSO_UTIL_COMPLETE_SCRIPT_DIR=~/.local/share/aws-sso-util
AWS_SSO_UTIL_COMPLETE_SCRIPT=$AWS_SSO_UTIL_COMPLETE_SCRIPT_DIR/complete.sh
if which aws-sso-util > /dev/null; then
  mkdir -p $AWS_SSO_UTIL_COMPLETE_SCRIPT_DIR
  (_AWS_SSO_UTIL_COMPLETE=source_bash aws-sso-util > $AWS_SSO_UTIL_COMPLETE_SCRIPT.tmp ;
    mv $AWS_SSO_UTIL_COMPLETE_SCRIPT.tmp $AWS_SSO_UTIL_COMPLETE_SCRIPT &)
  if [ -f $AWS_SSO_UTIL_COMPLETE_SCRIPT ]; then
    source $AWS_SSO_UTIL_COMPLETE_SCRIPT
  fi
fi

Configuring .aws/config

Read the full docs for aws-sso-util configure here.

aws-sso-util configure has two subcommands, aws-sso-util configure profile for configuring a single profile, and aws-sso-util configure populate to add all your permissions as profiles, in whatever region(s) you want (with highly configurable profile names).

You probably want to set the environment variables AWS_DEFAULT_SSO_START_URL and AWS_DEFAULT_SSO_REGION, which will inform these commands of your start url and SSO region (that is, the region that you've configured AWS SSO in), so that you don't have to pass them in as parameters every time.

aws-sso-util configure profile takes a profile name and prompts you with the accounts and roles you have access to, to configure that profile.

aws-sso-util configure populate takes one or more regions, and generates a profile for each account+role+region combination. The profile names are completely customizable.

Logging in and out

Read the full docs for aws-sso-util login and aws-sso-util logout here.

A problem with aws sso login is that it's required to operate on a profile, that is, you have to tell it to log in to AWS SSO plus some account and role. But the whole point of AWS SSO is that you log in once for many accounts and roles. You could have a particular account and role set up in your default profile, but I prefer not to have a default profile so that I'm always explicitly selecting a profile and never accidentally end up in the default by mistake. aws-sso-util login solves this problem by letting you just log in without having to think about where you'll be using those credentials.

Adding AWS SSO support to AWS SDKs

Read the full docs for aws-sso-util credential-process here.

Not all AWS SDKs have support for AWS SSO (which will change eventually). However, they all have support for credential_process, which allows an external process to provide credentials. aws-sso-util credential-process uses this to allow these SDKs to get credentials from AWS SSO. It's added automatically (by default) by the aws-sso-util configure commands.

Looking up identifiers and assignments

Read the full docs for aws-sso-util lookup and aws-sso-util assignments here.

When you're creating assignments through the API or CloudFormation, you're required to use identifiers like the instance ARN, the principal ID, etc. These identifiers aren't readily available through the console, and the principal IDs are not the IDs you're familiar with. aws-sso-util lookup allows you to get these identifers, even en masse.

There is no simple API for retrieving all assignments or even a decent subset. The current best you can do is list all the users with a particular PermissionSet on a particular account. aws-sso-util assigments takes the effort out of looping over the necessary APIs.

CloudFormation support

You'll want to read the full docs here.

AWS SSO's CloudFormation support currently only includes AWS::SSO::Assignment, which means for every combination of principal (group or user), permission set, and target (AWS account), you need a separate CloudFormation resource. Additionally, AWS SSO does not support OUs as targets, so you need to specify every account separately.

Obviously, this gets verbose, and even an organization of moderate size is likely to have tens of thousands of assignments. aws-sso-util cfn provides two mechanisms to make this concise.

I look forward to discarding this part of the tool once there are two prerequisites:

  1. OUs as targets for assignments
  2. An AWS::SSO::AssignmentGroup resource that allows specifications of multiple principals, permission sets, and targets, and performs the combinatorics directly.

CloudFormation Macro

aws-sso-util defines a resource format for an AssignmentGroup that is a combination of multiple principals, permission sets, and targets, and provides a CloudFormation Macro you can deploy that lets you use this resource in your templates.

Client-side generation

I am against client-side generation of CloudFormation templates, but if you don't want to trust this 3rd party macro, you can generate the CloudFormation templates directly.

aws-sso-util cfn takes one or more input files, and for each input file, generates a CloudFormation template and potentially one or more child templates. These templates can then be packaged and uploaded using aws cloudformation package or the SAM CLI, for example.

The input files can either be templates using the Macro (using the --macro flag), or somewhat simpler configuration files using a different syntax. These configuration files can define permission sets inline, have references that turn into template parameters, and you can provide a base template that the resulting resources are layered on top of.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-sso-util-2.8.0.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_sso_util-2.8.0-py3-none-any.whl (63.6 kB view details)

Uploaded Python 3

File details

Details for the file aws-sso-util-2.8.0.tar.gz.

File metadata

  • Download URL: aws-sso-util-2.8.0.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.3 Linux/4.19.128-microsoft-standard

File hashes

Hashes for aws-sso-util-2.8.0.tar.gz
Algorithm Hash digest
SHA256 50069ad962973d8bb56e0c324113e99c00171daa30d422ec5ce75e06656a959a
MD5 1e453a36f898b05b0fea774cf27622a5
BLAKE2b-256 e92aae76e50151fe4f015bce217e145e6d28561ef3b8d479b26b6f2f9244cc79

See more details on using hashes here.

File details

Details for the file aws_sso_util-2.8.0-py3-none-any.whl.

File metadata

  • Download URL: aws_sso_util-2.8.0-py3-none-any.whl
  • Upload date:
  • Size: 63.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.3 Linux/4.19.128-microsoft-standard

File hashes

Hashes for aws_sso_util-2.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea53007491af4467cf0596151c1a25c58c2eae8c70d4171773a7a36e656b07d6
MD5 ef28cd237f3f6a7ea1c5151bbbe71256
BLAKE2b-256 ecc76b72072e217d283e874f57efaebaa6ac37eac7d0ce6116397e86fc54d55d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page