Sub topic 3
External access and unused access analyzers
This chapter assumes you know IAM users, roles, and identity-based and resource-based policies. It also assumes you can read a JSON policy and run AWS CLI commands. An analyzer is the Access Analyzer resource that scans your environment and produces findings. Each analyzer has one type, and the type decides what it looks for.
Two questions, two analyzers
Access Analyzer answers two different questions:
- Who outside my zone of trust can reach this resource? An external access analyzer answers this.
- Which identities or permissions inside my account does nobody use? An unused access analyzer answers this.
External access analyzers
An external access analyzer examines resource-based policies and sharing settings. It covers resources such as S3 buckets, IAM roles, KMS keys, Lambda functions, SQS queues, SNS topics and Secrets Manager secrets. It reports a finding when a policy lets a principal outside your zone of trust reach the resource. The bucket policy below, with "Principal": "*", produces a public access finding:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowEveryoneRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-bucket/*"
}
]
}The zone of trust is either a single account (type ACCOUNT) or an entire organization (type ORGANIZATION). Access from inside the zone is not reported.
Unused access analyzers
An unused access analyzer examines identities, not resources. It compares what each IAM role and user has been granted with what it has actually used. It reports these finding types:
UnusedIAMRole: a role not used within the tracking period.UnusedIAMUserAccessKey: an access key not used within the period.UnusedIAMUserPassword: a console password not used within the period.UnusedPermission: a service or action permission that was granted but never used.
The tracking period is the number of days without use before a finding is created. The default is 90 days. You can set it from 1 to 365 days when you create the analyzer.
Creating one of each
Account-level types are ACCOUNT and ACCOUNT_UNUSED_ACCESS. The organization-level types are ORGANIZATION and ORGANIZATION_UNUSED_ACCESS. The next chapter covers organization analyzers in detail.
# 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}}'Confirm that both exist:
aws accessanalyzer list-analyzers --query 'analyzers[].[name,type,arn]' --output tableChoosing between them
| Aspect | External access analyzer | Unused access analyzer |
|---|---|---|
| Question answered | Who outside can reach this resource? | What granted access is never used? |
| What is scanned | Resource policies and sharing settings | IAM roles, users, credentials, permissions |
| Key setting | Zone of trust (account or organization) | Tracking period in days |
| Typical fix | Narrow the policy or archive an intended share | Delete the role or key, or remove permissions |
| Pricing | No charge | Charged per analyzed role or user |
Check current pricing before you enable the unused access analyzer across many accounts.
Exercise
A role has an administrator policy but only ever calls S3 and DynamoDB. Which analyzer type reports this, and which finding type does it use? Which analyzer would you use to find an SQS queue that any AWS account can send messages to?
Show answer
The unused access analyzer reports the role's unused service permissions as UnusedPermission findings. An external access analyzer reports the SQS queue, because its resource policy grants access to principals outside the zone of trust.