Sub topic 3
External access and unused access analyzers
This chapter compares the two analyzer types that IAM Access Analyzer offers. It covers what each one inspects, what it reports, how each is scoped and billed, and how to choose between them. It assumes you can read IAM policy JSON, know the difference between identity-based and resource-based policies, and can run AWS CLI commands in an account that belongs to AWS Organizations. Creating analyzers in detail, and reading individual findings, come in later chapters.
Two analyzers, two questions
An analyzer is a regional Access Analyzer resource that continuously evaluates your account or organization and writes findings. The type you choose decides which question it answers.
- An external access analyzer asks: "Which resources can be reached by a principal outside my zone of trust?"
- An unused access analyzer asks: "Which identities, credentials and permissions inside my zone of trust have not been used?"
The first finds access that is too wide. The second finds access that is too old or too large to justify. A resource can be fine under one analyzer and flagged by the other. An IAM role with a tight trust policy produces no external finding, yet the same role can produce an unused role finding if nobody has assumed it for months.
External access analyzers
An external access analyzer examines the policies attached to supported resources and uses automated reasoning to determine every principal that can reach the resource. It does not send test requests. It reasons over the policy text, including conditions, so it can report access that would work even if no one has used it yet.
Supported resource types include:
- Amazon S3 buckets, access points and directory buckets
- IAM roles (through the role trust policy)
- AWS KMS keys
- AWS Lambda functions and layers
- Amazon SQS queues
- AWS Secrets Manager secrets
- Amazon SNS topics
- Amazon EBS snapshots
- Amazon RDS snapshots
- Amazon ECR repositories
- Amazon EFS file systems
- Amazon DynamoDB tables and streams
AWS adds resource types over time, so check the current documentation when you depend on one.
When a resource policy allows a principal that is outside the zone of trust, the analyzer creates a finding. The finding records the resource, the external principal, the actions granted, and any condition keys that narrow the access. Here is a policy that produces a public access finding on the bucket:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowEveryoneRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-bucket/*"
}
]
}Conditions change the result. If the same statement had a Condition that restricted aws:PrincipalOrgID to your organization, an organization-scoped analyzer would not report it, because every allowed principal sits inside the zone of trust.
When findings are generated
The analyzer scans a resource when you create the analyzer, again within about 30 minutes after a policy change, and periodically as a safety net. Treat the 30-minute figure as typical behavior and not a guarantee. If you fix a policy and the finding does not change at once, wait before concluding that the fix failed.
Cost and regional scope
External access analysis has no additional charge. The analyzer is regional, so it only sees resources in the Region where you create it. To cover an account, create an analyzer in every Region you use.
Unused access analyzers
An unused access analyzer reviews IAM principals, not resource policies. It uses last-accessed information that AWS already collects and compares it with a tracking period, the number of days without activity after which something counts as unused. The default is 90 days. You can set it from 1 to 365 days when you create the analyzer.
It produces four finding types:
| Finding type | What it reports | Typical action |
|---|---|---|
| `UnusedIAMRole` | A role that nobody assumed during the tracking period | Confirm the owner, then delete or disable |
| `UnusedIAMUserAccessKey` | An active access key not used during the period | Deactivate the key, then delete it |
| `UnusedIAMUserPassword` | A console password not used during the period | Remove the login profile or the user |
| `UnusedPermission` | A service or action granted by a policy but never called | Remove it from the policy |
The last type is the most useful and the hardest to act on. It tells you the role is used but only some of its granted permissions are. Later chapters cover how to use recommendations to rewrite such policies safely.
Cost
Unused access analysis is a paid feature. AWS charges per IAM role and user analyzed each month. The charge depends on the number of principals, not on the number of findings. Check current pricing before enabling it across a large organization.
Scope inside the analyzer
You can exclude parts of the zone of trust from analysis. This keeps sandbox accounts, break-glass roles or tagged resources out of the report so the remaining findings are worth reading. The analysisRule setting takes exclusions by account ID or by resource tag.
Zone of trust and analyzer type
Both families come in account and organization variants. The zone of trust is the set of principals you treat as trusted, so it decides what counts as "external".
| Analyzer type value | Family | Zone of trust or scope |
|---|---|---|
| `ACCOUNT` | External access | The single account |
| `ORGANIZATION` | External access | The whole organization |
| `ACCOUNT_UNUSED_ACCESS` | Unused access | Principals in the single account |
| `ORGANIZATION_UNUSED_ACCESS` | Unused access | Principals in all member accounts |
For external access, an ACCOUNT analyzer treats other accounts in your organization as outside the zone. A bucket shared with a sibling account therefore appears as a finding. An ORGANIZATION analyzer treats those accounts as trusted and stays quiet. For unused access, the scope only decides which principals are reviewed, since "unused" does not depend on who the caller is.
You create organization analyzers from the organization's management account or from a delegated administrator account for IAM Access Analyzer. Member accounts cannot create them.
Creating one of each
The following commands create the two account-level analyzers:
# External access analyzer for the current account
aws accessanalyzer create-analyzer \
--analyzer-name account-external \
--type ACCOUNT
# Unused access analyzer that flags access unused for 90 days
aws accessanalyzer create-analyzer \
--analyzer-name account-unused \
--type ACCOUNT_UNUSED_ACCESS \
--configuration '{"unusedAccess":{"unusedAccessAge":90}}'To cover the organization, run the equivalent commands from the management or delegated administrator account. This example also excludes one sandbox account from the unused access analysis:
aws accessanalyzer create-analyzer \
--analyzer-name org-external \
--type ORGANIZATION
aws accessanalyzer create-analyzer \
--analyzer-name org-unused \
--type ORGANIZATION_UNUSED_ACCESS \
--configuration '{"unusedAccess":{"unusedAccessAge":90,"analysisRule":{"exclusions":[{"accountIds":["444455556666"]}]}}}'Confirm what exists, and which type each analyzer has:
aws accessanalyzer list-analyzers \
--query 'analyzers[].[name,type,status]' \
--output tableUse list-findings-v2 to read findings. The older list-findings command only understands external access findings, so a tool that still calls it will miss unused access results.
aws accessanalyzer list-findings-v2 \
--analyzer-arn arn:aws:access-analyzer:us-east-1:111122223333:analyzer/account-unused \
--filter '{"status":{"eq":["ACTIVE"]}}' \
--query 'findings[].[findingType,resource,status]' \
--output tableGotchas and edge cases
- Regional coverage differs by family. IAM is global, so an unused access analyzer reports on the principals of the whole account and needs creating in one Region only. External access analyzers need one per Region you use. Creating unused access analyzers in several Regions duplicates findings and cost.
- Analyzer quotas apply. Each account has limits on analyzers per Region. If
create-analyzerfails with a quota error, review Service Quotas before deleting anything. - A short tracking period creates noise. Quarterly jobs, disaster recovery roles and annual audit access can look unused over 30 days. Pick a period longer than your slowest legitimate cycle, then shorten it as you gain confidence.
- Unused does not mean safe to delete. Last-accessed data has gaps for some services and actions, and a role used once a year will appear unused until it runs. Verify with the owner or with CloudTrail before removing anything.
- Findings are not instant. Unused access findings refresh on a roughly daily cycle, so a newly created analyzer needs time before it reports.
- A clean external analyzer is not a clean account. It only evaluates supported resource types and only reasons about policies. Access granted through an unsupported resource is invisible to it.
Choosing between them
Run both. They cost different amounts and solve different problems, so the decision is about order and scope.
- Start with an external access analyzer at the organization level. It is free and finds the highest-impact exposures, such as public buckets and open KMS key policies.
- Add an account or organization unused access analyzer once you have an owner for cleanup work. Without an owner, the findings accumulate unread and the cost buys nothing.
- Use a delegated administrator account so that security staff do not need the management account.
Exercise
A bucket policy in account A grants s3:GetObject to a role in account B. Both accounts are in the same organization. You have an ACCOUNT external access analyzer in account A and an ORGANIZATION external access analyzer in the management account. Which analyzer reports a finding, and why? Separately, which analyzer type would tell you that a role in account B has not been assumed for 200 days?
Show answer
The ACCOUNT analyzer in account A reports a finding, because its zone of trust is only account A and account B is external to it. The ORGANIZATION analyzer does not, because account B is inside the organization and so inside its zone of trust. To find the role unused for 200 days you need an unused access analyzer (ORGANIZATIONUNUSEDACCESS, or ACCOUNTUNUSEDACCESS created in account B) with a tracking period of 200 days or less. It would report an UnusedIAMRole finding.