Sub topic 10
Using policy recommendations to right-size permissions
This chapter assumes you can read IAM policy JSON, you know the difference between identity-based and resource-based policies, and you have an unused access analyzer running. If you have not created one yet, the earlier chapter on creating analyzers shows how.
What a recommendation is
An unused access finding tells you that a role or user has permissions nobody has used within the tracking period. A policy recommendation is the next step: it tells you what to change. For findings of type UnusedPermission, Access Analyzer suggests which statements or actions to remove from the identity-based policy. For an UnusedIAMRole or UnusedIAMUserAccessKey finding, the recommended step is to delete the role or key, or to disable it first.
Recommendations come from the same service last accessed data that produces the finding. They are only as good as the tracking period you chose. A 90-day window will miss a quarterly job, so check the period before you act.
Retrieving a recommendation
Use the finding ID from list-findings-v2.
aws accessanalyzer get-finding-recommendation \
--analyzer-arn arn:aws:access-analyzer:us-east-1:111122223333:analyzer/account-unused \
--id FINDING_IDThe response includes a recommendationType and a list of recommended steps. For unused permissions, the steps name the policy and the actions to remove. The console shows the same information as a suggested replacement policy that you can compare with the current one.
A safe workflow
Apply recommendations in small steps, so you can undo each one.
- List active findings and pick one role.
- Retrieve the recommendation and read the proposed removals.
- Ask the owner of the workload whether any rare job relies on the permission, such as a year-end report or a disaster recovery runbook.
- Apply the change to a copy of the policy in your infrastructure-as-code repository, not by hand in the console.
- Deploy it, then watch CloudTrail for
AccessDeniedevents from that role. - If nothing breaks, resolve the finding. Access Analyzer marks it resolved on its next scan.
If something does break, restore the previous policy version. Customer managed policies keep up to five versions, so rollback is a single call.
Common errors
| Problem | Cause | Fix |
|---|---|---|
| Recommendation call returns an error for a finding | The finding is an external access finding, which has no recommendation | Use `list-findings-v2` and filter on unused finding types |
| Removing a permission breaks a monthly job | The tracking period is shorter than the job interval | Raise `unusedAccessAge` or confirm usage with the owner first |
| Finding stays active after the change | The next scan has not run yet | Wait for the next scan, then recheck |
| Recommendation covers only part of the access | Permissions also come from another attached policy | Review every policy attached to the principal |
Where this fits
Recommendations handle permissions that already exist. To check that a future change does not add new access, use the custom policy checks covered in a later chapter. Together they keep policies from drifting back to broad access.
Exercise
A role has an UnusedPermission finding for s3:DeleteObject. The tracking period is 90 days, and the role's owner says a yearly cleanup job needs that action. What should you do?
Show answer
Do not remove the permission yet. The 90-day window cannot see a yearly job, so the finding is a false signal for this action. Either keep the permission and archive the finding with an archive rule, or increase the tracking period if it is practical. Then document why the permission stays.
Exercise
After you deploy a reduced policy, which two signals tell you whether to keep it or roll it back?
Show answer
Check CloudTrail for AccessDenied events from the role, which means you removed something that was needed and should restore the previous policy version. Check the finding status after the next scan, because a resolved finding means the change took effect.