Review active access keys for an IAM user

Confirm the owner and purpose of IAM access keys and remove unnecessary long-term credentials.

Description

aws_iam_access_key manages IAM user keys. Check the owner's policies, key status and last use to identify workloads that can move to temporary role credentials.

Potential impact

A leaked active key pair grants the IAM user's permissions. Retiring a key before its workloads switch can interrupt them.

Remediation

  • Move each workload to the role and test it. Deactivate the old key, check the workloads again, then delete it. Limit any remaining IAM user's permissions and protect secret keys and Terraform state.
  • Check the AWS account root user separately. Remove its access keys and enable MFA for root sign-in.

Examples

Set pgp_key to the intended recipient's public key.

Before

hcl
resource "aws_iam_access_key" "root_access_key" {
  user    = "root"
  pgp_key = "keybase:some_person_that_exists"
  status  = "Active"
}

user = "root" creates an active key for an existing IAM user named root.

After

hcl
resource "aws_iam_user" "automation_user" {
  name = "loadbalancer"
  path = "/system/"
}

resource "aws_iam_access_key" "automation_access_key" {
  user    = aws_iam_user.automation_user.name
  pgp_key = "keybase:some_person_that_exists"
}

The second example creates loadbalancer and a new key. Omitting status makes the key active. Configure the user's permissions and secure delivery of the secret key. Check the Terraform plan before applying so the old key stays available until its workloads have switched.

References