Deprecating IAM User Access Keys and Migrating to aws login

Deprecating IAM User Access Keys and Migrating to aws login

Long-term IAM user access keys carry a high risk if leaked, so we recommend moving to short-term credentials using aws login. This article explains how to migrate.
2026.11.05

This page has been translated by machine translation. View original

Retire IAM user access keys and migrate to aws login

Hello, I'm Shimon from the Consulting Department.

An IAM user access key is a long-term credential that remains usable until you manually deactivate it. It is stored in plain text in ~/.aws/credentials on each user's device, so if it leaks, for example because the device is infected with malware through phishing and the file is read, or because it is accidentally committed to a repository, someone can operate AWS with the same permissions as its owner. There are also cases where you want to get rid of the keys themselves, such as when AWS Security Hub CSPM keeps flagging IAM.3 (rotate active access keys within 90 days) or when an internal audit raises an issue.

This article introduces how to retire IAM user access keys and migrate to aws login.

With aws login, you can obtain short-term credentials from the AWS Management Console sign-in and retire long-term access keys. Short-term credentials expire in 15 minutes, and automatic refresh stops after 12 hours at most, so even if they leak, the period during which they can be used is limited.

aws login requires signing in through a browser, so the access keys targeted for migration in this article are those that people use on their devices.

1. Order of work for administrators and each user

The people involved are the administrator who manages the account and each user who uses the AWS CLI on their device.

Section Who What
2 Administrator Select the access keys to migrate
3 Administrator Issue temporary passwords and let each user register MFA
4 Administrator Grant the aws login permissions (AWS managed policy SignInLocalDevelopmentAccess)
5 Each user Change the password and register MFA
6 Each user Switch to aws login and remove the old keys from the device
7.1, 7.2 Administrator Deactivate the access keys, observe, then delete them
7.3 Administrator Prevent new access keys from being created
8 Administrator (If you use Security Hub CSPM) Check how the findings change

2. Select the access keys to migrate (administrator)

First, use the credential report to list, for each user, the access key creation date, last used date, and the service and Region where it was last used.

Create the credential report and save it as CSV
aws iam generate-credential-report
aws iam get-credential-report --query Content --output text | base64 --decode > credential-report.csv

The last-used information alone does not tell you whether a key is used by a person on a device or by CI or a batch job. Check with the owner of each listed key, and target the keys that each user uses with the AWS CLI or SDK on their device. For keys whose owner is unknown, filter the AWS CloudTrail event history by key ID and get an idea of how the key is used from the source IP address and user agent.

Keys used by programs cannot be replaced with aws login, so they are out of scope for this article. Consider migrating them separately to IAM roles or federation via OIDC. Keys with an empty last-used date, or keys that have not been used for a long time (for example, 90 days or more), should not be migrated; simply deactivate them.

3. Issue temporary passwords and let each user register MFA (administrator)

aws login uses the console sign-in of an IAM user, so users who have only access keys need a password. The administrator decides only the temporary password; each user sets their actual password and MFA.

  1. Put the users to be migrated into an IAM group (here, aws-login-users). All the policies that follow are attached to this group

  2. Attach the following policy to the group so that each user can change their own password and register an MFA device

    Policy that lets each user change their own password and register an MFA device
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "AllowListActions",
          "Effect": "Allow",
          "Action": ["iam:ListUsers", "iam:ListVirtualMFADevices"],
          "Resource": "*"
        },
        {
          "Sid": "AllowUserToCreateVirtualMFADevice",
          "Effect": "Allow",
          "Action": ["iam:CreateVirtualMFADevice"],
          "Resource": "arn:aws:iam::*:mfa/*"
        },
        {
          "Sid": "AllowUserToManageTheirOwnMFA",
          "Effect": "Allow",
          "Action": ["iam:EnableMFADevice", "iam:GetMFADevice", "iam:ListMFADevices", "iam:ResyncMFADevice"],
          "Resource": "arn:aws:iam::*:user/${aws:username}"
        },
        {
          "Sid": "AllowUserToChangeTheirOwnPassword",
          "Effect": "Allow",
          "Action": ["iam:ChangePassword"],
          "Resource": [
            "arn:aws:iam::*:user/${aws:username}",
            "arn:aws:iam::*:user/*/${aws:username}"
          ]
        },
        {
          "Sid": "AllowViewAccountPasswordPolicy",
          "Effect": "Allow",
          "Action": ["iam:GetAccountPasswordPolicy"],
          "Resource": "*"
        }
      ]
    }
    
  3. Prepare, for each user, a random temporary password that satisfies the account's password policy, using a password manager or similar tool. In the IAM console, enable console access for each user, set the prepared temporary password as a custom password, and require a password change at the next sign-in

    Setting in the IAM console to enable console access and require a password change at the next sign-in

    If there are many users, you can issue passwords with the AWS CLI.

    Issue a temporary password and require a change at the next sign-in
    aws iam create-login-profile \
      --user-name example-user \
      --password '一時パスワード' \
      --password-reset-required
    
  4. Give each user their user name, temporary password, and the account's sign-in URL (https://アカウント ID.signin.aws.amazon.com/console)

If you use a policy that requires MFA (the common form that denies when aws:MultiFactorAuthPresent is false), add iam:ChangePassword and iam:GetAccountPasswordPolicy to the exceptions of the deny. Otherwise, each user will be unable to change their password when prompted and will not be able to sign in.

From the time the password is created until each user registers MFA, that user is flagged by Security Hub CSPM IAM.5 (IAM users that have a console password should have MFA enabled). After handing over the temporary password, have users complete MFA registration early.

4. Attach SignInLocalDevelopmentAccess (administrator)

The permissions required for aws login are signin:AuthorizeOAuth2Access and signin:CreateOAuth2Token, and they are bundled in the AWS managed policy SignInLocalDevelopmentAccess. Attach it to the group of users to be migrated.

Attach SignInLocalDevelopmentAccess to the group of users to be migrated
aws iam attach-group-policy \
  --group-name aws-login-users \
  --policy-arn arn:aws:iam::aws:policy/SignInLocalDevelopmentAccess

5. Change the password and register MFA (each user)

After receiving the user name, temporary password, and account sign-in URL from the administrator, sign in to the console as the IAM user and change the password to your own. Then open the security credentials page from the user name menu at the top right of the screen and register an MFA device. In addition to authenticator apps, passkeys and security keys can also be used.

Screen for assigning an MFA device on the security credentials page

After registering, sign out once and sign in again with MFA. If there is a policy that requires MFA, aws login returns a 400 error when you keep using the session from before you registered MFA.

6. Switch to aws login (each user)

6.1 Use AWS CLI 2.32.0 or later

Check the AWS CLI version, and update it if it is older than 2.32.0, the version that supports aws login.

Check the AWS CLI version
aws --version

6.2 Run aws login

If you retrieve the access key with credential_process from a password manager or similar tool, remove the credential_process line from that profile before running aws login. For a profile that has credential_process written in it, aws login refuses to run before opening the browser.

~/.aws/config (before migration)
[default]
region = ap-northeast-1
credential_process = /usr/local/bin/aws-credential-helper
~/.aws/config (after rewriting)
[default]
region = ap-northeast-1
Sign in with aws login
aws login

Set the aws login credentials on the same profile where you had written the access key. If you use a profile other than [default], specify the profile name with --profile. Because the profile name does not change, your scripts, AWS_PROFILE settings, and role profiles that point to this profile via source_profile keep working without being rewritten. A browser opens, so sign in.

If the sign-in screen offers a console session that remains in the same browser (a session of another IAM user, or your own session from before you registered MFA) as a candidate, open the URL displayed by the AWS CLI in a private window and sign in as the IAM user you are migrating.

When sign-in is complete, a login_session line is appended to the profile you ran it for in ~/.aws/config (here, [default]).

~/.aws/config (after sign-in)
[default]
login_session = arn:aws:iam::111122223333:user/example-user
region = ap-northeast-1

6.3 Remove the old access key from the device

From ~/.aws/credentials, remove the access key of the profile with the same name as the aws login profile. If your ~/.aws/credentials before migration looks like the following, remove the three lines of [default].

~/.aws/credentials (before migration)
[default]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

If you have set keys in the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, remove them from shell configuration files and .env files as well.

If either remains, the AWS CLI uses the key in preference to the aws login credentials. Keys in environment variables are used even if you select the aws login profile with [default] or AWS_PROFILE.

After removing them, check where the credentials come from with aws configure list --profile default. If the TYPE column is login, the aws login credentials are being used; if it is shared-credentials-file, the key in ~/.aws/credentials is being used.

When the aws login credentials are used
NAME       : VALUE                    : TYPE             : LOCATION
profile    : default                  : manual           : --profile
access_key : ****************ABCD     : login            :
secret_key : ****************WXYZ     : login            :
region     : ap-northeast-1           : config-file      : ~/.aws/config
When the key in ~/.aws/credentials is used
NAME       : VALUE                    : TYPE             : LOCATION
profile    : default                  : manual           : --profile
access_key : ****************MPLE     : shared-credentials-file :
secret_key : ****************EKEY     : shared-credentials-file :
region     : ap-northeast-1           : config-file      : ~/.aws/config

6.4 Signing in again after switching, and aws logout

The AWS CLI and versions of the SDKs that support it refresh the credentials automatically. Once the 12 hours after which refreshing stops have passed, run aws login again.

When you finish working, run aws logout. The refresh token remains in plain text in the cache, so deleting it shortens the period during which new credentials can be obtained from the device.

Delete the cache with aws logout
aws logout
Output of aws logout
Removed cached login credentials for profile 'default'. Note, any local developer tools that have already loaded the access token may continue to use it until its expiration. Access tokens expire in 15 minutes.

7. Retire the access keys (administrator)

7.1 Confirm that they are no longer used

Once each user has switched, create the credential report again. The report can be regenerated only once every 4 hours, so if it is within 4 hours of when you selected the keys to migrate, wait a while before creating it.

Regenerate the credential report and save it as CSV
aws iam generate-credential-report
aws iam get-credential-report --query Content --output text | base64 --decode > credential-report.csv

Open the CSV in a spreadsheet or similar tool and look at the access_key_1_last_used_date and access_key_2_last_used_date columns for the migrated users.

If a migrated user's last-used date is later than the day they switched, the key is still being used somewhere. Ask that user to check whether a key remains on their device or whether other tools are using the key.

7.2 Deactivate, then delete

First, deactivate the key. Calls made with a deactivated key fail, so if any place still uses the key, you can often notice through reports from each user, and you can reactivate the key if a problem occurs.

Deactivate the access key
aws iam update-access-key --user-name example-user --access-key-id AKIAIOSFODNN7EXAMPLE --status Inactive

If there are no problems for a certain period (for example, 2 weeks), delete it.

Delete the access key
aws iam delete-access-key --user-name example-user --access-key-id AKIAIOSFODNN7EXAMPLE

7.3 Prevent new access keys from being created

Even after you delete the keys, if each user has permission to create new keys themselves, you return to a state with access keys. Attach to the group of migrated users a policy that explicitly denies iam:CreateAccessKey.

Policy that prevents IAM users from creating access keys
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyCreateAccessKey",
      "Effect": "Deny",
      "Action": "iam:CreateAccessKey",
      "Resource": "*"
    }
  ]
}

This policy stops only the creation of keys by group members. It does not stop an administrator who is not in the group from creating keys for other users. If you operate an AWS Organizations management account, you can apply a service control policy (SCP) that denies iam:CreateAccessKey, excluding the administrative roles that are exceptions, across all member accounts. SCPs do not apply to the management account itself, so attach the policy above to the users of the management account.

8. Security Hub CSPM findings that change with the migration (administrator)

If you use Security Hub CSPM, this migration changes the results of the following controls.

Control Description Change from this migration
IAM.3 Rotate active access keys within 90 days Resolved at the next periodic evaluation once the key is deactivated or deleted
IAM.5 IAM users that have a console password should have MFA enabled Newly flagged if a user for whom you created a password has no MFA
IAM.22 Remove passwords and active access keys unused for 45 days Newly flagged if a user for whom you created a password does not sign in to the console or with aws login for 45 days or more
IAM.8 Remove passwords and active access keys unused for 90 days Newly flagged if a user for whom you created a password does not sign in to the console or with aws login for 90 days or more

IAM.22 is evaluated using the credential report, which is updated every 4 hours, so it can take up to 4 hours for changes to IAM users to appear in the IAM.22 results. Browser sign-ins with aws login are also recorded in the password's last-used date.

Summary

This article introduced the steps to replace the access keys that IAM users use on their devices with short-term credentials via aws login.

Access keys can be used indefinitely until they are deactivated, so if they leak from a device, someone may be able to operate AWS with the same permissions as the owner.

After migrating to aws login, no keys without an expiration remain on each user's device, and even if credentials leak, they become unusable after 12 hours at most. Once you delete the keys, the Security Hub CSPM IAM.3 finding also disappears. Even in environments where you cannot use AWS Organizations or IAM Identity Center, you can achieve this while remaining with IAM users.

References

Setting up and permissions for aws login:

Security Hub CSPM:

Share this article

AWSのお困り事はクラスメソッドへ