Skip to content

skillDevOps and cloudaws

AWS IAM Least Privilege

Narrows AWS IAM policies to the actions and resources a workload really uses, based on code and access logs, with every change explained.

npx workspacetemplates add aws-iam-least-privilege --tool claude-code

Writes 1 file to .claude/skills/aws-iam-least-privilege/

.claude/skills/aws-iam-least-privilege/SKILL.md30 lines · 1.6 KBFile
---
name: aws-iam-least-privilege
description: Narrows AWS IAM policies to the actions and resources a workload really uses, based on code and access logs, with every change explained.
---

# AWS IAM least privilege

Reduce permissions to what is used, and prove it before removing anything.

## Steps

1. List the policies in scope: inline, managed and trust policies in IaC files (Terraform, CloudFormation, CDK) or exported JSON.
2. Establish usage from three sources: the AWS SDK calls in the code (`grep` for client and command names), CloudTrail or `aws iam generate-service-last-accessed-details`, and IAM Access Analyzer findings if present.
3. Rewrite each statement:
   - replace `Action: "*"` and `service:*` with the named actions in use
   - replace `Resource: "*"` with specific ARNs, using prefixes like `arn:aws:s3:::my-bucket/uploads/*` where names are dynamic
   - add `Condition` keys that pin region, `aws:PrincipalOrgID`, VPC endpoint, or tag where they fit
   - split read and write into separate statements
4. Check trust policies: a specific principal, an `ExternalId` for cross-account roles, no `Principal: "*"` without conditions.
5. Validate with `aws accessanalyzer validate-policy` and, where possible, `aws iam simulate-principal-policy` for the calls the code makes.

## Rules

- Never remove a permission you cannot show is unused. Put it under "unconfirmed".
- Never apply policy changes to a live account; edit the files and let the user deploy.
- Keep `iam:PassRole` and `sts:AssumeRole` scoped to exact role ARNs.

## Report

Per policy: before and after actions, resources narrowed, evidence used, and the unconfirmed list.

What it does

Policies start broad because that is the quickest way to get something working, and then they stay broad for years. This skill reduces them with evidence: what the code calls, what the logs show was used, and what the resource names really are.

Wildcards are replaced with named actions and ARNs, conditions are added where they help, and anything the agent cannot confirm is listed for you to decide instead of removed on a guess.

Example

you › Tighten the IAM role for our upload service

agent › Role upload-svc: replaced s3:* on * with s3:PutObject and s3:GetObject on arn:aws:s3:::acme-uploads/incoming/*. Removed dynamodb:* (no calls found in code or in 90 days of CloudTrail). Unconfirmed: sqs:SendMessage on one queue; kept it pending your answer. Access Analyzer validation: 0 errors.

Questions

Could it break my service?
It lowers that chance by checking code and logs, and by listing what it could not confirm instead of deleting it. Deploy to a test environment first.
Does it need AWS credentials?
Not for the code and IaC analysis. Log and Access Analyzer checks use the CLI profile you already have, read-only.
  • CI Pipeline Speedup

    SkillDevOps and cloud

    Free
  • Deployment Strategies

    SkillDevOps and cloud

    Free