Safeguard
Security Guides•

How do you trim a CI role with IAM Access Analyzer?

Use IAM Access Analyzer to turn 90 days of CloudTrail activity into a tighter policy for a CI role. Steps, limits and the actions it cannot see.

Safeguard Security Team
4 min read

IAM Access Analyzer reads up to 90 days of CloudTrail activity for a role and drafts a policy containing only what the role used. For a CI role that started broad, this is a practical way to cut permissions, as long as you review the draft and know what it cannot see.

What policy generation does

AWS describes the feature this way: Access Analyzer reviews your CloudTrail logs and generates a policy template with the permissions the entity used in the date range you choose. You can then replace a broad policy on the role with the generated one.

A CI role is a good candidate. Pipelines are repetitive, so 30 to 90 days of history usually covers every real code path, including the monthly or release only jobs.

Steps

  1. Confirm a CloudTrail trail is enabled for the account. Policy generation needs one.
  2. Pick the role in the IAM console and choose the option to generate a policy from CloudTrail events.
  3. Choose the shortest time range that still covers your release cycle. AWS notes a range of up to 90 days is possible and shorter ranges generate faster.
  4. Select or create the service role that lets Access Analyzer read your trail, and select the trail.
  5. When generation finishes, review the actions and the list of services used. For some services you must add actions by hand.
  6. Replace the placeholder resource ARNs with real ones where the action supports resource level permissions.
  7. Save it as a managed policy, attach it to the role in a test account first, and run your pipeline.
  8. Detach the old broad policy once the pipeline passes.

AWS says you can view a generated policy in the console for seven days, so plan to finish the review in that window.

What it cannot see

AWS lists several limits. Read them before trusting the output.

LimitEffect on a CI role
No action level data for data events such as S3 object operationsArtifact uploads may show up at service level only
iam:PassRole is not tracked by CloudTrailA deploy role that passes roles will be missing that permission
Denied actions are included in the reviewFailed attempts can leak into the draft, so check them
Not meant for auditingUse CloudTrail itself to investigate activity

The PassRole gap matters most for deploy roles. If your pipeline creates a Lambda function or a compute service that takes a role, the generated policy will not include the pass permission, and the deploy will fail until you add a scoped statement. Our post on PassRole for deploy roles shows how to write one.

Review it like code

Treat the draft as a pull request against your own infrastructure. Look for wildcards that remain on resources, services you do not recognize, and actions that were only tried during a one time migration. Put the final policy in version control next to the pipeline so changes get reviewed.

Repeat the exercise every quarter. Pipelines drift, and permissions that were needed once tend to stay.

Quick check

How far back can Access Analyzer look?

Up to 90 days of CloudTrail events, per the AWS documentation. A shorter range generates faster.

Will the generated policy include iam:PassRole?

No. AWS states that PassRole is not tracked by CloudTrail and is not included, so add a scoped statement yourself if the role needs it.

Safeguard does not manage your cloud accounts. It scans your code and dependencies, applies pull request policies and gates, and automates compliance evidence. Try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.