Assume an AWS Role and get temporary credentials using Onelogin.
Users will be able to choose from among multiple AWS roles in multiple AWS accounts when they sign in using OneLogin in order to assume an AWS Role and obtain temporary AWS acccess credentials.
This is really useful for customers that run complex environments with multiple AWS accounts, roles and many different people that need periodic access as it saves manually generating and managing AWS credentials.
This repository contains 2 examples of how to get the temporary AWS acccess credentials:
Most people want the CLI tool so check that you have the prequisites in place and get started.
The "Configuring SAML for Amazon Web Services (AWS) with Multiple Accounts and Roles" guide explains how to:
There is a precompiled onelogin-aws-cli.jar file in the onelogin-aws-assume-role-cli/dist
folder that you can download and start using this tool immediately (once configured the required settings)
Use the tool to generate AWS credentials and output them to the terminal.
> java -jar onelogin-aws-cli.jar
Or alternately save them to your AWS credentials file to enable faster access from any terminal.
> java -jar onelogin-aws-cli.jar --profile profilename
The credentials only last for 1 hour so you can also make it regenerate and update the credentials file by using the --loop
option.
For a more detail set of instructions see the help guide.
If you want to include the code in another project, extend it or just build your own binary you can find the source in these locations.
The project is hosted at github. You can download it from:
The toolkit is hosted at Sonatype OSSRH (OSS Repository Hosting) that is synced to the Central Repository.
Install it as a maven dependecy:
aws-cli
<dependency>
<groupId>com.onelogin</groupId>
<artifactId>onelogin-aws-assume-role-cli</artifactId>
<version>1.2.2</version>
</dependency>
aws-jsp
<dependency>
<groupId>com.onelogin</groupId>
<artifactId>onelogin-aws-assume-role-jsp</artifactId>
<version>1.2.2</version>
</dependency>
It works with Java7 and Java8.
Both projects uses a settings file, where OneLogin SDK properties are placed, that can be found at src/resources folder:
Read more about Onelogin API credentials at: https://developers.onelogin.com/api-docs/1/getting-started/working-with-api-credentials
In addition the onelogin-aws-assume-role-cli is able to read those SDK attributes from the command line:
With that data, a SAMLResponse is retrieved. And possible AWS Role are retrieved.
A temporal AWS AccessKey and secretKey are retrieved in addition to a sessionToken. Those data can be used to generate an AWS BasicSessionCredentials to be used in any AWS API java sdk:
BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(
assumeRoleWithSAMLResult.getCredentials().getAccessKeyId(),
assumeRoleWithSAMLResult.getCredentials().getSecretAccessKey(),
assumeRoleWithSAMLResult.getCredentials().getSessionToken()
);
AmazonS3Client s3 = new AmazonS3Client(temporaryCredentials);
Adding onelogin-aws-assume-role-cli or onelogin-aws-assume-role-jsp as a project
In order to execute the cli code, at the Package Explorer, select the onelogin-aws-assume-role-cli, 2nd bottom of the mouse and Run As > Java application and select the OneloginAWSCLI.
You can see detailed info about how to play with the onelogin-aws-cli.jar precompiled version at OneLogin Developer site.
You can re-generate the jar by executing at the onelogin-aws-assume-role-cli folder the command:
mvn package
You can extend CLI functionality by using arguments. There are several:
Note: If you're bored typing your
username (--username
),
App ID (--appid
),
subdomain (--subdomain
) or
AWS region (--region
)
every time, you can specify these parameters as command-line arguments and
the tool won't ask for them any more.
The selection of the AWS account and Role can be also be done with the --aws-account-id and --aws-role-name parameters.
Note: Specifying your password directly with --password
is bad practice,
you should use that flag together with password managers, eg. with the OSX Keychain:
--password $(security find-generic-password -a $USER -s onelogin -w)
,
so your password won't be saved in you command line history.
Please note that your password will be visible in your process list,
if you use this flag (as the expanded command line arguments are part of the name of the process).
For more info execute the --help option.
If you want to deploy the web example, at the Package Explorer, select the onelogin-aws-assume-role-jsp, 2nd bottom of the mouse and Run As > Run Server Select a Tomcat Server in order to deploy the server.