Configures STS credentials using a MFA authenticated session.
Project description
AWS IAM Login
aws-iam-login
allows you to login using MFA as the IAM user itself. Once logged in your temporary credentials are
stored in the ~/.aws/credentials
file for re-use.
Configuration
You will need to configure your roles and IAM User credentials in the same places as you are used to. So in your
~/.aws/credentials
file. To make this process as easy as possible you could use the following command:
aws-iam-login my-profile init
This command will fetch the ARN of the caller identity. Based on this identity we will determin the username
and
mfa_serial
of the IAM User. These will then be stored in the ~/.aws/credentials
file. For example:
[my-profile]
aws_access_key_id = XXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXXXXXXXXXXXXX
mfa_serial = arn:aws:iam::111122223333:mfa/my-iam-user
username = my-iam-user
The only addition is the username
and mfa_serial
fields.
AWS Least privileged
Assuming you have an IAM User that is already configured you will need the following permissions to use aws-iam-login
:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowSessionTokeUsingMFA",
"Effect": "Allow",
"Action": [
"sts:GetSessionToken"
],
"Resource": "*",
"Condition": {
"BoolIfExists": {
"aws:MultiFactorAuthPresent": "true"
}
}
},
{
"Sid": "AllowAccessKeyRotation",
"Effect": "Allow",
"Action": [
"iam:ListAccessKeys",
"iam:CreateAccessKey",
"iam:UpdateAccessKey",
"iam:DeleteAccessKey"
],
"Resource": [
"arn:aws:iam::111122223333:user/${aws:username}"
]
}
]
}
Usage
When you want to make use of the MFA authenticated session of a configured profile. You will need to configure the following:
[profile my-role-1]
role_arn = arn:aws:iam::111122223333:role/my-role-1
source_profile = my-profile-sts
region = eu-west-1
Then when you perform your AWS cli calls you can use the AWS_PROFILE=my-role-1
as you are used to. But the first time it will fail. The reason for this is that the my-profile-sts
source profile does not exist (or the credentials are expired).
Perform the following command to login, this command will ask for your MFA Token:
aws-iam-login my-profile
This authenticates against the AWS API and request temporary credentials from AWS using your MFA Token. These credentials are then stored as <profile-name>-sts
.
So the next time you use AWS_PROFILE=my-role-1
the credentials will be present and not expired.
Because you are already authenticated using MFA there is no need to provide an MFA token when you assume the role. When you switch a lot between roles you really benefit from not having to type your MFA token each time you switch.
Rotating your AccessKey and SecretAccessKey
It is advised to rotate your credentials regularly. aws-iam-login
can help with that! By executing the following command:
aws-iam-login my-profile rotate
This command will execute the following actions:
- List all available keys for the user, when 1 key is active rotation is possible!
- Create a new AccessKey and SecretAccessKey.
- Use the newly created keys to deactivate the old keys.
- Write the new keys to the
~/.aws/configuration
file. - Delete the old keys.
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
Built Distribution
File details
Details for the file aws_iam_login-0.3.2.tar.gz
.
File metadata
- Download URL: aws_iam_login-0.3.2.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/40.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.0.3 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df568354318d50165a3cf34f12e8d44e32e0c7ab908ccff3b3248b5a50dfa343 |
|
MD5 | efd7667168f5662687f00cd6ea6ccd99 |
|
BLAKE2b-256 | 9679c21551b39aae972657a8a6d4414dd07f37c6ff352622ea200ab1ac41defc |
Provenance
File details
Details for the file aws_iam_login-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: aws_iam_login-0.3.2-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/40.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.0.3 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df609b9df8e419849892e159438bc4be32612b0922371ebbada3c458e25646a7 |
|
MD5 | e5afde72e4436b711baac60eb4683c5f |
|
BLAKE2b-256 | 96c21d0e1aeae41c7d257cb2034ad28561dfd9ae2ac2df0f0a9b24d99dfb7938 |