Sub topic 9
Removing unused access without breaking workloads
An unused access finding says that something looks unused. It does not say that removing it is safe. This chapter covers how to turn a finding into a change that you can reverse until you are confident.
This chapter assumes you can read the findings described in the previous chapters, that you have an unused access analyzer running, and that you can edit IAM policies with the AWS CLI. It also assumes you know the difference between an identity policy and a role trust policy.
Why unused is not the same as unnecessary
An unused access analyzer reports what it did not observe during the tracking period. The default period is 90 days. The shortest period you can set is 1 day and the longest is 365. Anything that runs less often than the period can look unused while still being needed.
Typical false positives:
- A quarterly or annual batch job. A 90-day window may miss it.
- A disaster recovery role that is meant to sit idle until a failover.
- A break-glass role for emergencies.
- A role that was created recently. It may not have had time to be used.
- A role that a pipeline assumes only on certain branches or release types.
- Service-linked roles, which AWS services create and manage. Do not delete these because of a finding.
Removing access is also harder to undo than adding it. A deleted access key cannot be restored, and a deleted role loses its trust policy and attached policies. You can recreate these, but only if you saved their contents first.
Match the action to the finding type
Each finding type calls for a different action. The table lists the lightest reversible step and the final step for each.
| Finding type | Reversible first step | Final step |
|---|---|---|
| `UnusedIAMUserAccessKey` | Set the key to `Inactive` | Delete the key |
| `UnusedIAMUserPassword` | Notify the owner and confirm they no longer sign in | Delete the login profile |
| `UnusedIAMRole` | Attach an explicit deny policy as a canary | Delete the role |
| `UnusedPermission` | Remove the unused statements or actions, keeping the old policy version | Keep the new version as the default |
An inactive access key is the best example of a reversible step. You can set it back to Active at any time.
A staged workflow
A safe removal runs in stages. At each stage you wait, watch for failures, and decide whether to continue.
Step 1: Establish context
Collect the facts before you change anything. Read the finding, then check the resource directly.
# When was the role last used, and in which Region?
aws iam get-role \
--role-name nightly-report-role \
--query 'Role.[RoleName,CreateDate,RoleLastUsed,Tags]'
# When was this access key last used?
aws iam get-access-key-last-used --access-key-id AKIAEXAMPLEKEYIDRoleLastUsed is empty if the role has never been used. Compare the creation date with the tracking period. If the role is younger than the period, the finding says little.
Also check tags and naming for an owner. If you cannot find an owner, treat that as a finding of its own. The next stage will bring the owner forward.
Step 2: Disable instead of delete
For an access key, set it to inactive:
aws iam update-access-key \
--user-name build-user \
--access-key-id AKIAEXAMPLEKEYID \
--status InactiveA caller that still uses the key will get an authentication error. The caller can be identified from the failed request, and you can reactivate the key with --status Active.
IAM has no "disabled" state for a role, so use an explicit deny policy as a canary. An explicit deny overrides every allow, so the role can no longer do anything, but its trust policy and permissions stay in place.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "TemporaryCanaryDenyAll",
"Effect": "Deny",
"Action": "*",
"Resource": "*"
}
]
}Save this as canary-deny.json and attach it as an inline policy:
aws iam put-role-policy \
--role-name nightly-report-role \
--policy-name TemporaryCanaryDenyAll \
--policy-document file://canary-deny.jsonTo roll back, delete only that inline policy:
aws iam delete-role-policy \
--role-name nightly-report-role \
--policy-name TemporaryCanaryDenyAllAttaching the deny does not stop sessions that were already issued from being denied. Because the deny applies at evaluation time, the existing sessions also lose access immediately. That is the point, but make sure nobody is running a long job under the role at that moment.
Step 3: Observe through a full usage cycle
Wait at least as long as the longest usage cycle you know of for that workload. A monthly job needs more than a month. Tell the owner the date you plan to delete.
Watch for failures. In CloudTrail, a denied call from the canary role appears with an AccessDenied or UnauthorizedOperation error code and the role's ARN as the principal. You can create a CloudWatch Logs metric filter or an EventBridge rule on those events, so you hear about the failure sooner than the owner does.
Step 4: Delete or restore
If nothing failed, delete the resource. Remove attached and inline policies, remove the role from instance profiles, and then delete the role:
aws iam delete-role-policy --role-name nightly-report-role --policy-name TemporaryCanaryDenyAll
aws iam list-attached-role-policies --role-name nightly-report-role
aws iam list-role-policies --role-name nightly-report-roleDetach or delete anything listed, then:
aws iam delete-role --role-name nightly-report-roleBefore this step, save the trust policy and policies to a file or to version control. That gives you a way to recreate the role if a rare job fails later.
If something failed, restore access and decide what to do with the finding. If the access is intended but rare, archive the finding with an archive rule so it does not return. Better still, document why the role is needed in a tag.
Shrinking permissions instead of removing identities
For an UnusedPermission finding, the identity is still in use, but some of its permissions are not. Ask for the recommendation first:
aws accessanalyzer get-finding-recommendation \
--analyzer-arn arn:aws:access-analyzer:us-east-1:111122223333:analyzer/account-unused \
--id FINDING_IDFor unused permission findings, the recommendation describes which policies to detach or edit, and it can suggest a replacement policy. Treat it as a draft. It reflects only the tracking period, and it does not know about your rare jobs.
A safer way to apply a policy change:
- Create a new version of a customer managed policy, or edit the inline policy, and keep a copy of the old document. Customer managed policies keep up to five versions, so you can set an older version as the default again.
- Remove the unused actions only. Keep actions you know are needed for rare events, even if they appear unused.
- Check the new policy with
validate-policyand withcheck-no-new-access, which should confirm that the new policy grants nothing the old one did not. - Roll out to a non-production account or a single role first.
AWS-managed policies cannot be edited. If the unused permissions come from an AWS-managed policy, detach it and attach a customer managed policy that contains only what the identity needs.
Unused permission findings cover services and, for some services, individual actions. A service-level finding means no action from that service was used. When the recommendation is action-level, check that the unused actions are not part of a set that the application calls together.
Confirm the result
After the change, wait for Access Analyzer to rescan. Then list the findings:
aws accessanalyzer list-findings-v2 \
--analyzer-arn arn:aws:access-analyzer:us-east-1:111122223333:analyzer/account-unused \
--filter '{"status":{"eq":["RESOLVED"]}}' \
--query 'findings[].[findingType,resource,status]' \
--output tableA finding moves to RESOLVED once the unused access no longer exists. Rescans are not instant, so a finding can stay ACTIVE for a while after you fix it. Do not repeat the change because of that delay.
Common mistakes
- Deleting on the first scan. Findings from a new analyzer, or for a new role, rest on little history.
- Skipping the owner. A silent deletion turns an access cleanup into an outage.
- Archiving to make the list shorter. An archive rule hides future findings for matching resources. Use it only for access you have confirmed is intended.
- Forgetting dependencies. A role may be referenced in another account's trust policy, an instance profile, a Lambda function, or a CI/CD configuration. Search for the role ARN before you delete it.
- Removing the permission but not the trust. A role that nobody uses but anyone in another account can assume is still a risk. Review the trust policy as well.
Exercise
A finding reports that the role quarterly-close-role is unused, with a 90-day tracking period. The role was created 200 days ago and its owner says it runs once a quarter. What should you do, and why is deleting it directly a risk?
Show answer
Do not delete it. The quarterly job may fall just outside the 90-day window, so the finding does not prove the role is unnecessary. Confirm the owner and the schedule, then either archive the finding with a reason (and tag the role with its purpose and owner), or attach a deny canary and wait through a full quarter before deciding. Deleting would also lose the trust policy and permissions, which you could restore only if you had saved them first.
Exercise
You attached the TemporaryCanaryDenyAll inline policy to a role. Two days later a team reports that their job fails with AccessDenied. How do you roll back, and what should you do with the finding afterwards?
Show answer
Delete only the inline policy with aws iam delete-role-policy --role-name ROLE --policy-name TemporaryCanaryDenyAll. The role's trust policy and other permissions were never touched, so access returns. Then archive the finding, ideally through an archive rule that matches the role, and tag the role with its purpose and owner so it does not reappear.