1. 程式人生 > >How to Rotate Access Keys for IAM Users

How to Rotate Access Keys for IAM Users

Changing access keys (which consist of an access key ID and a secret access key) on a regular schedule is a well-known security best practice because it shortens the period an access key is active and therefore reduces the business impact if they are compromised. Having an established process that is run regularly also ensures the operational steps around key rotation are verified, so changing a key is never a scary step.

In an earlier post, we described Identity and Access Management (IAM) roles for Amazon EC2. If you run applications on EC2 that need access to AWS services, we strongly recommend using this feature. Roles use temporary security credentials that auto-expire and auto-renew, so you don’t have to worry about access key rotation – AWS does it for you. However, if you are running applications somewhere other than on EC2, you should add access key rotation to your application management process. In this post, Cristian Ilac, software development manager on the IAM team, will walk you through the steps to rotate access keys for an IAM user. 

To rotate access keys, you should follow these steps:

  1. Create a second access key in addition to the one in use.
  2. Update all your applications to use the new access key and validate that the applications are working.
  3. Change the state of the previous access key to inactive.
  4. Validate that your applications are still working as expected.
  5. Delete the inactive access key.

Key Rotation Example

Here’s an example of the key rotation steps listed above. You are an administrative IAM user and will use the AWS Command Line Interface (CLI) to rotate access keys for a single user, Alice. The CLI uses IAM APIs, so the same steps can be performed programmatically via the AWS SDK, or using the web-based UI of the IAM Management Console like we showed in a previous post. Because keys are considered sensitive information, you should perform all of these commands only on a trusted computer.

After installing the CLI, run the following command to see what Alice’s access keys are:

aws iam list-access-keys --user-name Alice

The command returns something like this:

{
    "AccessKeyMetadata": [
        {
            "UserName": "Alice",
            "Status": "Active",
            "CreateDate": "2013-04-03T18:49:57Z",
            "AccessKeyId": "AKIAI44QH8DHBEXAMPLE"
        }
    ]
}

Step 1: Create a second access key

Create a new (second) access key for Alice using this command:

aws iam create-access-key --user-name Alice

This returns:

{
    "AccessKey": {
        "UserName": "Alice",
        "Status": "Active",
        "CreateDate": "2013-09-06T17:09:10.384Z",
        "SecretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY",
        "AccessKeyId": “AKIAIOSFODNN7EXAMPLE"
    }
}

Notice that AWS IAM commands use unique access key identifiers (AKIDs) to refer to individual access keys. You can use the AKIDs to identify and manage the access keys your application uses. Key creation is the only time AWS will expose the secret associated with the access key in clear text. Record it and store it securely.

Now Alice has two active access keys. Note that AWS only allows for two keys per user.  If you already have two active access keys, you will not be able to create a third one.

Listing the keys using the list-access-keys command shows both keys:

aws iam list-access-keys --user-name Alice
{

    "AccessKeyMetadata": [
        {
            "UserName": "Alice",
            "Status": "Active",
            "CreateDate": "2013-04-03T18:49:57Z",
            "AccessKeyId": "AKIAI44QH8DHBEXAMPLE"
        },
        {
            "UserName": "Alice",
            "Status": "Active",
            "CreateDate": "2013-09-06T17:09:10.384Z",
            "AccessKeyId": "AKIAIOSFODNN7EXAMPLE"
        }
    ]
}

Step 2: Distribute your access key to all instances of your applications

After creating the new key, you will distribute it and instruct your application to transition to using it.  Before moving on to the next step ensure that all instances of your application are indeed using it and that they function correctly.

Step 3: Change the state of the previous access key to inactive.

Disable the old access key using this command:

aws iam update-access-key --access-key-id AKIAI44QH8DHBEXAMPLE --status Inactive --user-name Alice

To verify that the key has been disabled, use this command to list the active and inactive keys for Alice:

aws iam list-access-keys --user-name Alice

You’ll see something like this:

{
    "AccessKeyMetadata": [
        {
            "UserName": "Alice",
            "Status": "Inactive",
            "CreateDate": "2013-04-03T18:49:57Z",
            "AccessKeyId": "AKIAI44QH8DHBEXAMPLE"
        },
        {
            "UserName": "Alice",
            "Status": "Active",
            "CreateDate": "2013-09-06T17:09:10.384Z",
            "AccessKeyId": "AKIAIOSFODNN7EXAMPLE"
        }
    ]
}

Step 4: Validate that your application is still working as expected

Once the key has been marked inactive, it cannot be used for authenticating AWS service API calls; therefore, you should verify at this point that your application still works. That’s why we just disabled the old access key first: if something were to go wrong, you could quickly re-enable the previous access key using the aws iam update-access-key command.

Step 5: Delete the inactive access key.

The last step is deleting the inactive access key by using this command:

aws iam delete-access-key --access-key-id AKIAI44QH8DHBEXAMPLE --user-name Alice

Note that the deleting action – unlike disabling the access key – is an irreversible operation. After deletion completes, an access key is no longer available. You can list Alice’s access keys again to confirm that you removed the old access key:

aws iam list-access-keys --user-name Alice

The old access key is gone from the results:

{
    "AccessKeyMetadata": [
        {
            "UserName": "Alice",
            "Status": "Active",
            "CreateDate": "2013-09-06T17:09:10.384Z",
            "AccessKeyId": "AKIAIOSFODNN7EXAMPLE"
        }
    ]
}

Conclusion:

If you’re using EC2 instances, we recommend using roles for EC2 in order to automatically rotate access keys.  If you are not using EC2, we suggest manually rotating keys on a periodic basis as a security best practice. For more information on access keys and rotation procedures, please visit the AWS IAM documentation.

– Ben

相關推薦

How to Rotate Access Keys for IAM Users

Changing access keys (which consist of an access key ID and a secret access key) on a regular schedule is a well-known security best practice beca

Managing Access Keys for IAM Users

Managing Access Keys for IAM Users

How to Change Default Location for Outlook Data File (PST & OST)

note right folder dialog https error data locate http Is there a way to change the default location of new .pst file when create a new e-

How to setup a slave for replication in 6 simple steps with Percona XtraBackup

second path binlog ica direct isam fetch owin value Data is, by far, the most valuable part of a system. Having a backup done systema

WPS 2019 How To Create New Sheets For Each Row In Excel?

https://www.extendoffice.com/documents/excel/3197-excel-create-new-sheet-for-each-row.html  How To Create New Sheets For Each Row In Excel? &nbs

【 InkGenius】Good developers who are familiar with the entire stack know how to make life easier for those around

Good developers who are familiar with the entire stack know how to make life easier for those around

How To Use SSH Keys connect to Linux server

如何透過 pub key 不用打密碼連進 linux server 裡,當然可以把密碼設的超級長,之後就透過 pub key 登入比較有效率。在 ssh client side 拿到的 key 在第1 次 ssh 時還是可以使用 id/password 方式去登入,再透過 vi ~/.ssh/authori

How to build a case for a product redesign

The overarching theme that emerged was that our product’s information hierarchy was unclear, which I pitched to stakeholders as the primary problem we shou

Android Developers Blog: how to develop audio apps for android

Posted by Don Turner, Developer Advocate, Android Audio Framework This week we released the first production-ready version of Oboe - a C++ library f

How to Conduct UX Research For Your Product

When you come up with a brilliant idea for a future product, you have no doubt about its success. You present it to your team, they tell you what you want

Instruction: How to Accept Bitcoin Payments for Your Store

If you or someone you know runs a business where transactions are frequently made, you might want to consider accepting Bitcoin payments from your customer

Ask HN: How to check the market for your saas product?

I have just finished a small tool that I would like to offer as saas. It is a very simple API that users can use from their terminal through curl/wget.Stil

How to write winning dialogue for Conversational UI đź’Ą

How to write winning dialogue for Conversational UI 💥And what you can learn from novelists and screenwritersNow that chatbots are taking over, writing

How to Reshape Input Data for Long Short

Tweet Share Share Google Plus It can be difficult to understand how to prepare your sequence dat

How to Use Power Transforms for Time Series Forecast Data with Python

Tweet Share Share Google Plus Data transforms are intended to remove noise and improve the signa

How to Build an Intuition for Machine Learning Algorithms

Tweet Share Share Google Plus Machine learning algorithms are complex. To get good at applying a

Oral Presentations: Tips on How to Deliver a Speech for School or Work

http://jerz.setonhill.edu/writing/technical-writing/oral-presentations-tips/ This document briefly describes how to write and deliver a

How to specify the orientation for an activity ?

unspecified -1 No preference specified: let the system decide the best orientation. This will either be the orientation selected by the activity below, or

How to build Clang toolchains for Android NDK from source code

we have some source changes to LLVM/Clang need add into NDK. After download and change "external/llvm" and build NDK from source. It find

How to create never expires Access Token for Facebook Page

How to create never expires Access Token for Facebook PageCreate an app from https://developers.facebook.com/ . Give necessary information and create the a