How to rotate AWS IAM access keys without breaking CI/CD
An IAM user can hold two access keys, and that limit is the whole rotation strategy: run both for a while, move every consumer, then deactivate before you delete. Here's the sequence, the CLI for each step, and the CI/CD places people forget.
- Key format
- Access key IDs start with
AKIAfor long-term IAM user keys andASIAfor temporary STS credentials. Each pairs with a secret access key. - Keys per user
- At most two. That's what makes an overlap possible, and what blocks a rotation when both slots are taken.
- Where
- IAM console → Users → the user → Security credentials → Access keys.
- Shown once
- The secret access key can be retrieved only when the key is created. Lose it and you must create a new key.
- Last used
aws iam get-access-key-last-used, or the console’s “Last used” column.- Revoke
- Deactivate first (reversible), delete later. Anything still using a deactivated key stops working.
- Permissions
- Whatever the user's policies allow. Add an aws:SourceIp or aws:SourceVpc condition so a leaked key fails elsewhere.
- Better option
- AWS recommends temporary credentials (IAM roles) over long-term access keys; GitHub Actions can use OIDC.
- Keysquid
- Automatic, through a rotator IAM user that may touch only your app user's keys.
Rotate an access key, step by step
This is AWS’s documented order, with the commands. app-user is the IAM user your application runs as.
- Check there is a free slot. If the user already has two keys, delete an inactive one first. Never delete an active key you can’t account for.
aws iam list-access-keys --user-name app-user - Create the second key. It’s active immediately, and the response is the only time you’ll see its secret.
aws iam create-access-key --user-name app-user - Update every consumer with both values,
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY(CI/CD examples below). Both keys work in the meantime. - Confirm the old key is idle. AWS suggests waiting several days before going on, for anything that runs rarely.
aws iam get-access-key-last-used --access-key-id AKIA_OLD_KEY_ID - Deactivate the old key rather than deleting it. If something breaks, reactivate it, fix that consumer, and try again.
aws iam update-access-key --user-name app-user --access-key-id AKIA_OLD_KEY_ID --status Inactive - Delete it once you’re sure.
aws iam delete-access-key --user-name app-user --access-key-id AKIA_OLD_KEY_ID
Where AWS keys hide in CI/CD
The AWS console shows you the key; it can’t show you who has a copy. These are the usual places:
- GitHub Actions repository or environment secrets. Update both values per repo:
gh secret set AWS_ACCESS_KEY_ID --repo acme/api --env production gh secret set AWS_SECRET_ACCESS_KEY --repo acme/api --env production - Vercel environment variables, per environment (production, preview, development). A changed variable applies only to new deployments, so redeploy afterwards.
- Railway, Render, Fly.io service variables: changing them usually triggers a redeploy, which is what you want here.
- Developers’
~/.aws/credentialsfiles, where keys are stored in plain text. If a person has the app’s key locally, that’s a reason to rotate on its own.
Better than rotating: for GitHub Actions, replace the stored key with OpenID Connect. The workflow assumes an IAM role and gets temporary credentials for each run, so there is no long-lived key to leak. AWS recommends temporary credentials over long-term access keys wherever they work.
By hand vs. with Keysquid
By hand
- Notice the key is 90 days old.
- Free a slot, create the key, copy the secret.
- Update GitHub, Vercel, Railway and anything else.
- Wait days; check last use.
- Deactivate, then delete.
With Keysquid
- A schedule you set (daily, hourly or every 15 minutes on higher plans).
- Keysquid creates the key and checks it with STS before using it.
- It writes both values to every mapped platform and redeploys.
- After the grace period it deactivates and deletes the old key.
How Keysquid handles AWS keys
Automatic Keysquid creates, verifies, distributes and revokes AWS IAM keys on a schedule, with no one in the loop. Access key pairs for an IAM user (2 keys max per user, handled for you).
Setup, as the app shows it:
- Create a dedicated IAM user “keysquid-rotator” with no console access.
- Attach a policy allowing only iam:ListAccessKeys, iam:CreateAccessKey, iam:UpdateAccessKey and iam:DeleteAccessKey on arn:aws:iam::<account>:user/<your-app-user>.
- Create an access key for the rotator user and paste it here.
- Writes to: Access key ID (default variable AWS_ACCESS_KEY_ID), Secret access key (default variable AWS_SECRET_ACCESS_KEY), in every platform and secret store you map it to.
- Interval: from every 1 hour to every 4 weeks, subject to your plan’s minimum.
- Lock the user to your network (set in AWS IAM): Add a Deny statement with an aws:SourceIp (or aws:SourceVpc) condition to the app user's policy. A leaked key then fails anywhere else.
Every rotation runs in the same order: create the new key, verify it, write it everywhere, redeploy where a platform needs it, and only then revoke the previous key after a grace period. If any write fails, everything written so far is restored and the new key is revoked. The value is encrypted to the agent you run, so Keysquid’s servers never see it.
The rotator user’s policy is limited to iam:ListAccessKeys, iam:CreateAccessKey, iam:UpdateAccessKey and iam:DeleteAccessKey on your app user’s ARN, so it can’t touch any other user. When the app user already has two keys, Keysquid only ever deletes an inactive one to make room. If both are active it stops and tells you, rather than guess which key is safe to remove.
If an AWS access key leaked
- Deactivate it immediately with
update-access-key --status Inactive. That’s reversible; a public key’s exposure isn’t. - Check CloudTrail for calls made with that access key ID, especially new IAM users, new access keys and EC2 instances in regions you don’t use.
- Assume the secret leaked with it. An access key ID on its own isn’t enough to sign requests, but the two are almost always stored together.
Frequently asked questions
How many access keys can an IAM user have?
Two. That limit is why a rotation creates the second key, moves every consumer to it, and then deactivates and deletes the first.
Should I delete the old access key straight away?
No. AWS recommends deactivating it first. A deactivated key can be reactivated if something still depended on it; a deleted one can't.
How do I know if an old access key is still in use?
Run aws iam get-access-key-last-used with the key's ID, or look at the Last used column on the user's Security credentials tab. Wait long enough for jobs that run rarely.
What's the difference between AKIA and ASIA keys?
AKIA access key IDs are long-term keys belonging to an IAM user and stay valid until deleted. ASIA IDs are temporary credentials from AWS STS, such as an assumed role, and expire on their own.
Is there an alternative to rotating access keys in GitHub Actions?
Yes: OpenID Connect. The workflow assumes an IAM role and receives short-lived credentials for each run, so there is no stored key to rotate or leak.