Sub topic 4
Creating analyzers and choosing a tracking period
This chapter assumes you can read IAM policy JSON, use the AWS CLI, and know what an AWS account and an AWS Organizations organization are. It also assumes you have met the two analyzer kinds (external access and unused access) and the idea of a zone of trust. Here you will create both kinds with the CLI, choose an unused-access tracking period, and check that the result works.
What an analyzer is
An analyzer is a regional resource in your account. It defines two things: what it analyzes (external access or unused access) and its scope (one account or a whole organization). Findings belong to the analyzer that produced them. If you delete the analyzer, its findings go with it.
The --type option of create-analyzer selects both choices at once:
| `--type` value | Finds | Scope (zone of trust) |
|---|---|---|
| `ACCOUNT` | External access | The current account |
| `ORGANIZATION` | External access | The whole organization |
| `ACCOUNT_UNUSED_ACCESS` | Unused access | The current account |
| `ORGANIZATION_UNUSED_ACCESS` | Unused access | Every account in the organization |
For external access, scope decides what counts as "outside". With ACCOUNT, a role in another account of your organization that reads your bucket produces a finding. With ORGANIZATION, that same access is inside the zone of trust and produces no finding.
Creating an external access analyzer
The simplest analyzer needs only a name and a type.
aws accessanalyzer create-analyzer \
--analyzer-name account-external \
--type ACCOUNTThe command returns the analyzer ARN. Save it, because most later commands (list-findings-v2, create-archive-rule) need the ARN or the name.
The first call also creates the service-linked role AWSServiceRoleForAccessAnalyzer. Access Analyzer uses this role to read resource configurations in your account. You need permission to create it the first time (iam:CreateServiceLinkedRole) along with access-analyzer:CreateAnalyzer.
Regions matter
An analyzer only examines resources in the Region where you create it. An S3 bucket policy is global in effect, but the analyzer that reports on it lives in the bucket's Region. A single analyzer in us-east-1 will not see a KMS key or an SQS queue in eu-west-1.
To cover your environment, create the analyzer in every Region you use. Many teams also create one in Regions they do not use. A resource created there by mistake or by an attacker would then still be reported.
for region in us-east-1 us-west-2 eu-west-1; do
aws accessanalyzer create-analyzer \
--region "$region" \
--analyzer-name account-external \
--type ACCOUNT
doneQuotas limit how many analyzers of each type you may have per Region. The limits can change, so check Service Quotas for your account instead of assuming a number.
Creating an unused access analyzer
An unused access analyzer needs one more piece: a configuration that sets the tracking period.
aws accessanalyzer create-analyzer \
--analyzer-name account-unused \
--type ACCOUNT_UNUSED_ACCESS \
--configuration '{"unusedAccess":{"unusedAccessAge":90}}'unusedAccessAge is a number of days. Access Analyzer compares the last-accessed information that IAM keeps against this threshold. Anything not used within that many days becomes a finding. The value must be between 1 and 365, and the default is 90 if you omit the configuration.
Unused access analysis covers IAM users and roles in the analyzed accounts. It reports these things:
- Roles with no activity inside the period (
UnusedIAMRole). - Users with access keys or passwords that have not been used (
UnusedIAMUserAccessKey,UnusedIAMUserPassword). - Permissions that a role or user holds but has not exercised (
UnusedPermission).
Unused access analyzers are also regional in how you create and read them. IAM itself is global, but the analyzer that holds the findings lives in one Region. Create one unused access analyzer in a single Region that you will use as your reporting home. A second one in another Region only duplicates the findings and the cost.
Choosing a tracking period
The tracking period is the most consequential setting you choose at creation. It controls how many findings you get and how safe each one is to act on.
- A short period (for example 30 days) produces many findings. Some will be false alarms for roles that run on a longer cycle.
- A long period (for example 365 days) produces fewer findings, and each one is better supported. The cost is that unused access stays in place longer before you see it.
Pick the period from the slowest legitimate cycle in your workloads. A quarterly reporting job runs once every 90 days or so. If your period is 90, that job's role may look unused on the day it is about to run. A period of 120 or more avoids this. Annual processes, such as a year-end close or a disaster recovery drill, need up to 365.
| Situation | Reasonable period |
|---|---|
| Fast-moving dev and sandbox accounts | 30 to 60 days |
| General production workloads | 90 days |
| Quarterly batch jobs or audits | 120 to 180 days |
| Annual jobs, disaster recovery roles | 365 days |
You can run more than one unused access analyzer with different periods in the same Region, subject to quotas. A common pattern is a strict 30-day analyzer for sandbox accounts and a conservative 365-day one for production.
Two details affect how you read results:
- A new analyzer does not see history beyond what IAM already tracks. IAM last-accessed data covers roughly the last 400 days for services, but Access Analyzer reports only what falls outside your chosen period.
- After creation, the first scan takes a while. An empty finding list a few minutes after creation does not mean you have no unused access.
Excluding accounts or resources
For organization-wide analyzers, you often need to leave out accounts or roles that are expected to be idle, such as break-glass roles. The unused access configuration accepts an analysis rule with exclusions, either by account ID or by resource tag.
aws accessanalyzer create-analyzer \
--analyzer-name org-unused \
--type ORGANIZATION_UNUSED_ACCESS \
--configuration '{
"unusedAccess": {
"unusedAccessAge": 180,
"analysisRule": {
"exclusions": [
{"accountIds": ["444455556666"]},
{"resourceTags": [{"access-review": "exempt"}]}
]
}
}
}'An exclusion removes the resource from analysis entirely. Compare this with an archive rule, which still lets the finding be generated and then hides it. An exclusion also avoids the per-resource analysis charge. Use exclusions sparingly, because an excluded role is invisible to this analyzer.
Organization analyzers
Organization-scope analyzers (ORGANIZATION and ORGANIZATION_UNUSED_ACCESS) can be created only from the organization's management account or from an account registered as the delegated administrator for Access Analyzer. In most cases use the delegated administrator, so that day-to-day security work does not run in the management account. Trusted access for access-analyzer.amazonaws.com must be enabled in AWS Organizations first.
aws organizations enable-aws-service-access \
--service-principal access-analyzer.amazonaws.com
aws organizations register-delegated-administrator \
--service-principal access-analyzer.amazonaws.com \
--account-id 111122223333Run the first command from the management account. The second registers the security account, here 111122223333, as the administrator. After that, sign in to the delegated administrator and run the same create-analyzer commands with the organization types.
Verifying the analyzers
List what you created and check type and status.
aws accessanalyzer list-analyzers \
--query 'analyzers[].[name,type,status,arn]' \
--output tableA status of ACTIVE means the analyzer is working. CREATING is normal for a short time after the call. FAILED includes a statusReason. The usual cause is a missing service-linked role permission or an organization that has not enabled trusted access.
To see the configured tracking period, read the analyzer back.
aws accessanalyzer get-analyzer \
--analyzer-name account-unused \
--query 'analyzer.configuration'Changing or removing an analyzer
An analyzer's name and type cannot be changed. If you chose the wrong type, delete the analyzer and create a new one. For the tracking period, check aws accessanalyzer help in your CLI version. If an update-analyzer command is present, use it to change the configuration in place. Otherwise delete and recreate.
aws accessanalyzer delete-analyzer --analyzer-name account-unusedCommon mistakes
- One analyzer in one Region. External access in other Regions goes unreported. Create the analyzer in each Region you use.
- Wrong scope. An
ACCOUNTanalyzer in a multi-account organization floods you with findings for access between your own accounts. Use anORGANIZATIONanalyzer in the delegated administrator account. - Default period for everything. 90 days is a reasonable starting point, but it flags quarterly and annual roles. Look at your slowest workloads first.
- Acting on early findings. Removing access based on a finding from a short period risks breaking a workload that runs rarely. Chapter material on remediation covers how to do this safely.
Exercise
Your organization has a year-end financial close that runs once a year under a dedicated IAM role. You want an organization-wide unused access analyzer that does not flag this role as unused. Which type and tracking period do you choose, and from which account do you create it?
Show answer
Use ORGANIZATION_UNUSED_ACCESS with unusedAccessAge set to 365, because the role is used about once every 365 days and a shorter period would flag it between runs. Create it from the organization's management account or, better, from the delegated administrator account for Access Analyzer, after enabling trusted access for access-analyzer.amazonaws.com. An alternative is a shorter period plus an exclusion by resource tag for that role, but that hides the role from analysis completely.
Exercise
You created an ACCOUNT external access analyzer in us-east-1 and see no findings, but you know an SQS queue in eu-west-1 is shared with an unknown account. Why is there no finding, and how do you fix it?
Show answer
An analyzer only examines resources in the Region where it was created. Create an external access analyzer in eu-west-1 (with aws accessanalyzer create-analyzer --region eu-west-1 --analyzer-name account-external --type ACCOUNT), and the shared queue will then appear as a finding.