SAML login for AWS using Shibboleth IDP
Project description
This Python package provides some helper functions to allow programmatic retrieval of temporary AWS credentials from STS (Security Token Service) when using federated login with Shibboleth IDP.
The implementation relies on HTML parsing of the Shibboleth redirect page (HTML form) and the AWS role selection page.
This package requires Python 3.4.
Installation
$ sudo pip3 install --upgrade aws-saml-login
Usage
from aws_saml_login import authenticate, assume_role, write_aws_credentials, get_boto3_session
# authenticate against identity provider
saml_xml, roles = authenticate('https://shibboleth-idp.example.org', user, password)
print(roles)
# just use the first role here, we might display a user dialog to choose one
first_role = roles[0]
provider_arn, role_arn, account_name = first_role
# get temporary AWS credentials
key_id, secret, session_token = assume_role(saml_xml, provider_arn, role_arn)
# write to ~/.aws/credentials
write_aws_credentials('default', key_id, secret, session_token)
# get boto3 session
session = get_boto3_session(key_id, secret, session_token)
ec2 = session.resource('ec2', 'eu-west-1')
iam = session.client('iam')
# get boto3 session with default region eu-central-1
session = get_boto3_session(key_id, secret, session_token, 'eu-central-1')
ec2 = session.resource('ec2')
# get session for the first 5 roles
sessions = {}
for role in roles[:5]:
provider_arn, role_arn, account_name = role
key_id, secret, session_token, expiration = assume_role(saml_xml, provider_arn, role_arn)
sessions['{} {}'.format(account_name,role_arn.split(':')[-1])] = get_boto3_session(None, key_id, secret, session_token)
for key in sessions.keys():
print('Key: {} / AccountAlias: {}'
.format(key,
sessions[key].client('iam').list_account_aliases()['AccountAliases']))
# AWS SDK (e.g. boto) can be used to call AWS endpoints
License
Copyright © 2015 Zalando SE
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aws_saml_login-1.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f037f333c6248fc07424bf023280f74fdf4f50edd24f55859b96c163a44eb9d |
|
MD5 | eeeb00382de58cfe5c777c9dc9f03322 |
|
BLAKE2b-256 | c1d233a6dd98a63830f435f1b7c938034bb79bd44b97d7b9e4ffd3057f160cef |