Giter VIP home page Giter VIP logo

swamp's Introduction

SWAMP: Profile Manager for AWS build

You can use swamp to switch AWS profiles with ease.

Use case

swamp assumes you have an AWS account with CLI access credentials and you want to assume role into a set of AWS accounts from there. swamp optionally supports MFA authentication before assuming the target role.

Without MFA

swamp calls aws sts assume-role and writes the returned credentials into the specified target profile.

Example:

Create a session token based on your default profile:

$ swamp -profile default -target-profile target -target-role admin -account [target-account-id]
Wrote session token for profile target
Token is valid until: 2017-07-06 08:31:10 +0000 UTC

Create a session token based on your instance profile when running in an ec2 instance or ecs task:

$ swamp -instance -target-profile target -target-role admin -account [target-account-id]
Wrote session token for profile target
Token is valid until: 2017-07-06 08:31:10 +0000 UTC

With MFA

swamp calls aws sts get-session-token with MFA authentication to obtain a profile with enabled MFA. The returned credentials are written to the specified intermediate profile. Subsequent calls may skip that step as long as the session token is still valid. With these intermediate credentials aws sts assume-role is called as above.

Example:

$ swamp -target-profile target -target-role admin -account [target-account-id] -mfa-device arn:aws:iam::[origin-account-id]:mfa/[userid]
Enter mfa token for arn:aws:iam::[origin-account-id]:mfa/[userid]: XXXXXX
Wrote session token for profile session-token
Token is valid until: 2017-07-06 20:32:09 +0000 UTC
Wrote session token for profile target
Token is valid until: 2017-07-06 08:31:10 +0000 UTC

And run it again:

$ swamp -target-profile target -target-role admin -account [target-account-id] -mfa-device arn:aws:iam::[origin-account-id]:mfa/[userid]
Session token for profile session-token is still valid
Wrote session token for profile target
Token is valid until: 2017-07-06 08:32:15 +0000 UTC

Or create a session profile only:

$ swamp -mfa-device arn:aws:iam::[origin-account-id]:mfa/[userid]
Enter mfa token for arn:aws:iam::[origin-account-id]:mfa/[userid]: XXXXXX
Wrote session token for profile session-token
Token is valid until: 2017-07-06 20:32:09 +0000 UTC

Auto-Obtain MFA Token

If using swamp with an mfa-enabled account you can use the -mfa-exec flag to tell swamp to try to obtain the token itself. You need to give an executable command which returns the 6-digit code.

swamp is known to integrate well with the following tools:

  • pass / pass-otp: -mfa-exec "pass otp amazonaws.com"
  • ykman: -mfa-exec "ykman oath code amazonaws.com | awk '{ print $NF }'"

Example:

$ swamp -target-profile target -target-role admin -account [target-account-id] -mfa-device arn:aws:iam::[origin-account-id]:mfa/[userid] -mfa-exec "pass otp amazonaws.com"
Obtaining mfa token for: arn:aws:iam::[origin-account-id]:mfa/[userid]
Wrote session token for profile session-token
Token is valid until: 2017-07-06 20:32:09 +0000 UTC
Wrote session token for profile target
Token is valid until: 2017-07-06 08:31:10 +0000 UTC

Renew

swamp allows running in a loop to create a new profile for the target account before credentials expire. It even works with enabled MFA thanks to the cached intermediate credentials.

Example

$ swamp -target-profile target -target-role admin -account [target-account-id] -mfa-device arn:aws:iam::[origin-account-id]:mfa/[userid] -renew
Enter mfa token for arn:aws:iam::[origin-account-id]:mfa/[userid]: XXXXXX
Wrote session token for profile session-token
Token is valid until: 2017-07-06 20:32:09 +0000 UTC
Wrote session token for profile target
Token is valid until: 2017-07-06 08:31:10 +0000 UTC
Session token for profile session-token is still valid
Wrote session token for profile target
Token is valid until: 2017-07-06 08:46:10 +0000 UTC
...

Set profile in environment

To get a shell with AWS_PROFILE properly set, just use the -exec flag and run the shell of your choice. Close the shell when done and you are back int the context before running swamp.

Example

$ echo "outer shell: '$AWS_PROFILE'"
outer shell: ''
$ swamp -target-profile target -target-role admin -account [target-account-id] -mfa-device arn:aws:iam::[origin-account-id]:mfa/[userid] -exec bash
$ echo "inner shell: '$AWS_PROFILE'"
inner shell: 'target'
$ exit
$ echo "outer shell: '$AWS_PROFILE'"
outer shell: ''

Generating shell aliases

swamp has a lot of command line options. It is strongly recommended to create some kind of aliases for running swamp more easily. swamp -alias-config <config.yaml> does exactly that:

swamp -alias-config example/config.yaml >> ~/.bashrc

The output example/bash_aliases.sh file is generated from the example config example/config.yaml.

Install

General

Fetch the latest binary from https://github.com/felixb/swamp/releases. You may install it from source by running make install optionally setting something like TARGET=/usr/local/bin/ to specify a different installation target.

macOS

You can install swamp on macOS using brew with a third-party repository. Simply run brew tap splieth/swamp to add the repository and then brew install swamp to install the binary.

swamp's People

Contributors

benwilb avatar christianplatta1012 avatar felixb avatar m-31 avatar martin-villis avatar splieth avatar timdekarz1063 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

Watchers

 avatar  avatar  avatar  avatar

swamp's Issues

Install swamp via brew on Mac

Even though you most likely won’t consider MacOS as a real operating system: I was tired of installing swamp manually, so I created a custom tap for brew. Would you mind having it in ze Readme so others can make use of it as well?

Token shown on input

Atm, the token is shown when typing it in – which I dislike. Open for an PR?

Mac OS - Support for installation via HomeBrew Cask

This is great tool! Makes it great to interacting with AWS Tools that do not yet recognize shared credentials and need explicit access/secret key.

I was wondering if you have considering put it up as a official brew cask formula. This is so that it simplifies installation for Mac OS users to just be brew cask install swamp.

If it hasn't been considered yet I don't mind adding in formula myself to enable this.

Is it possible to get the AWS_PROFILE export into the current shell back with yaml alias generation?

Hi,
as far as I understood, it is not possible to export the AWS_PROFILE in the current shell that executed the swamp command.
The exec command is executed in a new /bin/sh shell and cannot set environment variables in the parent shell. Even sourcing a script in exec does not work. I think this is because the go process itself is not able to changed env vars in the shell that called swamp.
Am I missing something? Can this still be done like in version 0.11.0 with -export-profile and -export-file ?
The yaml config alias generation is useful but I don't see a way to emulate the -export-profile behavior with this.
Sometimes we don't want to spawn a new shell just for swamping. You get a lot of nested shells when you switch between multiple accounts a lot which is annoying. Having both options (new shell vs. use current shell) would be nice.

Best regards,
Christian

alpine home dir

Error initializing profile writer: Error fetching home dir: user: Current not implemented on linux/amd64

whoami :root
ls ~ : /root/...

what went wrong?

swamp should not rely on stdin

Hi
the following code snippet won't work:

while read line
do
  read -r id name <<< ${line}
  swamp -profile "<snip>" -mfa-device "<snip>" -account "${id}" -target-role "${role}" -target-profile "<snip>"
done <<-EOL
123456789012 account-name
EOL

Swamp seems to read from the same input stream as the while loop is doing.
Whilst we found a work around I do wonder why swamp doesn't use another file descriptor for the MFA token?

locking for credetials file

When running multiple swamp instances in parallel you end up with a race condition when writing profiles to .aws/credentials.

create a make install

It would be nice to "install" the build files after running make with make install

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.