Skip to main content

Renew AWS Simple Token Service Credentials

Project description

# AWS KERBEROS STS
Based on the ADSF-CLI script [originally posted by Quint Van Deman] (https://blogs.aws.amazon.com/security/post/Tx1LDN0UBGJJ26Q/How-to-Implement-Federated-API-and-CLI-Access-Using-SAML-2-0-and-AD-FS)

## Overview
This script provides a seamless mechanism for federating the AWS CLI. When
properly configured this script allows a user to get a short lived (1 hour) set of
credentials for each authorized role.

The script leverages Kerberos and ADFS to avoid any need for the user to enter
a AD domain password or provide AWS credentials. However, users can also
authenticate using NTLM with their username and password or with a Kerberos keytab.

## Configuration
Kerb-STS looks for configuration in the ~/.kerb-sts/config.json file. This file contains
the URL of the ADFS AWS login page and the default region. Users can generate this file with Kerb-STS:
```
kerb-sts --configure
```
This will prompt the user for those values and then serialize the configuration. Users
can also manually create the configuration file which should look like the following:
```
{
"region": "us-east-1",
"adfs_url": "https://sample.domain.com/adfs/ls/IdpInitiatedSignOn.aspx?loginToRp=urn:amazon:webservices"
}
```
Users can override either of the configured values on the command line.

## Installation
* *Note: Python 2.7.10 is the minimal version supported*
* *Note: All platforms have been tested with both Python 2.7 and 3.5*

### OSX
* *Note: If you are using El Capitan or Sierra, refer to the subsequent OSX section*

0. sudo easy_install pip
1. sudo pip install kerb-sts

### OSX - El Capitan
* *Note: El Capitan forces the version of some modules which directly interfere with kerb-sts. In order to
get it to work users need to either use a version of Python that was not included with the OS or need
to follow these instructions which leverage virtual environments.*

0. sudo easy_install pip virtualenv
1. virtualenv ~/kerb-sts
2. source ~/kerb-sts/bin/activate
3. sudo pip install kerb-sts --ignore-installed six
4. deactivate
5. sudo ln -s ~/kerb-sts/bin/kerb-sts /usr/local/bin/kerb-sts

### MacOS Sierra
0. You will need to update your version of Python to 2.7.12+; Homebrew is the easiest method.
1. You will also need to install/update the XCODE Development Extensions
1a. sudo xcode-select install
2. You can then just run sudo pip install kerb-sts

### Windows
0. Install [Python] (https://www.python.org/downloads/)
1. Ensure python and python/scripts are on the PATH
2. Install pywin32 from [SourceForge] (https://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/). Follow the instructions to ensure you get the correct version.
3. pip install kerb-sts

### Ubuntu
0. sudo apt-get update
1. sudo apt-get install -y krb5-kdc libkrb5-dev python-setuptools python3-pip
2. sudo pip install kerb-sts

## Usage
If the install went smoothly `kerb-sts` should be on your path. There are a lot of configuration options.
The best way to discover them is to check out the help statement.
```
kerb-sts --help
```

#### Default Role
The script allows users to specify an AWS IAM role that will be set as the default IAM role in
the credentials file.
```
kerb-sts -r [iam-role-to-assume]
```
All subsequent AWS CLI commands will use this role by default.

Additionally, all available roles will be added as named profiles to the credentials file.
Users can then leverage the default role or use the AWS_DEFAULT_PROFILE environment variable to
select a specific role/profile. You can find more information about the credentials file
in the [AWS Documentation](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files).

#### Daemon
By passing in a `--daemon` flag, the script will continue running and update the credentials file every
half hour. The refresh time can be set with the `--refresh` argument, but remember
the tokens only last for one hour.
```
kerb-sts -r iam-role-to-assume --daemon
```

#### NTLM Auth
The script allows users to authenticate using NTLM (username, domain, password).
```
kerb-sts -u username -p 'password' -d DOMAIN
```

#### Keytab
This script allows users to generate Kerberos tokens with Kerberos keytabs. Keytabs
are private key files that are signed with the user's name, domain, and password.
You can generate a keytab by running:
```
ktutil -k username.keytab add -p username@DOMAIN.COM -e arcfour-hmac-md5 -V 1
```
Users can use the keytab to authenticate with Kerberos by running:
```
kinit -kt username.keytab username@DOMAIN.COM
```
Keytabs allow users to authenticate without their password. The keytab is signed with the password however, so
when a password is updated the keytab must likewise be updated.
They can then be used with kerb-sts to generate temporary tokens:
```
kerb-sts --key username.keytab -u username -d DOMAIN.COM
```

#### Credential File
The default location for the AWS credentials file is ~/.aws/credentials. Users are also able to specify
a different location for the credentials generated.
```
kerb-sts -c ./aws-credentials
```

## Troubleshooting
#### Kerberos
If you are having issues authenticating with Kerberos, make sure you can run `kinit`. This should prompt you for
your password and then login successfully. You can view your current Kerberos tickets with `klist`. If you want to
ensure Kerberos is working properly you can delete all of your tickets with `kdestroy -A` and then try to get another
ticket issued by running `kinit`.

## Building a Distribution
The easiest way to install and distribute kerb-sts is using a wheel.
A distribution can be built by running:
```
python setup.py bdist_wheel
```
That should output a .whl file in the dist directory which can be installed with pip.

## Development
The recommended way to install locally from source is to use a virtual environment. From the root
of the kerb-sts source code directory run:

0. pip install virtualenv
1. virtualenv venv
2. source venv/bin/activate
3. python setup.py install
4. python kerb_sts/

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

kerb-sts-0.1.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distributions

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

kerb_sts-0.1.1-py2.py3-none-any.whl (18.6 kB view details)

Uploaded Python 2Python 3

kerb_sts-0.1.1-py2.7.egg (27.4 kB view details)

Uploaded Egg

File details

Details for the file kerb-sts-0.1.1.tar.gz.

File metadata

  • Download URL: kerb-sts-0.1.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for kerb-sts-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b0535d31902db2987f71f9d457178af854a6f220b891ecfe2bccb6cf05574931
MD5 d15c6df5646dc6d6ec51618866780b8e
BLAKE2b-256 9785a499b78ec68fb0604df7904bb63cc0de0460fa940ba425e39808cbfa1ede

See more details on using hashes here.

File details

Details for the file kerb_sts-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for kerb_sts-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ae5f6b074f109f11fe2df9c88e3d166b75b63174b9b8538cf04638668e75a62a
MD5 d1a00710d9a674cbda81d5c79c630378
BLAKE2b-256 a1a2538e842d17e4c57daa3363d4ad7b0301aa9c9c7ca7e8439c469505001265

See more details on using hashes here.

File details

Details for the file kerb_sts-0.1.1-py2.7.egg.

File metadata

  • Download URL: kerb_sts-0.1.1-py2.7.egg
  • Upload date:
  • Size: 27.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for kerb_sts-0.1.1-py2.7.egg
Algorithm Hash digest
SHA256 6e2157d711571089f9dd3ce8dc368a04c1e52b87db6bc9fe35c6ee238fd23c73
MD5 f67a1f989e3df5a240f6dc3316f96c3e
BLAKE2b-256 b42928fe8313e3e7960ae963afb79600889eb981b0aca1fc6cffae40b69957f1

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