AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured approach to AWS IAM management, focusing on correcting common AI pitfalls regarding policy evaluation, trust policies, and service-specific role configurations. It mandates the use of automated tools for policy generation when source code or Terraform plans are available, ensuring deterministic and secure outcomes. It covers critical edge cases including STS session limits, Organizations quirks, and condition operator safety, while providing clear guidelines for creating scoped service and execution roles with proper confused deputy protections.
What it does
- Provides verified corrections for common AI-generated IAM policy errors.
- Mandates automated policy generation for application source code and Terraform plan JSON files.
- Defines structured workflows for creating service and execution roles with confused deputy protection.
- Offers guidance on complex IAM topics like condition operators, trust policies, and Organizations.
- Supplies specific patterns for handling STS, SAML, MFA, and service-specific role requirements.
- Ensures adherence to security best practices by prioritizing official documentation over pre-training.
When to use it
- When creating or updating IAM roles for AWS services.
- When generating IAM policies from application source code or Terraform plan JSON files.
- When troubleshooting IAM policy evaluation, trust policy issues, or condition operator logic.
- When configuring cross-account access, STS sessions, or AWS Organizations policies.
- When implementing security-hardened service roles with source account and ARN restrictions.
Advantages
- Reduces security risks by enforcing confused deputy protection and scoped permissions.
- Eliminates manual policy construction errors through automated tool integration.
- Provides reliable, verified solutions for known IAM edge cases and pitfalls.
- Standardizes role management workflows across different AWS services.
- Ensures policy generation is reproducible and based on deterministic analysis.
Usage examples
- “Create an IAM execution role for a Lambda function that needs to read from a specific S3 bucket.”
- The agent will identify the Lambda service principal, construct a trust policy with appropriate source account conditions, and generate a scoped permissions policy for the S3 bucket.
- “Generate an IAM policy based on this Terraform plan JSON.”
- The agent will provide the exact uvx iam-policy-autopilot command to generate the policy, ensuring the output is derived from deterministic analysis of the plan.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/aws/aws-iam/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip aws-iam.zip -d .agents/skills
Documentation by AWS
AWS IAM — Common Pitfalls
About This Skill
This skill contains verified corrections for things that AI agents frequently get wrong about IAM. It is not a comprehensive IAM guide — for full IAM guidance, search AWS documentation. When answering IAM questions, verify specific claims (limits, quotas, exact API names, edge-case behaviors) against official AWS documentation rather than relying on pre-training. Prefer fetching known documentation URLs over broad searches. Trust official documentation over memory when they conflict.
Common Workflows
Use the best available tool for AWS operations — the AWS MCP server is recommended but not required; AWS CLI or SDK may be used as alternatives. Read reference files only when the conversation requires deeper detail.
Read references/aws-iam-role-management.md if the user needs to create, scope, or maintain IAM roles when provisioning or updating AWS resources. Covers service roles, execution roles, trust policies, confused deputy protection, and permission hygiene.
Read references/aws-iam-policy-generation.md if the user needs to generate IAM policies, determine required IAM actions for API calls, or understand action-to-operation mappings. CRITICAL: If the user provides application source code (in any language) or a Terraform plan JSON file (
terraform show -jsonoutput), you MUST read this reference — it mandates using iam-policy-autopilot instead of manual policy construction. Uses the programmatic service authorization reference for accurate mappings.
Verified Edge Cases
CloudTrail:
AcceptHandshake/DeclineHandshake logged in ACTING account ONLY, not management account. Organization trail required for centralization.
ConsoleLogin region varies by endpoint/cookies, NOT always us-east-1.
?region=forces specific region.
STS:
GetSessionToken restrictions: (1) No IAM APIs unless MFA included (2) No STS except AssumeRole and GetCallerIdentity.
Cross-account AssumeRole to opt-in region: TARGET account must enable region, not calling account.
Role chaining: max 1-hour session.
Organizations:
Suspended/closed accounts CANNOT be removed until permanently closed (~90 days). Remove FIRST, then close.
Policy management delegation: use PutResourcePolicy, NOT register-delegated-administrator.
AI opt-out policies: management account required by default.
Organizations policy types for ListPolicies filter: fetch the current list via
aws organizations list-available-policy-typesor the Organizations API reference.
SDK Specifics:
Organizations:
DuplicatePolicyAttachmentException(not PolicyAlreadyAttachedException).Boto3 IAM AccessKey: methods are
activate(),deactivate(),delete()— NOupdate().Instance profiles: waiter +
time.sleep(10)pattern.Managed policy max versions: 5.
SAML:
Encrypted assertions URL:
https://region-code.signin.aws.amazon.com/saml/acs/IdP-ID.Private key from IdP uploaded to IAM in .pem format.
Policy Evaluation:
ForAllValues with empty/missing key: evaluates to true (vacuous truth). To avoid that, use a
Nullcondition in addition to theForAllValueson the same context key to require that key to be present and non-null. For example, when evaluating theaws:TagKeyscontext key:{ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Action": "ec2:RunInstances", "Resource": "*", "Condition": { "ForAllValues:StringEquals": { "aws:TagKeys": ["Alpha", "Beta"] }, "Null": { "aws:TagKeys": "false" } } } }aws:TagKeysvalues are case-sensitive, but the tag key inaws:PrincipalTag/<key>,aws:ResourceTag/<key>, andaws:RequestTag/<key>is not. The Allow allowlist above is unaffected (a re-cased key is simply not in the list), but a Deny that protects a tag key withForAnyValue:StringEqualsonaws:TagKeysis bypassed by a re-cased key (PROTECTED-TAG) — useForAnyValue:StringEqualsIgnoreCase. See references/common-pitfalls.md.Resource-based policies granting to IAM user ARN bypass permissions boundaries in same account.
8 privilege escalation actions via direct IAM policy manipulation: PutGroupPolicy, PutRolePolicy, PutUserPolicy, CreatePolicy, CreatePolicyVersion, AttachGroupPolicy, AttachRolePolicy, AttachUserPolicy.
iam:PassRolewithResource: "*"+ create/update on a compute service (EC2RunInstances, LambdaCreateFunction/UpdateFunctionConfiguration, ECSRegisterTaskDefinition, Glue, SageMaker, CloudFormation, etc.) = privilege escalation to any passable role in the account, including Administrator. ScopeResourceto specific role ARNs or an IAM path; optionally constrain withiam:PassedToService/iam:AssociatedResourceArn. See IAM User Guide — Grant a user permissions to pass a role.
MFA:
Unassigned virtual MFA devices auto-deleted when adding new ones.
MFA resync-only policy NotAction needs exactly: iam:ListMFADevices, iam:ListVirtualMFADevices, iam:ResyncMFADevice.
SigV4:
IncompleteSignatureException includes SHA-256 hash of Authorization header for transit modification diagnosis.
Service-Specific Roles:
Redshift Serverless trust policy: include BOTH
redshift-serverless.amazonaws.comANDredshift.amazonaws.comas service principals (per AWS docs; omitting serverless causesNot authorized to get credentials of roleon COPY).IAM OIDC providers: thumbprints are not required for most providers (AWS verifies via trusted CAs).
Policy Summary Display:
Single statement with multi-service wildcard actions (e.g.
codebuild:*,codecommit:*) + service-specific resource ARNs: each resource appears ONLY under its matching service's summary (CodeBuild ARN under CodeBuild, etc.). A resource whose service prefix matches NO action in the statement is the only case where it appears in all action summaries ("mismatched resource").
Files
- ATTRIBUTION.mdAdded by AutoGineer879 B
- LICENSELicence file added by AutoGineer9.9 KiB
- NOTICELicence file added by AutoGineer67 B
- SKILL.md7.2 KiB
- references/aws-iam-policy-generation.md39.0 KiB
- references/aws-iam-role-management.md6.6 KiB
- references/common-pitfalls.md5.8 KiB
- references/service-authorization.md2.7 KiB
references/aws-iam-role-management.md
IAM Role Management
Overview
This skill provides a structured workflow for identifying, creating, and maintaining IAM roles as part of any resource provisioning or update task. Without explicit guidance, agents tend to skip role creation, produce malformed trust policies, use overly broad permissions, or miss implicit role dependencies.
When the prompt provides sufficient context (resource names, service types), proceed directly with role creation. Do not ask for confirmation or additional parameters — use the account ID and region from your AWS session context.
Role identification
Before creating any AWS resource, determine all IAM roles the task requires:
Service roles — assumed by an AWS service to act on your behalf (e.g., Glue crawler reading S3, Firehose delivering to S3). The service itself is the principal.
Execution roles — assumed by an AWS service to run customer code (e.g., Lambda execution role, ECS task role).
For each resource:
Identify whether the service requires a role to operate
Check whether the service uses a service-linked role (no custom role needed — e.g., GuardDuty, Auto Scaling)
Identify dependent resources that also need roles (e.g., CodePipeline + CodeBuild)
Do not skip role creation by referencing "pre-existing roles" unless the user explicitly provides a role ARN.
Create service role
Identify the correct service principal for the service that will assume the role at runtime
Construct the trust policy with confused deputy protections
Identify all resources the role needs to access from the current task context
Build a scoped permissions policy using those resource ARNs
Attach relevant managed policies where they exist
Trust policy
Use the correct service principal: always
[service].amazonaws.com(e.g.,glue.amazonaws.com,states.amazonaws.com). The trust principal must be the service that actually callssts:AssumeRoleat runtime, which may differ from the service being configured (e.g., CloudWatch Synthetics canaries uselambda.amazonaws.com).Include confused deputy protections — add both
aws:SourceArnandaws:SourceAccountconditions:When the resource name is provided, use it in
aws:SourceArn— construct the full ARN including account ID, region, and resource type. Do not use wildcards when the name is known.When the resource name is genuinely unknown, use a wildcard ARN with as much specificity as possible.
Include
aws:SourceAccountwith the full account ID.Include
aws:SourceArnandaws:SourceAccountconditions when the assuming service supports them — most major services do, including Glue, CloudTrail, Firehose, Lambda, S3 replication, DataSync, and VPC Flow Logs. Check service documentation if unsure which condition keys a specific service populates.Example:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "glue.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "aws:SourceAccount": "123456789012" }, "ArnLike": { "aws:SourceArn": "arn:aws:glue:us-east-1:123456789012:crawler/my-crawler" } } } ] }
The trust policy goes in
AssumeRolePolicyDocument, not in the permissions policy.
Permissions policy
Identify all resources from the current task that this role will access — buckets, tables, streams, log groups, etc. Construct the most specific resource ARN possible. Use
*only for components you genuinely don't know.Scope CloudWatch Logs actions (
logs:CreateLogStream,logs:PutLogEvents,logs:DescribeLogStreams) to the specific log group ARN, notResource: *. Use the patternarn:aws:logs:REGION:ACCOUNT:log-group:LOG_GROUP_NAME:*.Separate permissions by purpose into distinct policy statements (e.g., source-read vs. target-write).
Attach AWS managed policies when they closely match the work (e.g.,
AWSGlueServiceRole). Supplement with scoped inline policies for resource-specific access.Do not use
"Action": "*"or"Resource": "*"as a pair. If broad access is genuinely needed, explain why.
Naming
Use a descriptive role name identifying the service and purpose (e.g., GlueETL-my-job, FirehoseDelivery-my-stream).
Maintain service role
When updating a resource that has an associated service role:
Read the existing role's trust policy, permissions policy, and tags
If tags indicate the role is managed by an external tool (e.g.,
aws:cloudformation:stack-name,managed-by: terraform), flag this to the user before proceedingIf the trust policy lacks
aws:SourceArnandaws:SourceAccountconditions, add them — this is required, not optional. Follow the confused deputy guidance from the Create section. Use the specific resource ARN from the task context.Update the permissions policy to cover the new activity — prefer extending the existing role over creating a new one when the trust principal is unchanged
If existing permissions are broader than needed after the update, offer to scope them down
Create execution role
When creating an execution role (Lambda, ECS task, EC2 instance profile, EKS pod):
Include baseline permissions the execution environment needs (e.g.,
AWSLambdaBasicExecutionRolefor Lambda)If the user's prompt specifies what the code will do, create a scoped role matching those responsibilities. If the prompt signals exploratory/PoC intent, use broader permissions
Briefly explain the scoping choice and offer to adjust
Maintain execution role
When altering code that runs in an AWS execution environment:
Examine the associated execution role and its tags
If code changes introduce new AWS API calls, verify the role permits them and update if not
Do not silently remove permissions — confirm with the user before narrowing
Gotchas
Trust policy and permissions policy are separate documents. Never put resource-scoped permissions inside the trust policy.
Some services use service-linked roles that AWS manages automatically. Do not create custom roles for these — verify first.
When a task involves multiple services in a chain (e.g., SES → Firehose → S3), each link may need its own role. Create separate, purpose-specific roles.
Additional Resources
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs an MCP server
Security
What our scanner noticed· Low risk
- Phrasing that asks for actions without confirmation
- Instructions that use the network
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- AWS
- Publisher
- AWS (Official)
- Source
- aws/agent-toolkit-for-aws · skills/core-skills/aws-iam · commit 0a218f8
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- NOTICE (added by AutoGineer from NOTICE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
- Also distributed in
- aws/agent-toolkit-for-aws
AutoGineer is not affiliated with or endorsed by AWS.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download aws-iam.zip