Sub topic 8
Archive rules for intended access
This chapter assumes you can read IAM and resource policies. It also assumes you have created an analyzer and seen findings in the console or the CLI, as in the earlier chapters. Here you learn how to mark access you meant to grant as expected, so the findings that remain deserve attention.
Why archive rules exist
An external access analyzer reports every resource policy that grants access outside the zone of trust. Some of that access is deliberate. A bucket may be shared with a partner account, or a role may be assumed by a vendor's monitoring tool. Left alone, these findings stay ACTIVE and bury the ones that matter.
An archive rule is a saved filter on an analyzer. Access Analyzer checks each finding against the analyzer's rules. If a finding matches, it moves to the ARCHIVED status without any manual step. You can still read archived findings. They are only hidden from the active list.
Archive rules do not change any access. They record your decision that a finding is expected. The bucket policy still grants what it granted before.
How a rule is evaluated
A rule has a name and a filter. The filter is a set of criteria, and each criterion is a finding attribute with one or more operators.
| Operator | Meaning |
|---|---|
| `eq` | The attribute equals one of the listed values |
| `neq` | The attribute equals none of the listed values |
| `contains` | The attribute contains one of the listed values as a substring |
| `exists` | The attribute is present (`true`) or absent (`false`) |
Two logic rules govern a filter:
- Several values inside one operator are combined with OR.
"eq": ["a", "b"]matchesaorb. - Several criteria in the same filter are combined with AND. A finding must satisfy every criterion to match.
Common attributes for external access findings include resource, resourceType, resourceOwnerAccount, isPublic, principal.AWS, and condition.* keys. Unused access analyzers use different attributes, such as findingType, resource, and resourceOwnerAccount.
The archive rule is also applied to existing findings, not only new ones. When a rule is created, matching active findings are archived. If you need to re-run a rule later, apply-archive-rule applies it to current findings.
Creating a rule for a known partner bucket
Suppose example-partner-share is shared with a partner account on purpose. This rule archives findings for that one bucket:
aws accessanalyzer create-archive-rule \
--analyzer-name account-external \
--rule-name known-partner-bucket \
--filter '{"resource":{"eq":["arn:aws:s3:::example-partner-share"]}}'This rule has a weakness. It archives every finding for that bucket, whoever the principal is. If someone later edits the bucket policy to grant access to *, the new public finding matches the rule and is archived silently.
Writing narrower rules
Add criteria so the rule describes the intended access and nothing wider. Each added criterion is ANDed, so the rule gets stricter.
aws accessanalyzer create-archive-rule \
--analyzer-name account-external \
--rule-name partner-bucket-partner-account-only \
--filter '{
"resource": {"eq": ["arn:aws:s3:::example-partner-share"]},
"principal.AWS": {"eq": ["444455556666"]},
"isPublic": {"eq": ["false"]}
}'This rule archives a finding only if all three hold:
- The finding is for that bucket.
- The external principal is account
444455556666. - The access is not public.
A policy change that adds another account, or opens the bucket to everyone, produces a finding that does not match. It stays ACTIVE and shows up for triage. Narrow rules turn Access Analyzer into change detection for the exceptions you approved.
The isPublic filter takes the string values "true" and "false". Verify your filter keys against the output of get-finding-v2 for a real finding. Attribute names must match what the finding reports.
Rules for unused access analyzers
Archive rules also work on unused access analyzers. The cases are different. You are not saying that sharing is intended. You are saying that a role or permission is expected to be unused.
Typical examples:
- A break-glass role that is only used during incidents. It will show as an unused role for months by design.
- A disaster recovery role that exists for a failover you hope never happens.
- A role in a sandbox account where unused access is accepted.
aws accessanalyzer create-archive-rule \
--analyzer-name account-unused \
--rule-name break-glass-role \
--filter '{
"findingType": {"eq": ["UnusedIAMRole"]},
"resource": {"eq": ["arn:aws:iam::111122223333:role/break-glass-admin"]}
}'Here the criteria name both the finding type and the resource. If the same role later gets an UnusedPermission finding, that is a different finding type and is not archived by this rule.
Managing rules over time
Rules need the same upkeep as other configuration. These commands cover the lifecycle:
aws accessanalyzer list-archive-rules --analyzer-name account-external
aws accessanalyzer get-archive-rule \
--analyzer-name account-external \
--rule-name known-partner-bucket
aws accessanalyzer update-archive-rule \
--analyzer-name account-external \
--rule-name known-partner-bucket \
--filter '{"resource":{"eq":["arn:aws:s3:::example-partner-share"]},"isPublic":{"eq":["false"]}}'
aws accessanalyzer apply-archive-rule \
--analyzer-arn arn:aws:access-analyzer:us-east-1:111122223333:analyzer/account-external \
--rule-name known-partner-bucket
aws accessanalyzer delete-archive-rule \
--analyzer-name account-external \
--rule-name known-partner-bucketThree behaviors catch people out:
update-archive-rulereplaces the whole filter. It does not merge new criteria into the old ones.- Deleting a rule does not reactivate findings it already archived. Those stay
ARCHIVEDuntil you change their status. - Rules belong to one analyzer. A rule on the account analyzer does nothing for an organization analyzer, so repeat it where you need it.
Archiving by hand versus by rule
For a one-off finding, archive it directly instead of writing a rule:
aws accessanalyzer update-findings \
--analyzer-arn arn:aws:access-analyzer:us-east-1:111122223333:analyzer/account-external \
--status ARCHIVED \
--ids FINDING_IDA manual archive applies to that one finding. If the resource policy changes in a way that creates a new finding, that finding appears as ACTIVE. A rule suits access that recurs or that you want to cover on future resources.
Auditing what you archived
Archived findings are your record of accepted risk, so review them. List them with a status filter:
aws accessanalyzer list-findings-v2 \
--analyzer-arn arn:aws:access-analyzer:us-east-1:111122223333:analyzer/account-external \
--filter '{"status":{"eq":["ARCHIVED"]}}' \
--query 'findings[].[resource,findingType,status]' \
--output tableReview on a schedule, such as quarterly. For each rule ask whether the partner relationship still exists, whether the named role still exists, and whether the filter is still as narrow as you meant it to be.
A useful habit is to put the reason in the rule name. partner-bucket-partner-account-only tells a reviewer more than rule1. Rule names cannot hold long text, so keep the full justification in a ticket or a runbook.
Common mistakes
- Filtering on the resource alone. The rule hides any later change on that resource. Add a principal or
isPubliccriterion. - Using
containsfor convenience. A substring such aspartnercan match unrelated resources. - Expecting a rule to fix anything. The risky policy is still in place. Archiving only hides the finding.
- Forgetting the rule after the need ends. A rule for a decommissioned partner keeps hiding findings if the same bucket is reused.
- Assuming rules are shared. Each analyzer needs its own rules.
Decision guide
| Situation | Action |
|---|---|
| A single finding is expected and will not recur | Archive it manually |
| The same access appears on many resources or repeatedly | Create a narrow archive rule |
| The access is not intended | Fix the policy and let the finding resolve |
| The access is intended but you are unsure the filter is narrow enough | Test the filter on current findings, then review the archived list |
Exercise
A rule has the filter {"resource":{"eq":["arn:aws:s3:::example-partner-share"]}}. Later, someone adds a statement to the bucket policy with "Principal": "*". Will the new public access finding be shown as ACTIVE? How would you change the rule so it would be?
Show answer
No. The rule matches on the resource only, so the new public finding for the same bucket is archived automatically and nobody sees it. Add criteria that describe the intended access, for example "principal.AWS" set to the partner account ID and "isPublic" set to "false". The public finding then fails the filter, stays ACTIVE, and appears in triage.
Exercise
You run delete-archive-rule on a rule that archived 12 findings. What status do those 12 findings have afterward, and what do you do if you want them active again?
Show answer
They stay ARCHIVED, because deleting a rule does not change findings it already archived. To make them active again, change their status back with update-findings, or review them with list-findings-v2 using a status filter of ARCHIVED.