Skip to main content

AWS IAM Login

License Maintenance GitHub release Continuous Integration

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:

  1. List all available keys for the user, when 1 key is active rotation is possible!
  2. Create a new AccessKey and SecretAccessKey.
  3. Use the newly created keys to deactivate the old keys.
  4. Write the new keys to the ~/.aws/configuration file.
  5. Delete the old keys.

Metadata

Release files for aws-iam-login 0.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-iam-login 0.3.6
File Size Uploaded
aws_iam_login-0.3.6.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-iam-login 0.3.6
File Interpreter ABI Platform
aws_iam_login-0.3.6-py3-none-any.whl Python 3 none any Details

Total release size: 26.5 kB

Release files / aws_iam_login-0.3.6.tar.gz

Download URL aws_iam_login-0.3.6.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bc0062b20326ea8ba0903bf3218ff64e1a18e8cdd1157c3f2d3ad84578223d66
BLAKE2b-256 checksum
How to use checksums
61fbcb321291fb85e02c9774306f978d69eb05f71042d58460b3f2fd3dd6c54a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.8

Release files / aws_iam_login-0.3.6-py3-none-any.whl

Download URL aws_iam_login-0.3.6-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
98e66e6ae3aeb8d3a7d74ea4af3f400ccc5789c11dea3bb3a810d2ee065f26cf
BLAKE2b-256 checksum
How to use checksums
ee3eb4904d70c6e08f1929a9597cc93929f482c7a0bf8b3203f976798d8002d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.3.6 This release

2 release files

0.3.4

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page