[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7E67HYNFX1ZHBAT248SQ63F":3,"skill-same:01M7E67HYNFX1ZHBAT248SQ63F":57},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":35,"commitSha":36,"skillDirectory":37,"forksCount":14,"repositoryHtmlUrl":38,"repositoryHomepageUrl":6,"ownerHtmlUrl":39,"ownerBlogUrl":40,"ownerDescription":41,"updatedAt":42,"install":43,"resources":56},"01M7E67HYNFX1ZHBAT248SQ63F","aws-iam",null,"Write and audit AWS IAM - least-privilege policies, roles and trust policies, OIDC federation for CI, permission boundaries, cross-account access, MFA conditions and Access Analyzer. Use when creating or debugging IAM access; use deploying-on-aws for overall account architecture.","w0rxbend\u002Fdot-agents","w0rxbend","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F8176996?v=4","01M7E4XY3Y871Z2NFBXF3H3T8F","Oleksandr B.","01M7E4XY51E6NSG05FXR36H9RV",0,"MIT","https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents\u002Fblob\u002Fmain\u002Fskills\u002Fplatforms\u002Faws-iam\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: aws-iam\ndescription: \"Write and audit AWS IAM - least-privilege policies, roles and trust policies, OIDC federation for CI, permission boundaries, cross-account access, MFA conditions and Access Analyzer. Use when creating or debugging IAM access; use deploying-on-aws for overall account architecture.\"\ncategory: devops\nrisk: critical\nsource: https:\u002F\u002Fgithub.com\u002FBagelHole\u002FDevOps-Security-Agent-Skills\nsource_repo: BagelHole\u002FDevOps-Security-Agent-Skills\nsource_type: community\ndate_added: '2026-09-20'\nlicense: MIT\nlicense_source: https:\u002F\u002Fgithub.com\u002FBagelHole\u002FDevOps-Security-Agent-Skills\u002Fblob\u002Fmain\u002FLICENSE\ncompatibility: Requires AWS CLI v2 with credentials for the target account; mutating commands need the corresponding IAM permissions.\nmetadata:\n  author: devops-skills\n  version: '1.0'\n---\n\n# AWS IAM\n\n## When to Use This Skill\n\n- Roles for EC2 instances, Lambda functions or ECS tasks\n- Custom least-privilege IAM policies\n- OIDC federation for GitHub Actions or other CI\u002FCD systems\n- Permission boundaries for delegated administration\n- Access audits with IAM Access Analyzer and credential reports\n- Cross-account access with assume-role patterns\n- MFA and session policy enforcement\n\n## Prerequisites\n\n- AWS CLI v2 installed and configured\n- IAM permissions: `iam:*` (or scoped to specific actions for least privilege)\n- For OIDC: permission to create identity providers (`iam:CreateOpenIDConnectProvider`)\n- AWS Organizations access for Service Control Policies (SCPs)\n\n## IAM Policy Structure\n\nAlways specify minimum required actions and resources.\n\n```json\n{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Sid\": \"AllowS3List\",\n      \"Effect\": \"Allow\",\n      \"Action\": \"s3:ListBucket\",\n      \"Resource\": \"arn:aws:s3:::my-app-bucket\"\n    },\n    {\n      \"Sid\": \"AllowS3ReadWrite\",\n      \"Effect\": \"Allow\",\n      \"Action\": [\n        \"s3:GetObject\",\n        \"s3:PutObject\"\n      ],\n      \"Resource\": \"arn:aws:s3:::my-app-bucket\u002F*\"\n    },\n    {\n      \"Sid\": \"DenyUnencryptedUploads\",\n      \"Effect\": \"Deny\",\n      \"Action\": \"s3:PutObject\",\n      \"Resource\": \"arn:aws:s3:::my-app-bucket\u002F*\",\n      \"Condition\": {\n        \"StringNotEquals\": {\n          \"s3:x-amz-server-side-encryption\": \"aws:kms\"\n        }\n      }\n    }\n  ]\n}\n```\n\nEncryption conditions such as `s3:x-amz-server-side-encryption` only appear on write\nrequests (`PutObject`, `CopyObject`, multipart create). Never put them on an Allow for\n`GetObject` or `ListBucket`, or reads are silently never allowed. Enforce encryption with\nseparate Deny on `PutObject` as above, or with bucket default encryption.\n\n## Create and Manage Roles\n\n```bash\n# Create an EC2 instance role with trust policy\naws iam create-role \\\n  --role-name EC2AppRole \\\n  --assume-role-policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n      \"Effect\": \"Allow\",\n      \"Principal\": {\"Service\": \"ec2.amazonaws.com\"},\n      \"Action\": \"sts:AssumeRole\"\n    }]\n  }' \\\n  --tags '[{\"Key\":\"Team\",\"Value\":\"platform\"},{\"Key\":\"Environment\",\"Value\":\"production\"}]'\n\n# Create and attach an inline policy\naws iam put-role-policy \\\n  --role-name EC2AppRole \\\n  --policy-name s3-access \\\n  --policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n      \"Effect\": \"Allow\",\n      \"Action\": [\"s3:GetObject\", \"s3:PutObject\"],\n      \"Resource\": \"arn:aws:s3:::my-app-bucket\u002F*\"\n    }]\n  }'\n\n# Attach a managed policy\naws iam attach-role-policy \\\n  --role-name EC2AppRole \\\n  --policy-arn arn:aws:iam::aws:policy\u002FCloudWatchAgentServerPolicy\n\n# Create instance profile and associate the role\naws iam create-instance-profile --instance-profile-name EC2AppProfile\naws iam add-role-to-instance-profile \\\n  --instance-profile-name EC2AppProfile \\\n  --role-name EC2AppRole\n\n# Create a Lambda execution role\naws iam create-role \\\n  --role-name LambdaExecRole \\\n  --assume-role-policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n      \"Effect\": \"Allow\",\n      \"Principal\": {\"Service\": \"lambda.amazonaws.com\"},\n      \"Action\": \"sts:AssumeRole\"\n    }]\n  }'\n\naws iam attach-role-policy \\\n  --role-name LambdaExecRole \\\n  --policy-arn arn:aws:iam::aws:policy\u002Fservice-role\u002FAWSLambdaBasicExecutionRole\n```\n\n## Cross-Account Access\n\n```bash\n# In Account B: create role that Account A can assume\naws iam create-role \\\n  --role-name CrossAccountReadRole \\\n  --assume-role-policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n      \"Effect\": \"Allow\",\n      \"Principal\": {\"AWS\": \"arn:aws:iam::111111111111:root\"},\n      \"Action\": \"sts:AssumeRole\",\n      \"Condition\": {\n        \"StringEquals\": {\"sts:ExternalId\": \"unique-external-id-12345\"}\n      }\n    }]\n  }'\n\n# In Account A: assume via CLI profile (bare `aws sts assume-role` prints secret keys to the transcript)\naws configure set profile.cross-account.role_arn arn:aws:iam::222222222222:role\u002FCrossAccountReadRole\naws configure set profile.cross-account.source_profile default\naws configure set profile.cross-account.external_id unique-external-id-12345\naws sts get-caller-identity --profile cross-account\n```\n\n## OIDC Federation for GitHub Actions\n\n```bash\n# Create the GitHub OIDC identity provider.\n# AWS validates GitHub's token endpoint against its own trusted CA store, so the\n# thumbprint is not used for it; recent AWS CLI v2 versions accept the call without\n# --thumbprint-list. On older CLIs that still require the flag, pass any 40-hex value\n# (e.g. the historical GitHub thumbprint shown below).\naws iam create-open-id-connect-provider \\\n  --url https:\u002F\u002Ftoken.actions.githubusercontent.com \\\n  --client-id-list sts.amazonaws.com \\\n  --thumbprint-list \"6938fd4d98bab03faadb97b34396831e3780aea1\"\n\n# Create a role for GitHub Actions with repo-scoped trust\naws iam create-role \\\n  --role-name GitHubActionsDeployRole \\\n  --assume-role-policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n      \"Effect\": \"Allow\",\n      \"Principal\": {\n        \"Federated\": \"arn:aws:iam::123456789012:oidc-provider\u002Ftoken.actions.githubusercontent.com\"\n      },\n      \"Action\": \"sts:AssumeRoleWithWebIdentity\",\n      \"Condition\": {\n        \"StringEquals\": {\n          \"token.actions.githubusercontent.com:aud\": \"sts.amazonaws.com\"\n        },\n        \"StringLike\": {\n          \"token.actions.githubusercontent.com:sub\": \"repo:my-org\u002Fmy-repo:ref:refs\u002Fheads\u002Fmain\"\n        }\n      }\n    }]\n  }'\n\n# Attach deployment permissions to the role\naws iam attach-role-policy \\\n  --role-name GitHubActionsDeployRole \\\n  --policy-arn arn:aws:iam::123456789012:policy\u002FDeploymentPolicy\n```\n\nGitHub Actions workflow usage:\n\n```yaml\n# .github\u002Fworkflows\u002Fdeploy.yml\npermissions:\n  id-token: write\n  contents: read\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n      # Pin to a reviewed commit SHA in production (tags can move).\n      - uses: aws-actions\u002Fconfigure-aws-credentials@v4\n        with:\n          role-to-assume: arn:aws:iam::123456789012:role\u002FGitHubActionsDeployRole\n          aws-region: us-east-1\n      - run: aws sts get-caller-identity\n```\n\n## Permission Boundaries\n\n```bash\n# Create a permission boundary policy\naws iam create-policy \\\n  --policy-name DeveloperBoundary \\\n  --policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n      {\n        \"Sid\": \"AllowedServices\",\n        \"Effect\": \"Allow\",\n        \"Action\": [\n          \"s3:*\",\n          \"lambda:*\",\n          \"dynamodb:*\",\n          \"sqs:*\",\n          \"sns:*\",\n          \"logs:*\",\n          \"cloudwatch:*\",\n          \"ecr:*\",\n          \"ecs:*\"\n        ],\n        \"Resource\": \"*\"\n      },\n      {\n        \"Sid\": \"DenyIAMChanges\",\n        \"Effect\": \"Deny\",\n        \"Action\": [\n          \"iam:CreateUser\",\n          \"iam:DeleteUser\",\n          \"iam:CreateRole\",\n          \"iam:DeleteRole\",\n          \"iam:AttachRolePolicy\",\n          \"iam:PutRolePermissionsBoundary\",\n          \"iam:DeleteRolePermissionsBoundary\"\n        ],\n        \"Resource\": \"*\"\n      },\n      {\n        \"Sid\": \"DenyOutsideRegion\",\n        \"Effect\": \"Deny\",\n        \"Action\": \"*\",\n        \"Resource\": \"*\",\n        \"Condition\": {\n          \"StringNotEquals\": {\n            \"aws:RequestedRegion\": [\"us-east-1\", \"us-west-2\"]\n          },\n          \"ArnNotLike\": {\n            \"aws:PrincipalArn\": \"arn:aws:iam::*:role\u002Fadmin-*\"\n          }\n        }\n      }\n    ]\n  }'\n\n# Create a role with the permission boundary\naws iam create-role \\\n  --role-name DeveloperRole \\\n  --assume-role-policy-document file:\u002F\u002Ftrust-policy.json \\\n  --permissions-boundary \"arn:aws:iam::123456789012:policy\u002FDeveloperBoundary\"\n```\n\n## IAM Access Analyzer and Auditing\n\n```bash\n# Create an IAM Access Analyzer\naws accessanalyzer create-analyzer \\\n  --analyzer-name account-analyzer \\\n  --type ACCOUNT\n\n# List findings (externally accessible resources)\naws accessanalyzer list-findings \\\n  --analyzer-arn arn:aws:access-analyzer:us-east-1:123456789012:analyzer\u002Faccount-analyzer\n\n# Generate credential report\naws iam generate-credential-report\naws iam get-credential-report --output text --query Content | base64 -d > credential-report.csv\n\n# Find users with console access but no MFA\naws iam list-users --query \"Users[].UserName\" --output text | while read user; do\n  mfa=$(aws iam list-mfa-devices --user-name \"$user\" --query \"MFADevices\" --output text)\n  if [ -z \"$mfa\" ]; then\n    echo \"NO MFA: $user\"\n  fi\ndone\n\n# List all policies attached to a role\naws iam list-attached-role-policies --role-name EC2AppRole\naws iam list-role-policies --role-name EC2AppRole\n\n# Get the last-accessed services for a role\naws iam generate-service-last-accessed-details --arn arn:aws:iam::123456789012:role\u002FEC2AppRole\n# Then retrieve results with the returned JobId\naws iam get-service-last-accessed-details --job-id \"job-id-from-above\"\n\n# Simulate a policy to test access\naws iam simulate-principal-policy \\\n  --policy-source-arn arn:aws:iam::123456789012:role\u002FEC2AppRole \\\n  --action-names s3:GetObject s3:PutObject \\\n  --resource-arns arn:aws:s3:::my-app-bucket\u002Fdata.json\n```\n\n## Terraform IAM Role with OIDC\n\n```hcl\n# OIDC provider for GitHub Actions\nresource \"aws_iam_openid_connect_provider\" \"github\" {\n  url             = \"https:\u002F\u002Ftoken.actions.githubusercontent.com\"\n  client_id_list  = [\"sts.amazonaws.com\"]\n  # Not used by AWS for GitHub; optional in recent AWS provider versions.\n  thumbprint_list = [\"6938fd4d98bab03faadb97b34396831e3780aea1\"]\n}\n\n# Role for GitHub Actions\nresource \"aws_iam_role\" \"github_actions\" {\n  name = \"GitHubActionsDeployRole\"\n\n  assume_role_policy = jsonencode({\n    Version = \"2012-10-17\"\n    Statement = [{\n      Effect = \"Allow\"\n      Principal = {\n        Federated = aws_iam_openid_connect_provider.github.arn\n      }\n      Action = \"sts:AssumeRoleWithWebIdentity\"\n      Condition = {\n        # Pin sub to one branch or environment (repo:my-org\u002Fmy-repo:environment:production);\n        # repo:my-org\u002Fmy-repo:* lets any branch or PR workflow assume the deploy role.\n        StringEquals = {\n          \"token.actions.githubusercontent.com:aud\" = \"sts.amazonaws.com\"\n          \"token.actions.githubusercontent.com:sub\" = \"repo:my-org\u002Fmy-repo:ref:refs\u002Fheads\u002Fmain\"\n        }\n      }\n    }]\n  })\n\n  permissions_boundary = aws_iam_policy.boundary.arn\n}\n\nresource \"aws_iam_role_policy_attachment\" \"deploy\" {\n  role       = aws_iam_role.github_actions.name\n  policy_arn = aws_iam_policy.deployment.arn\n}\n\n# Permission boundary\nresource \"aws_iam_policy\" \"boundary\" {\n  name = \"DeveloperBoundary\"\n  policy = jsonencode({\n    Version = \"2012-10-17\"\n    Statement = [\n      {\n        Sid      = \"AllowedServices\"\n        Effect   = \"Allow\"\n        Action   = [\"s3:*\", \"lambda:*\", \"dynamodb:*\", \"ecs:*\", \"logs:*\"]\n        Resource = \"*\"\n      },\n      {\n        Sid      = \"DenyIAMEscalation\"\n        Effect   = \"Deny\"\n        Action   = [\"iam:CreateUser\", \"iam:CreateRole\", \"iam:AttachRolePolicy\"]\n        Resource = \"*\"\n      }\n    ]\n  })\n}\n```\n\n## Service Control Policies (Organizations)\n\n```json\n{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Sid\": \"DenyRootAccount\",\n      \"Effect\": \"Deny\",\n      \"Action\": \"*\",\n      \"Resource\": \"*\",\n      \"Condition\": {\n        \"StringLike\": {\n          \"aws:PrincipalArn\": \"arn:aws:iam::*:root\"\n        }\n      }\n    },\n    {\n      \"Sid\": \"RequireIMDSv2\",\n      \"Effect\": \"Deny\",\n      \"Action\": \"ec2:RunInstances\",\n      \"Resource\": \"arn:aws:ec2:*:*:instance\u002F*\",\n      \"Condition\": {\n        \"StringNotEquals\": {\n          \"ec2:MetadataHttpTokens\": \"required\"\n        }\n      }\n    },\n    {\n      \"Sid\": \"DenyRegionsOutsideUS\",\n      \"Effect\": \"Deny\",\n      \"Action\": \"*\",\n      \"Resource\": \"*\",\n      \"Condition\": {\n        \"StringNotEquals\": {\n          \"aws:RequestedRegion\": [\"us-east-1\", \"us-west-2\"]\n        },\n        \"ArnNotLike\": {\n          \"aws:PrincipalArn\": [\"arn:aws:iam::*:role\u002FOrganizationAdmin\"]\n        }\n      }\n    }\n  ]\n}\n```\n\n## Troubleshooting\n\n| Problem | Cause | Fix |\n|---|---|---|\n| Access Denied on API call | Missing or wrong policy | Test with `simulate-principal-policy`; check resource ARN format |\n| Role cannot be assumed | Trust policy does not include caller | Verify trust policy Principal matches caller ARN |\n| OIDC federation fails | Audience or subject mismatch | Verify OIDC provider URL, client ID list (`sts.amazonaws.com`) and `sub`\u002F`aud` condition keys |\n| Permission boundary blocks action | Boundary does not include action | Add action to boundary; effective = identity AND boundary |\n| Credential report shows stale keys | Keys not rotated in 90+ days | Rotate keys; disable unused access keys |\n| Service-linked role creation fails | Organization SCP blocks iam:CreateServiceLinkedRole | Add SCP exception for that specific service |\n| Cross-account assume role fails | Missing ExternalId or wrong account | Verify ExternalId matches; check account number in Principal |\n| MFA condition not enforced | Condition key not in policy | Add `aws:MultiFactorAuthPresent` condition |\n\n## Related Skills\n\n- `aws-ec2` - instance profiles and roles\n- `aws-s3` - bucket policies combined with IAM policies\n- `deploying-on-aws` - service selection, including Lambda and ECS execution roles\n- `github-actions-advanced` - OIDC federation from GitHub Actions\n- `pulumi-components` - IAM resources as code\n\n## Safety\n\n- Before any change, run `aws sts get-caller-identity` and confirm account, region and profile with the user. Get user approval before each mutating call (create, put, attach, add, update, delete); trust policies and attachments grant access.\n- Use `get`\u002F`list` calls first. Test policy changes with `aws iam simulate-principal-policy` (IAM has no `--dry-run`). Keep a working admin session open while editing trust policies, boundaries or deny statements, so a mistake cannot lock you out.\n\n","# AWS IAM\n\n## When to Use This Skill\n\n- Roles for EC2 instances, Lambda functions or ECS tasks\n- Custom least-privilege IAM policies\n- OIDC federation for GitHub Actions or other CI\u002FCD systems\n- Permission boundaries for delegated administration\n- Access audits with IAM Access Analyzer and credential reports\n- Cross-account access with assume-role patterns\n- MFA and session policy enforcement\n\n## Prerequisites\n\n- AWS CLI v2 installed and configured\n- IAM permissions: `iam:*` (or scoped to specific actions for least privilege)\n- For OIDC: permission to create identity providers (`iam:CreateOpenIDConnectProvider`)\n- AWS Organizations access for Service Control Policies (SCPs)\n\n## IAM Policy Structure\n\nAlways specify minimum required actions and resources.\n\n```json\n{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Sid\": \"AllowS3List\",\n      \"Effect\": \"Allow\",\n      \"Action\": \"s3:ListBucket\",\n      \"Resource\": \"arn:aws:s3:::my-app-bucket\"\n    },\n    {\n      \"Sid\": \"AllowS3ReadWrite\",\n      \"Effect\": \"Allow\",\n      \"Action\": [\n        \"s3:GetObject\",\n        \"s3:PutObject\"\n      ],\n      \"Resource\": \"arn:aws:s3:::my-app-bucket\u002F*\"\n    },\n    {\n      \"Sid\": \"DenyUnencryptedUploads\",\n      \"Effect\": \"Deny\",\n      \"Action\": \"s3:PutObject\",\n      \"Resource\": \"arn:aws:s3:::my-app-bucket\u002F*\",\n      \"Condition\": {\n        \"StringNotEquals\": {\n          \"s3:x-amz-server-side-encryption\": \"aws:kms\"\n        }\n      }\n    }\n  ]\n}\n```\n\nEncryption conditions such as `s3:x-amz-server-side-encryption` only appear on write\nrequests (`PutObject`, `CopyObject`, multipart create). Never put them on an Allow for\n`GetObject` or `ListBucket`, or reads are silently never allowed. Enforce encryption with\nseparate Deny on `PutObject` as above, or with bucket default encryption.\n\n## Create and Manage Roles\n\n```bash\n# Create an EC2 instance role with trust policy\naws iam create-role \\\n  --role-name EC2AppRole \\\n  --assume-role-policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n      \"Effect\": \"Allow\",\n      \"Principal\": {\"Service\": \"ec2.amazonaws.com\"},\n      \"Action\": \"sts:AssumeRole\"\n    }]\n  }' \\\n  --tags '[{\"Key\":\"Team\",\"Value\":\"platform\"},{\"Key\":\"Environment\",\"Value\":\"production\"}]'\n\n# Create and attach an inline policy\naws iam put-role-policy \\\n  --role-name EC2AppRole \\\n  --policy-name s3-access \\\n  --policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n      \"Effect\": \"Allow\",\n      \"Action\": [\"s3:GetObject\", \"s3:PutObject\"],\n      \"Resource\": \"arn:aws:s3:::my-app-bucket\u002F*\"\n    }]\n  }'\n\n# Attach a managed policy\naws iam attach-role-policy \\\n  --role-name EC2AppRole \\\n  --policy-arn arn:aws:iam::aws:policy\u002FCloudWatchAgentServerPolicy\n\n# Create instance profile and associate the role\naws iam create-instance-profile --instance-profile-name EC2AppProfile\naws iam add-role-to-instance-profile \\\n  --instance-profile-name EC2AppProfile \\\n  --role-name EC2AppRole\n\n# Create a Lambda execution role\naws iam create-role \\\n  --role-name LambdaExecRole \\\n  --assume-role-policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n      \"Effect\": \"Allow\",\n      \"Principal\": {\"Service\": \"lambda.amazonaws.com\"},\n      \"Action\": \"sts:AssumeRole\"\n    }]\n  }'\n\naws iam attach-role-policy \\\n  --role-name LambdaExecRole \\\n  --policy-arn arn:aws:iam::aws:policy\u002Fservice-role\u002FAWSLambdaBasicExecutionRole\n```\n\n## Cross-Account Access\n\n```bash\n# In Account B: create role that Account A can assume\naws iam create-role \\\n  --role-name CrossAccountReadRole \\\n  --assume-role-policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n      \"Effect\": \"Allow\",\n      \"Principal\": {\"AWS\": \"arn:aws:iam::111111111111:root\"},\n      \"Action\": \"sts:AssumeRole\",\n      \"Condition\": {\n        \"StringEquals\": {\"sts:ExternalId\": \"unique-external-id-12345\"}\n      }\n    }]\n  }'\n\n# In Account A: assume via CLI profile (bare `aws sts assume-role` prints secret keys to the transcript)\naws configure set profile.cross-account.role_arn arn:aws:iam::222222222222:role\u002FCrossAccountReadRole\naws configure set profile.cross-account.source_profile default\naws configure set profile.cross-account.external_id unique-external-id-12345\naws sts get-caller-identity --profile cross-account\n```\n\n## OIDC Federation for GitHub Actions\n\n```bash\n# Create the GitHub OIDC identity provider.\n# AWS validates GitHub's token endpoint against its own trusted CA store, so the\n# thumbprint is not used for it; recent AWS CLI v2 versions accept the call without\n# --thumbprint-list. On older CLIs that still require the flag, pass any 40-hex value\n# (e.g. the historical GitHub thumbprint shown below).\naws iam create-open-id-connect-provider \\\n  --url https:\u002F\u002Ftoken.actions.githubusercontent.com \\\n  --client-id-list sts.amazonaws.com \\\n  --thumbprint-list \"6938fd4d98bab03faadb97b34396831e3780aea1\"\n\n# Create a role for GitHub Actions with repo-scoped trust\naws iam create-role \\\n  --role-name GitHubActionsDeployRole \\\n  --assume-role-policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [{\n      \"Effect\": \"Allow\",\n      \"Principal\": {\n        \"Federated\": \"arn:aws:iam::123456789012:oidc-provider\u002Ftoken.actions.githubusercontent.com\"\n      },\n      \"Action\": \"sts:AssumeRoleWithWebIdentity\",\n      \"Condition\": {\n        \"StringEquals\": {\n          \"token.actions.githubusercontent.com:aud\": \"sts.amazonaws.com\"\n        },\n        \"StringLike\": {\n          \"token.actions.githubusercontent.com:sub\": \"repo:my-org\u002Fmy-repo:ref:refs\u002Fheads\u002Fmain\"\n        }\n      }\n    }]\n  }'\n\n# Attach deployment permissions to the role\naws iam attach-role-policy \\\n  --role-name GitHubActionsDeployRole \\\n  --policy-arn arn:aws:iam::123456789012:policy\u002FDeploymentPolicy\n```\n\nGitHub Actions workflow usage:\n\n```yaml\n# .github\u002Fworkflows\u002Fdeploy.yml\npermissions:\n  id-token: write\n  contents: read\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n      # Pin to a reviewed commit SHA in production (tags can move).\n      - uses: aws-actions\u002Fconfigure-aws-credentials@v4\n        with:\n          role-to-assume: arn:aws:iam::123456789012:role\u002FGitHubActionsDeployRole\n          aws-region: us-east-1\n      - run: aws sts get-caller-identity\n```\n\n## Permission Boundaries\n\n```bash\n# Create a permission boundary policy\naws iam create-policy \\\n  --policy-name DeveloperBoundary \\\n  --policy-document '{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n      {\n        \"Sid\": \"AllowedServices\",\n        \"Effect\": \"Allow\",\n        \"Action\": [\n          \"s3:*\",\n          \"lambda:*\",\n          \"dynamodb:*\",\n          \"sqs:*\",\n          \"sns:*\",\n          \"logs:*\",\n          \"cloudwatch:*\",\n          \"ecr:*\",\n          \"ecs:*\"\n        ],\n        \"Resource\": \"*\"\n      },\n      {\n        \"Sid\": \"DenyIAMChanges\",\n        \"Effect\": \"Deny\",\n        \"Action\": [\n          \"iam:CreateUser\",\n          \"iam:DeleteUser\",\n          \"iam:CreateRole\",\n          \"iam:DeleteRole\",\n          \"iam:AttachRolePolicy\",\n          \"iam:PutRolePermissionsBoundary\",\n          \"iam:DeleteRolePermissionsBoundary\"\n        ],\n        \"Resource\": \"*\"\n      },\n      {\n        \"Sid\": \"DenyOutsideRegion\",\n        \"Effect\": \"Deny\",\n        \"Action\": \"*\",\n        \"Resource\": \"*\",\n        \"Condition\": {\n          \"StringNotEquals\": {\n            \"aws:RequestedRegion\": [\"us-east-1\", \"us-west-2\"]\n          },\n          \"ArnNotLike\": {\n            \"aws:PrincipalArn\": \"arn:aws:iam::*:role\u002Fadmin-*\"\n          }\n        }\n      }\n    ]\n  }'\n\n# Create a role with the permission boundary\naws iam create-role \\\n  --role-name DeveloperRole \\\n  --assume-role-policy-document file:\u002F\u002Ftrust-policy.json \\\n  --permissions-boundary \"arn:aws:iam::123456789012:policy\u002FDeveloperBoundary\"\n```\n\n## IAM Access Analyzer and Auditing\n\n```bash\n# Create an IAM Access Analyzer\naws accessanalyzer create-analyzer \\\n  --analyzer-name account-analyzer \\\n  --type ACCOUNT\n\n# List findings (externally accessible resources)\naws accessanalyzer list-findings \\\n  --analyzer-arn arn:aws:access-analyzer:us-east-1:123456789012:analyzer\u002Faccount-analyzer\n\n# Generate credential report\naws iam generate-credential-report\naws iam get-credential-report --output text --query Content | base64 -d > credential-report.csv\n\n# Find users with console access but no MFA\naws iam list-users --query \"Users[].UserName\" --output text | while read user; do\n  mfa=$(aws iam list-mfa-devices --user-name \"$user\" --query \"MFADevices\" --output text)\n  if [ -z \"$mfa\" ]; then\n    echo \"NO MFA: $user\"\n  fi\ndone\n\n# List all policies attached to a role\naws iam list-attached-role-policies --role-name EC2AppRole\naws iam list-role-policies --role-name EC2AppRole\n\n# Get the last-accessed services for a role\naws iam generate-service-last-accessed-details --arn arn:aws:iam::123456789012:role\u002FEC2AppRole\n# Then retrieve results with the returned JobId\naws iam get-service-last-accessed-details --job-id \"job-id-from-above\"\n\n# Simulate a policy to test access\naws iam simulate-principal-policy \\\n  --policy-source-arn arn:aws:iam::123456789012:role\u002FEC2AppRole \\\n  --action-names s3:GetObject s3:PutObject \\\n  --resource-arns arn:aws:s3:::my-app-bucket\u002Fdata.json\n```\n\n## Terraform IAM Role with OIDC\n\n```hcl\n# OIDC provider for GitHub Actions\nresource \"aws_iam_openid_connect_provider\" \"github\" {\n  url             = \"https:\u002F\u002Ftoken.actions.githubusercontent.com\"\n  client_id_list  = [\"sts.amazonaws.com\"]\n  # Not used by AWS for GitHub; optional in recent AWS provider versions.\n  thumbprint_list = [\"6938fd4d98bab03faadb97b34396831e3780aea1\"]\n}\n\n# Role for GitHub Actions\nresource \"aws_iam_role\" \"github_actions\" {\n  name = \"GitHubActionsDeployRole\"\n\n  assume_role_policy = jsonencode({\n    Version = \"2012-10-17\"\n    Statement = [{\n      Effect = \"Allow\"\n      Principal = {\n        Federated = aws_iam_openid_connect_provider.github.arn\n      }\n      Action = \"sts:AssumeRoleWithWebIdentity\"\n      Condition = {\n        # Pin sub to one branch or environment (repo:my-org\u002Fmy-repo:environment:production);\n        # repo:my-org\u002Fmy-repo:* lets any branch or PR workflow assume the deploy role.\n        StringEquals = {\n          \"token.actions.githubusercontent.com:aud\" = \"sts.amazonaws.com\"\n          \"token.actions.githubusercontent.com:sub\" = \"repo:my-org\u002Fmy-repo:ref:refs\u002Fheads\u002Fmain\"\n        }\n      }\n    }]\n  })\n\n  permissions_boundary = aws_iam_policy.boundary.arn\n}\n\nresource \"aws_iam_role_policy_attachment\" \"deploy\" {\n  role       = aws_iam_role.github_actions.name\n  policy_arn = aws_iam_policy.deployment.arn\n}\n\n# Permission boundary\nresource \"aws_iam_policy\" \"boundary\" {\n  name = \"DeveloperBoundary\"\n  policy = jsonencode({\n    Version = \"2012-10-17\"\n    Statement = [\n      {\n        Sid      = \"AllowedServices\"\n        Effect   = \"Allow\"\n        Action   = [\"s3:*\", \"lambda:*\", \"dynamodb:*\", \"ecs:*\", \"logs:*\"]\n        Resource = \"*\"\n      },\n      {\n        Sid      = \"DenyIAMEscalation\"\n        Effect   = \"Deny\"\n        Action   = [\"iam:CreateUser\", \"iam:CreateRole\", \"iam:AttachRolePolicy\"]\n        Resource = \"*\"\n      }\n    ]\n  })\n}\n```\n\n## Service Control Policies (Organizations)\n\n```json\n{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Sid\": \"DenyRootAccount\",\n      \"Effect\": \"Deny\",\n      \"Action\": \"*\",\n      \"Resource\": \"*\",\n      \"Condition\": {\n        \"StringLike\": {\n          \"aws:PrincipalArn\": \"arn:aws:iam::*:root\"\n        }\n      }\n    },\n    {\n      \"Sid\": \"RequireIMDSv2\",\n      \"Effect\": \"Deny\",\n      \"Action\": \"ec2:RunInstances\",\n      \"Resource\": \"arn:aws:ec2:*:*:instance\u002F*\",\n      \"Condition\": {\n        \"StringNotEquals\": {\n          \"ec2:MetadataHttpTokens\": \"required\"\n        }\n      }\n    },\n    {\n      \"Sid\": \"DenyRegionsOutsideUS\",\n      \"Effect\": \"Deny\",\n      \"Action\": \"*\",\n      \"Resource\": \"*\",\n      \"Condition\": {\n        \"StringNotEquals\": {\n          \"aws:RequestedRegion\": [\"us-east-1\", \"us-west-2\"]\n        },\n        \"ArnNotLike\": {\n          \"aws:PrincipalArn\": [\"arn:aws:iam::*:role\u002FOrganizationAdmin\"]\n        }\n      }\n    }\n  ]\n}\n```\n\n## Troubleshooting\n\n| Problem | Cause | Fix |\n|---|---|---|\n| Access Denied on API call | Missing or wrong policy | Test with `simulate-principal-policy`; check resource ARN format |\n| Role cannot be assumed | Trust policy does not include caller | Verify trust policy Principal matches caller ARN |\n| OIDC federation fails | Audience or subject mismatch | Verify OIDC provider URL, client ID list (`sts.amazonaws.com`) and `sub`\u002F`aud` condition keys |\n| Permission boundary blocks action | Boundary does not include action | Add action to boundary; effective = identity AND boundary |\n| Credential report shows stale keys | Keys not rotated in 90+ days | Rotate keys; disable unused access keys |\n| Service-linked role creation fails | Organization SCP blocks iam:CreateServiceLinkedRole | Add SCP exception for that specific service |\n| Cross-account assume role fails | Missing ExternalId or wrong account | Verify ExternalId matches; check account number in Principal |\n| MFA condition not enforced | Condition key not in policy | Add `aws:MultiFactorAuthPresent` condition |\n\n## Related Skills\n\n- `aws-ec2` - instance profiles and roles\n- `aws-s3` - bucket policies combined with IAM policies\n- `deploying-on-aws` - service selection, including Lambda and ECS execution roles\n- `github-actions-advanced` - OIDC federation from GitHub Actions\n- `pulumi-components` - IAM resources as code\n\n## Safety\n\n- Before any change, run `aws sts get-caller-identity` and confirm account, region and profile with the user. Get user approval before each mutating call (create, put, attach, add, update, delete); trust policies and attachments grant access.\n- Use `get`\u002F`list` calls first. Test policy changes with `aws iam simulate-principal-policy` (IAM has no `--dry-run`). Keep a working admin session open while editing trust policies, boundaries or deny statements, so a mistake cannot lock you out.\n\n",{"name":5,"risk":24,"source":25,"license":15,"category":26,"metadata":27,"date_added":30,"description":7,"source_repo":31,"source_type":32,"compatibility":33,"license_source":34},"critical","https:\u002F\u002Fgithub.com\u002FBagelHole\u002FDevOps-Security-Agent-Skills","devops",{"author":28,"version":29},"devops-skills","1.0","2026-09-20","BagelHole\u002FDevOps-Security-Agent-Skills","community","Requires AWS CLI v2 with credentials for the target account; mutating commands need the corresponding IAM permissions.","https:\u002F\u002Fgithub.com\u002FBagelHole\u002FDevOps-Security-Agent-Skills\u002Fblob\u002Fmain\u002FLICENSE","main","101d0f67250256ca5d80dc3f95767cad7b541457","skills\u002Fplatforms\u002Faws-iam","https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents","https:\u002F\u002Fgithub.com\u002Fw0rxbend","https:\u002F\u002Freadme.worxbend.com\u002F","Fluent in Backend-ese (microservices, distributed systems, you know the drill)\r\nFunctional Programming Fanatic...","2026-11-14 14:44:12",{"source":8,"skillName":5,"commands":44,"prompt":54,"zipAvailable":55},[45,48,51],{"tool":46,"command":47},"npx","npx skills add w0rxbend\u002Fdot-agents --skill aws-iam",{"tool":49,"command":50},"bunx","bunx skills add w0rxbend\u002Fdot-agents --skill aws-iam",{"tool":52,"command":53},"pnpm","pnpm dlx skills add w0rxbend\u002Fdot-agents --skill aws-iam","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents\u002Fblob\u002Fmain\u002Fskills\u002Fplatforms\u002Faws-iam\u002FSKILL.md",true,[],[58,65,72,80,87,94],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":19},"01M7E6TS1SW1ZSXN748N0RBGHT","wiki-builder","Create and maintain a local Markdown research wiki (sources with provenance, compiled concept\u002Fsource pages, index, maintenance log) driven by a per-wiki config. Use when the user wants to start a wiki or knowledge base, ingest sources into one, or query and update it; use wiki-page-writer for a single code deep-dive page.","https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents\u002Fblob\u002Fmain\u002Fskills\u002Fworkflow\u002Fwiki-builder\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M7E6S8ARS0VQR85H4FEC390B","refactoring-guru","Diagnose a named code smell and apply the smallest behavior-preserving refactoring, with verification before and after and an explicit stop condition. Use for structural refactors (extract, move, consolidate, change ownership), not for feature or bug work; for readability cleanup of recent changes use code-simplification.","https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents\u002Fblob\u002Fmain\u002Fskills\u002Fworkflow\u002Frefactoring-guru\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":76,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M7E6RRXCYGSHA0ZBFX3YZP7Y","legacy-seams","When changing untested legacy code, pin the observed results with characterization tests and open the smallest seam that substitutes only the blocking dependency, separate from any later logic change. Use when a clock, random source, I\u002FO, global, or hidden constructor blocks a test or a safe edit. Use test-driven-development for a new behavior or a bug, refactoring-guru for one named structural refactor after the seam exists, and code-refactoring-tech-debt to choose which legacy to replace.","https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents\u002Fblob\u002Fmain\u002Fskills\u002Fworkflow\u002Flegacy-seams\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents\u002Fblob\u002Fmain\u002Fskills\u002Fworkflow\u002Flegacy-seams\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M7E6QZ11XWSNHCBGYK8HH97C","idea-refine","Refine a raw idea into a one-page brief (problem statement, recommended direction, assumptions to validate, MVP scope, not-doing list) through divergent then convergent thinking. Use when an idea is still vague or you want options and a stress test before committing; use interview-me when the goal itself is unclear and spec-driven-development once the direction is chosen.","https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents\u002Fblob\u002Fmain\u002Fskills\u002Fworkflow\u002Fidea-refine\u002FSKILL.md",[],[],{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":19},"01M7E6N2N7BYW7BA5XGM0QD3B4","code-review-and-quality","Review rubric and approval standard for any change before merge, including code written by you, another agent, or a human: five axes (correctness, readability, architecture, security, performance), change sizing, structural remedies, severity labels, and feedback technique. Use to judge whether a change is fit to merge; use code-review to run a PR or diff review end to end.","https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents\u002Fblob\u002Fmain\u002Fskills\u002Fworkflow\u002Fcode-review-and-quality\u002FSKILL.md",[],[],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":98,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":19},"01M7E6MNCZPTRD77Z419X755HQ","code-perfection","Smell and style gate for code you write or change. Bans known code smells (long method, large class, primitive obsession, long parameter list, data clumps, duplicate code, dead code, feature envy, shotgun surgery, flag arguments, message chains) and enforces behavior-preserving structure. On Scala files, enforces worxbend style. Use while implementing, reviewing a diff for smells, or when a smell or style violation is suspected. Routine construction stays with code-complete. SOLID and DRY stay with clean-code-guard. One named structural refactor stays with refactoring-guru.","https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents\u002Fblob\u002Fmain\u002Fskills\u002Fworkflow\u002Fcode-perfection\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fw0rxbend\u002Fdot-agents\u002Fblob\u002Fmain\u002Fskills\u002Fworkflow\u002Fcode-perfection\u002FSKILL.md",[],[]]