Description
IAM allows two access keys per user so a workload can switch keys during rotation.
Potential impact
A forgotten active key still grants the IAM user's access if the key pair leaks.
Remediation
Prefer temporary role credentials. If a long-term key is required, switch each workload to the new key and test it. Deactivate the old key, verify continued operation, then delete it.
Examples
Both examples use the IAM user loadbalancer. The second keeps only primary. Set pgp_key to the recipient’s public key. For an existing deployment, keep the user's Terraform address or declare the move from aws_iam_user.lb to aws_iam_user.example. Check the plan before applying.
Before
hcl
resource "aws_iam_access_key" "primary" {
user = aws_iam_user.lb.name
pgp_key = "keybase:some_person_that_exists"
}
resource "aws_iam_access_key" "secondary" {
user = aws_iam_user.lb.name
pgp_key = "keybase:some_person_that_exists"
}
resource "aws_iam_user" "lb" {
name = "loadbalancer"
path = "/system/"
}
After
hcl
resource "aws_iam_user" "example" {
name = "loadbalancer"
path = "/system/"
tags = {
tag-key = "tag-value"
}
}
resource "aws_iam_access_key" "primary" {
user = aws_iam_user.example.name
pgp_key = "keybase:some_person_that_exists"
}