Sub topic 9
Removing unused access without breaking workloads
This chapter assumes you can read IAM policies and use the AWS CLI. You should also have an unused access analyzer running, as set up in earlier chapters. A finding says that access went unused during the tracking period. It does not say the access is safe to remove, so this chapter covers how to remove it in reversible steps.
Why unused does not mean unneeded
The analyzer only sees activity inside its tracking period, for example 90 days. Some access is used less often than that:
- A year-end reporting role.
- A disaster recovery role that exists for an emergency.
- A break-glass user whose credentials should stay unused.
- A scheduled job that runs quarterly.
Deleting these on the strength of a finding can cause an outage months later. Treat each finding as a question for the resource owner.
A staged removal process
Step 1: identify the owner and the use
Check tags, the role's trust policy, and CloudTrail for the last known caller. Ask the team whether the access has a seasonal or emergency purpose. If it does, archive the finding. An archive rule can do this for a whole class of resources, such as roles tagged purpose=break-glass.
Step 2: disable before you delete
Each finding type has a reversible first step:
| Finding type | Reversible step | Final step |
|---|---|---|
| UnusedIAMUserAccessKey | Set the key to Inactive | Delete the key |
| UnusedIAMUserPassword | Delete the login profile only after the owner agrees, since the password cannot be restored | Delete the user |
| UnusedIAMRole | Attach an inline policy that denies all actions | Delete the role |
| UnusedPermission | Apply a narrowed policy, keeping the old version | Remove the old policy version |
Deactivating an access key is the simplest example:
aws iam update-access-key \
--user-name ci-deployer \
--access-key-id AKIAIOSFODNN7EXAMPLE \
--status InactiveIf a job fails, run the same command with --status Active and the key works again.
For a role, a deny-all inline policy stops use while keeping the role, its trust policy and its ARN. Callers get an explicit access denied error that names the role, so the failure is easy to trace.
Step 3: observe, then finish
Pick an observation period before you start, and make it longer than the longest cycle you know of, such as a month for monthly jobs. Watch CloudTrail for AccessDenied errors against the disabled role or key. If none appear, delete it. If one does, restore access and archive the finding so it stops reappearing.
Removing unused permissions
For an UnusedPermission finding, the role is in use but some of its permissions are not. Fetch the recommendation for the finding:
aws accessanalyzer get-finding-recommendation \
--analyzer-arn arn:aws:access-analyzer:us-east-1:111122223333:analyzer/account-unused \
--id FINDING_IDThe result lists the unused actions and the policy changes to remove them. Apply them as a new policy version rather than editing in place, so you can roll back. Test the change in a non-production account first when the role runs production workloads.
Exercise
A finding reports that the role quarterly-billing-export has been unused for 90 days. The role is deployed with a tag showing it is owned by the finance team. What should you do before deleting it, and what is a safe first action if the owner cannot be reached?
Show answer
Ask the finance team whether the role supports a job that runs less often than every 90 days, because a quarterly job can fall just outside the tracking period. If the owner cannot be reached, do not delete the role. Attach a deny-all inline policy, observe CloudTrail for AccessDenied errors for at least one full quarter, and remove the policy if something breaks.