Git Product home page Git Product logo

aws-cli-oidc's Introduction

aws-cli-oidc

CLI tool for retrieving temporary AWS credentials using an OIDC provider.

How does it work?

AWS Identity Providers and Federation supports IdPs that are compatible with OpenID Connect (OIDC). This tool works as an OIDC client. If the federation between the AWS account and the IdP is established, and an OIDC client for this tool is registered in the IdP, you can get AWS temporary credentials via standard browser login. It means you don't need to pass your credential of the IdP to this tool.

Please refer to the following diagrams on how it works. Steps (1) and (2) are slightly simplified as there is more going on but it should give an overview.

                (1) authenticate user [username, password]        +---------------+
    +------------------------------------------------------------>|               |
    |                                                             | OIDC Provider |
    |      +------------------------------------------------------|               |
    |      |       (2) authentication successful [id_token]       +---------------+
    |      |                                                                |
    |      v                                                                |
+--------------+                                                            |
|              |                                        trust OIDC provider |
| aws-cli-oidc |                                                            |
|              |                                                            |
+--------------+                     AWS                                    |
    ^      |                       +----------------------------------------|-----+
    |      | (3) assume role A     |  +---------+       +--------+--------------+ |
    |      |     [id_token]        |  |   STS   |      -| Role A | Trust Policy | |
    |      +------------------------->|         |    -/ +--------+--------------+ |
    |                              |  |         | --/             .               |
    |                              |  |         |/                .               |
    |                              |  |         |                 .               |
    +---------------------------------|         |       +--------+--------------+ |
     (4) temporary AWS credential  |  |         |       | Role Z | Trust Policy | |
         [aws_key, aws_secret]     |  +---------+       +--------+--------------+ |
                                   +----------------------------------------------+

Prerequisite AWS and OIDC provider settings before using this tool

Before using this tool, the system administrator need to setup the following configuration.

Tested OIDC Provider

Install

Homebrew

If you are on a Mac, you can use Homebrew to install the tool:

brew tap mbrtargeting/mbr
brew install aws-cli-oidc

Binary Releases

You can download binary releases for all major operating system from the Releases page.

Build From Source

Alternatively, you can also build from source.

make build

After building, the binaries will reside in the bin/ subfolder.

Usage

aws-cli-oidc.

Usage:
  aws-cli-oidc get-cred <idp> <role>
  aws-cli-oidc setup <idp>
  aws-cli-oidc -h | --help

Options:
  -h --help  Show this screen.

Setup

Before you use tool you need to setup an identity provider first. There are two options to do so.

The first one is to provide a YAML file containing the configuration. An example configuration with an identity provider named "google" might look like this:

google:
  oidc_server: accounts.google.com
  auth_url: https://accounts.google.com/o/oauth2/v2/auth
  token_url: https://oauth2.googleapis.com/token
  client_id: my_client_id
  client_secret: my_client_secret
  max_session_duration_seconds: 3600

This file must be saved as $AWS_CLI_OIDC_CONFIG/config.yaml where AWS_CLI_OIDC_CONFIG is an environment variable pointing to the root config folder. If AWS_CLI_OIDC_CONFIG is not set it defaults to ~/.aws-cli-oidc/.

The alternative to writing a config file by hand is to use the guided setup via aws-cli-oidc setup <idp> where <idp> is the name you wish to give to this configuration (like "google" in the above example). After finishing this guided survey, the tool will append the resulting provider configuration to the config file.

When you are done with the configuration, you can reference the providers aws-cli-oidc get-cred <idp> <role> using the short name you gave them (aws-cli-oidc get-cred google <role> for the above example).

Get temporary AWS credentials

To obtain temporary AWS credential, execute the aws-cli-oidc get-cred <idp> <role> command where <idp> is the name of a configured identity provider and <role> is the role you want to assume on a AWS account (for example, aws-cli-oidc get-cred google arn:aws:iam::123443211234:role/my-role). If you did not log in for a long time or if you are using the tool for the first time, it opens your browser for you to authenticate. If the authentication is successful, AWS temporary credentials will be output in the JSON format.

You can also use this tool directly as a credential process. For this, add the following lines to your .aws/credentials file.

[my-profile]
credential_process=aws-cli-oidc get-cred google arn:aws:iam::123443211234:role/my-role

And make sure that the aws-cli-oidc is on your PATH or, alternatively, provide the full path to the binary in the configuration above.

Licence

Licensed under the MIT license.

Authors

aws-cli-oidc's People

Contributors

verbit avatar wadahiro avatar

Watchers

 avatar  avatar

Forkers

unya

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.