SecurityZines.com Join

AWS IAM, the zine class

Learn AWS IAM step by step: who can do what, how AWS decides, how attackers abuse it, and how to protect it. Ada asks interview questions as you read.

IAM controls every request in an AWS account. Many cloud breaches start with a stolen key or a weak IAM setting. Cloud security, AppSec and DevOps interviews ask about IAM a lot. This class teaches IAM from the basics to senior-level detail.

Each drawing plays when you scroll to it. Tap a drawing to go one step at a time. Your answers stay in this browser only.

1Meet the cast

These six characters are in all Zine Classes. In this class, some of them have cloud jobs.

ZeeYou, the learner.
MalloryThe attacker. She wants AWS keys.
AliceA developer. She owns the AWS account.
BrowsyThe app or job that calls AWS. It signs each request.
ServoAWS. It checks each request against the policies.
AdaThe interviewer. She asks the questions.

2What is AWS IAM?

In plain wordsAn office building gives each person a key card. The card opens some doors and not others. The door reader checks the card, not the face. If you drop your card, a stranger can open the same doors.

AWS Identity and Access Management (IAM) decides who can do which action on which resource. The caller signs almost every AWS API call with its credentials. AWS finds the identity from the credentials. Then AWS checks the policies and allows or denies the call.

aws s3 sync
A quick test. I will remove the key later.
github.com/alice/app · config.pyAWS_ACCESS_KEY_ID=AKIA…AWS_SECRET_ACCESS_KEY=…
My bot scans public code for AKIA keys.
The signature is valid. The policy allows s3:*. OK.
Data copied!
AWS checks the key. AWS cannot see who holds the key.
  1. Alice puts an access key in her code to test fast.
  2. She pushes the code to a public repository. The key is now public.
  3. Mallory scans public code for strings that start with AKIA. She finds the key.
  4. Mallory signs AWS API calls with the key from her own computer.
  5. Servo checks the signature and the policy of the key's user. Both are correct.
  6. Servo sends the data. For AWS, this is a normal request from Alice's user.
  7. IAM did its job. The key was the problem. A key is an identity.

Most IAM incidents have one or both of two causes: a leaked credential and too much permission.

An attacker uses a leaked access key from a laptop in another country. What does AWS check before it allows the call?

  1. The device and the country of the caller
  2. The signature of the request and the policies that apply to that identity
  3. That the real owner of the key sent the request
  4. That the caller passed MFA in the last hour

AWS verifies the signature and evaluates the policies. Anyone with the key and the secret is that identity. Conditions such as aws:SourceIp add checks only if you write them.

3How AWS decides

Each request has four parts. The principal is who calls. The action is what they do, for example s3:GetObject. The resource is the target, written as an ARN. The context holds facts such as the source IP, the time and MFA.

Two rules control all of IAM. All requests start as denied. This is the implicit deny. An explicit Deny always wins over an Allow. The root user is an exception to the first rule. It has full access to its own account. In a member account of an organization, SCPs can still limit the root user.

Request
s3:GetObject on bills/2026.pdf
1 · Explicit Deny?
A Deny matches? Stop. Deny wins.
2 · SCP and RCP
The org guardrails must allow it.
3 · An Allow?
An identity or resource policy must allow it.
4 · Boundary, session
If they exist, they must also allow it.
ALLOW
  1. Browsy sends a request. At the start, the answer is "deny".
  2. Servo looks for an explicit Deny in all policies that apply. One match ends the check with a deny.
  3. Organization guardrails (SCPs and RCPs) must allow the action. They cannot grant anything.
  4. An identity-based or resource-based policy must say Allow. With no Allow, the implicit deny stays.
  5. A permissions boundary and a session policy, if present, must also allow the action.
  6. The request passed all checks. Servo allows it.

The result is an intersection. Guardrails, boundaries and session policies only make access smaller. Only identity-based and resource-based policies give access. In one account, an Allow in either of these two is usually sufficient. For cross-account access, both sides must allow the request.

"Walk me through how AWS evaluates a request."

All requests start as denied. If any explicit Deny matches, the result is deny. Then SCPs and RCPs must allow the action. Then an identity-based or resource-based policy must allow it. Then a boundary and a session policy, if present, must allow it. Cross-account requests need an Allow on both sides. Also say that SCPs do not apply to the management account.

4Identities and policies

The identities

  • Root user: the first identity of the account. It signs in with the account email address and has full access. Use it only for the few tasks that need it.
  • IAM user: a person or app with long-term credentials: a password and up to two access keys (AKIA…).
  • IAM group: a set of users that share policies. A group is not a principal.
  • IAM role: an identity with no long-term credentials. A trusted principal assumes the role and gets temporary keys (ASIA…) from AWS STS.

AWS recommends roles for workloads and federation for people. With federation, a person signs in through IAM Identity Center or a company identity provider. Then the person gets a role session.

AssumeRoleWithWebIdentity
GitHub Actions job
I must upload the site to S3. I have no AWS keys.
AWS STS
Trust policy check
issuer: GitHub ✓
aud: sts.amazonaws.com ✓
sub: repo:alice/site:ref:refs/heads/main ✓
ASIA… key, secret and session token. They expire.
Upload done. No secret is in my repo.
no stored keys
  1. Browsy is a deploy job in GitHub Actions. It must write to S3. It has no AWS keys.
  2. GitHub gives the job a signed OIDC token. Browsy sends it to AWS STS and asks for a role.
  3. Servo reads the role's trust policy. It checks the issuer, the audience and the subject: which repo and which branch.
  4. Servo sends temporary credentials. The key ID starts with ASIA. The credentials expire.
  5. Browsy uploads the site. The repository holds no secret that an attacker can steal.

The policy types

A role has two policies. The trust policy says who can assume the role. The permissions policy says what the role can do.

  • Identity-based policy: on a user, group or role. AWS managed, customer managed or inline.
  • Resource-based policy: on a resource, for example an S3 bucket policy. It names a Principal. A trust policy is one too.
  • Permissions boundary: a managed policy that sets the maximum permissions for one user or role.
  • SCP and RCP: AWS Organizations policies. An SCP limits the principals in member accounts. An RCP limits the resources.
  • Session policy: a caller can pass it when it assumes a role. It makes that session smaller.
More termsAn ARN names a resource: arn:aws:iam::111122223333:role/deploy. An instance profile carries a role to an EC2 instance. A service-linked role belongs to an AWS service, and SCPs do not affect it. Access key IDs that start with AKIA are long-term. IDs that start with ASIA are temporary.

Classify each policy type.

  • A customer managed policy on a role
  • A service control policy (SCP)
  • An S3 bucket policy
  • A permissions boundary
  • A session policy passed to AssumeRole
  • An inline policy on a user
  • A resource control policy (RCP)

Only identity-based and resource-based policies can say "yes". SCPs, RCPs, boundaries and session policies set a maximum. An SCP that allows * gives no access to a user that has no Allow in an identity-based or resource-based policy.

5Reading a policy

A policy is JSON. Each statement has an Effect, an Action, a Resource and an optional Condition. Resource-based policies also have a Principal. Most IAM bugs come from one wildcard or one missing condition in these fields.

So the danger is usually a wildcard in the wrong place?
Yes. Read each field and ask: "Who else does this match?" That question finds most IAM bugs.

PolicyAn identity policy on an app role.

{"Effect": "Allow", "Action": "*", "Resource": "*"}

AttackIf the role's keys leak, the attacker gets full access to the account.

FixList the exact actions and ARNs. Use IAM Access Analyzer to make a policy from real CloudTrail activity.

Policy"All but IAM" for developers.

{"Effect": "Allow", "NotAction": "iam:*", "Resource": "*"}

WhyNotAction with Allow allows all other actions, including new AWS services.

FixUse NotAction only with Deny. Use an Action list for Allow.

PolicyA role trust policy.

{"Effect": "Allow", "Principal": {"AWS": "*"}, "Action": "sts:AssumeRole"}

AttackA principal in any AWS account can assume the role.

Why"*" in Principal means all AWS principals, not "all principals in my account".

FixName the exact account or role ARN. Add aws:PrincipalOrgID as a condition for your organization.

PolicyA role for a monitoring vendor.

{"Effect": "Allow", "Principal": {"AWS": "VENDOR_ACCOUNT_ID"},
 "Action": "sts:AssumeRole"} no Condition

AttackA different customer of the vendor enters your role ARN. The vendor then reads your account. This is the confused deputy problem.

FixAdd "Condition": {"StringEquals": {"sts:ExternalId": "VALUE_FROM_VENDOR"}}. The vendor makes a unique ID for each customer.

PolicyA deploy role for GitHub Actions.

"Principal": {"Federated": "arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com"},
"Condition": {"StringEquals": {"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"}}
no check on token.actions.githubusercontent.com:sub

AttackA workflow in any GitHub repository can get credentials for this role.

WhyBy default, the audience is the same for all GitHub users. Only sub names your repo and branch.

FixMatch sub. IAM now rejects a new or changed trust policy for GitHub without a sub check, or with a sub that is only a wildcard. Old roles that nobody changed can still have this gap.

PolicyA policy that lets a developer start servers.

{"Effect": "Allow", "Action": ["ec2:RunInstances", "iam:PassRole"], "Resource": "*"}

AttackThe developer starts an instance with the admin role and reads its keys.

Whyiam:PassRole lets a principal give a role to a service. If the role has more access, the principal gets that access too.

FixAllow iam:PassRole only on named role ARNs. Add the iam:PassedToService condition.

A role trust policy has "Principal": {"AWS": "*"} and no condition. Who can assume the role?

  1. Only principals in the same account
  2. No one, because the caller also needs an Allow for sts:AssumeRole
  3. A principal in any AWS account that knows the role ARN
  4. Only AWS services

The star matches all AWS principals. The attacker gives themselves sts:AssumeRole in their own account. Name exact principals, or add aws:PrincipalOrgID.

A vendor asks you to make a cross-account role for its service. What protects you from the confused deputy problem?

  1. An sts:ExternalId condition with a unique value from the vendor
  2. A secret role name that only the vendor knows
  3. An aws:MultiFactorAuthPresent condition
  4. A maximum session duration of one hour

The vendor sends a unique external ID for each customer. A different customer cannot change that value. For AWS services, use aws:SourceArn and aws:SourceAccount.

6Escalation paths

Privilege escalation in IAM means a principal uses its permissions to get more permissions. Rhino Security Labs listed 21 methods in 2018. Learn the pattern: a permission that changes permissions is an admin permission.

Dangerous permissions
  • iam:CreatePolicyVersion
  • iam:Attach*Policy, iam:Put*Policy
  • iam:CreateAccessKey
  • iam:CreateLoginProfile
  • iam:UpdateAssumeRolePolicy
  • iam:PassRole + a compute action
  • lambda:UpdateFunctionCode
What the attacker does
  • Writes an admin version of their own policy
  • Attaches AdministratorAccess to themselves
  • Makes keys for a stronger user
  • Sets a console password for a stronger user
  • Adds themselves to a role trust policy
  • Runs EC2, Lambda or Glue with a stronger role
  • Puts new code in a function that has a strong role
Safe alternatives
  • Give IAM write actions to a pipeline, not to people
  • Scope IAM actions to named ARNs
  • Use a permissions boundary on created roles
  • Allow PassRole only for named roles
  • Add iam:PassedToService
  • Deny IAM changes in an SCP outside the admin role

This policy is on a CI user. Tap the two lines that let the user become an admin.

{"Effect":"Allow","Action":"s3:GetObject","Resource":"arn:aws:s3:::assets/*"}
{"Effect":"Allow","Action":"logs:PutLogEvents","Resource":"*"}
{"Effect":"Allow","Action":"iam:CreatePolicyVersion","Resource":"*"}
{"Effect":"Allow","Action":"ec2:DescribeInstances","Resource":"*"}
{"Effect":"Allow","Action":"iam:GetRole","Resource":"*"}
{"Effect":"Allow","Action":["iam:PassRole","ec2:RunInstances"],"Resource":"*"}
{"Effect":"Deny","Action":"s3:DeleteBucket","Resource":"*"}

Line 3 lets the user write a new default version of its own policy. Line 6 lets the user start an instance with any role, for example an admin role, and read its keys. Line 7 is a Deny, so it only removes access.

7Attacking IAM

RuleTest only systems that you have permission to test. Use your own test accounts. Do not use a key that you find unless the owner gives you written permission. Report a found key to the owner.

You are on an authorised assessment. You get an access key for a test account. Put the steps in the correct order.

  1. Confirm the scope and the written permission
  2. Run aws sts get-caller-identity to see the principal and the account
  3. List the policies of that principal and its groups
  4. Map the escalation paths with a tool such as PMapper or Pacu
  5. Show the impact with the smallest safe action in the test account
  6. Report, and ask the owner to deactivate and rotate the key

Know your limits first. Then learn who the key is, what it can do, and the paths to more access. get-caller-identity needs no permissions, and an explicit Deny does not stop it.

Commands, from simple to deep

# who am I? (works even with an explicit Deny)
aws sts get-caller-identity
# which account owns this key?
aws sts get-access-key-info --access-key-id AKIA...
# what can this user do?
aws iam list-attached-user-policies --user-name ci-bot
aws iam list-groups-for-user --user-name ci-bot
aws iam get-policy-version --policy-arn POLICY_ARN --version-id v1
# test a guess without a real call
aws iam simulate-principal-policy --policy-source-arn USER_ARN --action-names iam:CreatePolicyVersion
# instance metadata on an EC2 host that you test (IMDSv2)
TOKEN=$(curl -X PUT http://169.254.169.254/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 300")
curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/

Stealing role keys through the metadata service

An EC2 instance gets its role keys from the instance metadata service (IMDS) at 169.254.169.254. With IMDSv1, a plain GET returns the keys. So a server-side request forgery (SSRF) bug in an app can read them.

This app fetches any URL that I give it.
?url=http://169.254.169.254
/latest/meta-data/iam/
security-credentials/web-role
app on EC2 · IMDSv1
169.254.169.254AccessKeyId: ASIA…SecretAccessKey: …Token: …
Valid role keys. This role can read all buckets.
Buckets copied!
  1. Mallory finds an app on EC2 that fetches any URL. This is an SSRF bug.
  2. Mallory gives it the metadata URL for the role credentials.
  3. The instance uses IMDSv1. A plain GET returns the role's temporary keys.
  4. The app sends the response to Mallory. Now she has the keys.
  5. Mallory uses the keys from her own computer.
  6. The role can read all buckets, so Servo allows it. The Capital One breach in 2019 used a similar chain.

IMDSv2 makes this harder. The caller must send a PUT to get a session token, then send the token in a header. Most SSRF bugs can only send a GET. IMDSv2 also rejects a PUT with an X-Forwarded-For header.

Why does "IMDSv2 required" stop most SSRF attacks on role keys?

  1. It moves the metadata service to a secret IP address
  2. The caller must send a PUT to get a token and then send the token in a header. Most SSRF bugs cannot do both.
  3. It encrypts the role credentials so that only the SDK can read them
  4. It only answers requests from the AWS SDK process

Without the X-aws-ec2-metadata-token header, the request gets 401. IMDSv2 is defence in depth. Also fix the SSRF and make the role small.

Real incidents

  • Code Spaces, 2014: an attacker got into the AWS console and deleted the instances, buckets and backups. The company closed.
  • Uber, 2016: attackers found an AWS access key in plain text in a private GitHub repository of Uber engineers. With the key, they downloaded 25.6 million names and email addresses of Uber users (FTC).
  • Capital One, 2019: a misconfigured web application firewall sent requests to the metadata service. Its role had too many permissions. The attacker copied data about more than 100 million people, mostly from credit card applications.
  • LastPass, 2022: attackers put malware on a DevOps engineer's home computer. They took keys from the corporate vault and read the S3 production backups.
  • Public .env files, 2024: Unit 42 reported a campaign that targeted 110,000 domains with exposed .env files. About 7,000 of the stolen variables belonged to cloud services. In AWS, the attackers made a role with AdministratorAccess. They copied and deleted S3 data and left a ransom note.

"You find an AWS access key in a public repo during a bug bounty. What do you do?"

Do not use the key to look at data. If the program rules allow it, run only aws sts get-caller-identity to show the key is live. Report at once with the repo URL and the commit. Ask the owner to deactivate the key and review CloudTrail. The key stays compromised after a new commit deletes it.

8Defences in layers

No single setting makes IAM safe. Use layers. Each layer stops what the layer before it did not stop. Put the real fix first: remove long-term keys.

Stolen key: AKIA…
1 · No long keys
SSO and roles. Their keys expire.
2 · Least privilege
Exact actions on exact ARNs.
3 · Boundaries
A boundary caps each new role.
4 · SCP and RCP
The org blocks the action in all accounts.
5 · Detect
CloudTrail and GuardDuty flag odd calls.
  1. Mallory has a stolen key. Five layers protect Alice's account.
  2. Remove long-term keys. People sign in with IAM Identity Center. Workloads use roles. Their keys expire.
  3. Least privilege. Each role gets the actions it uses, on the resources it uses. Remove unused access.
  4. Permissions boundaries. Teams can make roles, but no role can get more than the boundary.
  5. SCPs and RCPs. The organization denies dangerous actions everywhere, for example turning off CloudTrail.
  6. Detection. CloudTrail records each call. GuardDuty flags role keys used outside AWS and other odd use.

Common mistakes

  • Root user: access keys on root, or no MFA on root. AWS now requires MFA for the root user in all account types.
  • Long-lived IAM users for CI: use OIDC federation with a strict sub condition.
  • Unused access: old roles, keys and permissions. IAM Access Analyzer finds them.
  • IMDSv1 allowed: set "IMDSv2 required" on all instances.

Which actions reduce the risk of a leaked key? Do not choose items that only help you find the leak later.

  1. Replace IAM users with roles and federation
  2. Turn on CloudTrail in all regions
  3. Remove permissions that the principal did not use in 90 days
  4. Turn on GuardDuty
  5. Add a permissions boundary to roles that developers create
  6. Turn on CloudTrail log file validation

Temporary credentials expire. Least privilege makes each key smaller. A boundary stops escalation through new roles. CloudTrail and GuardDuty detect. They do not prevent.

A safe trust policy for GitHub Actions

{
  "Effect": "Allow",
  "Principal": { "Federated": "arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com" },
  "Action": "sts:AssumeRoleWithWebIdentity",
  "Condition": {
    "StringEquals": {
      "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
      "token.actions.githubusercontent.com:sub": "repo:alice/site:ref:refs/heads/main"
    }
  }
}

The sub line limits the role to one repository and one branch. Give the role only the S3 actions it uses. On github.com, repositories created or renamed after 15 July 2026 use a new sub format with numeric IDs, for example repo:alice@123456/site@456789:ref:refs/heads/main. Check the sub format of your repository before you write the condition.

An SCP on the root of your organization denies cloudtrail:StopLogging. An admin in the management account runs that action. What happens?

  1. The SCP blocks it
  2. The SCP blocks it only if the admin has no MFA
  3. An RCP is necessary to block it
  4. It works. SCPs do not apply to users or roles in the management account.

SCPs affect only member accounts. Keep the management account almost empty. SCPs also do not affect service-linked roles.

9Senior round

Senior interviews often ask about these topics. Know what each one is and how it works.

Confused deputyA trusted party acts for the wrong customer. Cross-account: require sts:ExternalId. Cross-service: when a resource policy trusts an AWS service, add aws:SourceArn or aws:SourceAccount.
Same-account resource policiesIn one account, an Allow in the identity policy or in the resource policy is usually sufficient. Role trust policies and KMS key policies are exceptions. They must allow the principal, by name or through its account. An identity policy alone does not give access to a role or a KMS key. Also, a resource policy that names an IAM user ARN directly gives access even when the boundary of that user does not allow the action.
Role chaining and session lengthA role session lasts from 15 minutes to the role's maximum of 1 to 12 hours. A role that assumes another role gets 1 hour at most. To stop sessions early, revoke them. This adds a Deny on aws:TokenIssueTime.
Data perimeterAllow only my principals, on my resources, from my networks. Use aws:PrincipalOrgID, aws:ResourceOrgID and VPC endpoint conditions. RCPs (November 2024) put the resource checks in one place.
ABAC with tagsAllow access when aws:PrincipalTag/team equals aws:ResourceTag/team. Control who can change tags, because a tag change is then a permission change.
Finding unused accessIAM Access Analyzer finds external access to resources. Since November 2023, it also finds unused roles, keys and permissions.

"A developer needs to create roles for their Lambda functions. How do you allow this without giving them admin?"

Allow iam:CreateRole only with the condition iam:PermissionsBoundary set to an approved boundary. Deny changes to that boundary. Allow iam:PassRole only on an agreed role path, and only to Lambda with iam:PassedToService.

"GuardDuty says that role keys from an EC2 instance are in use from an outside IP address. What do you do?"

Revoke the active sessions of the role. Use CloudTrail to list all actions of that session. Look for persistence: new users, keys, roles and trust policy changes. Find the root cause on the instance, for example SSRF with IMDSv1. Fix it and make the role smaller.

A user has AdministratorAccess. A permissions boundary on the user allows only s3:*. The SCP allows *. Can the user call ec2:RunInstances?

  1. Yes, because AdministratorAccess allows it
  2. No, because the SCP blocks it
  3. No. The action must be in the boundary too, and the boundary allows only S3.
  4. Yes, because boundaries apply only to roles

Effective permissions are the intersection of the identity policy, the boundary and the SCP. Here that is s3:*.

10Interview mode

Give your answer in four parts: what it is, how attackers use it, how to fix it, and one deeper detail. Use 30 to 60 seconds.

Example: "What is iam:PassRole and why is it dangerous?"

  1. What: a permission that lets a principal give a role to an AWS service, for example to an EC2 instance or a Lambda function.
  2. Attack: with iam:PassRole on * and ec2:RunInstances, an attacker starts an instance with an admin role and reads its keys.
  3. Fix: allow PassRole only on named role ARNs, with iam:PassedToService.
  4. Detail: PassRole is a permission, not an API call, so CloudTrail has no PassRole event.

Say each answer aloud before you flip the card. Tick "only the ones I missed" to practise your missed cards.

What is AWS IAM?
The AWS service that controls who can do which action on which resource. It checks each API call against the policies.
What is the difference between a user, a group and a role?
A user has long-term credentials. A group is a set of users that share policies. A role has no long-term credentials. A trusted principal assumes it and gets temporary credentials.
Why use roles instead of access keys?
Role credentials expire. Nothing secret is stored in code. AWS delivers and refreshes them on EC2, Lambda and ECS.
What is the difference between a trust policy and a permissions policy?
The trust policy says who can assume the role. The permissions policy says what the role can do.
What is the principle of least privilege?
Give each identity only the actions and resources that it needs. Remove access that it does not use.
What is the difference between an implicit deny and an explicit deny?
An implicit deny is the default when no policy allows the action. An explicit deny is a Deny statement, and it always wins.
How do you protect the root user?
Set strong MFA. Do not create root access keys. Use root only for the tasks that need it.
What is the difference between identity-based and resource-based policies?
An identity-based policy is on a user, group or role. A resource-based policy is on a resource and names a principal.
What do AKIA and ASIA mean?
Access key IDs that start with AKIA are long-term keys of a user or the root user. IDs that start with ASIA are temporary keys from AWS STS.
How does an app on EC2 get AWS credentials?
Attach a role through an instance profile. The SDK gets temporary credentials from the instance metadata service.
What is AWS STS?
The Security Token Service. It issues temporary credentials, for example through AssumeRole.
What is the difference between managed and inline policies?
A managed policy is a separate object with versions, for many identities. An inline policy is part of one identity.
An access key leaked. What are the first steps?
Deactivate the key. Check CloudTrail for its calls. Remove what the attacker made, such as new users, keys and roles.
What does CloudTrail record?
The AWS API calls: who called, which action, when, from which IP, and the result.
Explain the policy evaluation order.
Explicit Deny first. Then SCPs and RCPs must allow. Then an identity or resource policy must allow. Then a boundary and a session policy must allow.
What is an SCP? What can it not do?
It sets the maximum permissions for principals in member accounts. It never grants access. It does not affect the management account.
What is a permissions boundary?
A managed policy that sets the maximum permissions of one user or role. It grants nothing.
What is iam:PassRole?
A permission to give a role to an AWS service. Passing a strong role to a service you control gives you its access.
Name three IAM privilege escalation paths.
iam:CreatePolicyVersion on your own policy. iam:AttachUserPolicy to add admin to yourself. iam:PassRole with ec2:RunInstances or lambda:CreateFunction.
How do you give access to a role in a different account?
The trust policy in account B names a principal in A. A policy in A allows sts:AssumeRole on the role. Both sides must allow it.
What is the confused deputy problem?
A trusted vendor acts on the wrong customer's account. Fix it with sts:ExternalId, or aws:SourceArn for AWS services.
Why is NotAction with Allow dangerous?
It allows every action not in the list, including future services. Use NotAction with Deny only.
How does IMDSv2 stop SSRF attacks?
A caller must send a PUT for a token, then send it in a header. Most SSRF bugs can send only a GET.
How do you connect GitHub Actions to AWS without keys?
Add GitHub as an OIDC provider. The role's trust policy checks aud and sub. The job gets temporary credentials.
What do IAM condition keys do? Give examples.
They check the request context, for example aws:MultiFactorAuthPresent, aws:SourceIp and aws:PrincipalOrgID.
How do you find unused permissions?
Use IAM last accessed data and the unused access findings of IAM Access Analyzer.
What does GetCallerIdentity tell an attacker?
The account ID and the ARN of the user or role that owns the key. It needs no permissions. A Deny does not stop it.
In one account, is one Allow sufficient?
Usually yes. An Allow in the identity policy or in the resource policy is sufficient. Role trust policies and KMS key policies must always allow the principal. Cross-account access needs an Allow on both sides.
What is an RCP and why was it added?
A resource control policy (November 2024). It sets the maximum permissions on resources in member accounts, without editing each resource policy.
What is a data perimeter?
A set of guardrails: only trusted identities get to trusted resources, from expected networks. Use org ID conditions, VPC endpoint policies, SCPs and RCPs.
How do you revoke temporary credentials?
They stay valid until they expire. Revoke the role's sessions, which adds a Deny on aws:TokenIssueTime.
What is role chaining and what is its limit?
A role session assumes a different role. The new session lasts one hour at most.
How do you let developers create roles safely?
Require a boundary with iam:PermissionsBoundary on CreateRole. Limit PassRole to named roles.
What is ABAC in AWS? What is its risk?
Access based on matching tags. A user who can change tags can change their access.
What went wrong in the Capital One breach?
An SSRF in a misconfigured WAF read role keys from the metadata service. The role could read many buckets.
How do you investigate a role whose keys are used outside AWS?
Revoke the sessions. Use CloudTrail to find all calls. Look for persistence. Fix the root cause on the workload.
How does an attacker keep access after you rotate the key they stole?
The attacker makes new access keys, users or roles. The attacker adds their own account to a trust policy or sets a console password.
Why is the GitHub OIDC sub condition so important?
By default, the audience is the same for all GitHub users. Without sub, any repository can assume the role.
How do you make the management account safe?
SCPs do not apply to it. Run no workloads in it, and allow very few people in.
How do you scale least privilege across 200 accounts?
Use IAM Identity Center for people and SCPs and RCPs as guardrails. Put boundaries on new roles. Keep policies as code and review each change.

11Cheat sheet

The ideaThe caller signs each AWS call. AWS finds the identity and checks all policies. Default deny. Explicit Deny wins.
Identities
  • Root: full access, use it rarely
  • User: long-term keys (AKIA)
  • Role: temporary keys (ASIA)
  • Group: holds policies, not a principal
Policy types
  • Grant: identity-based, resource-based
  • Limit: SCP, RCP, boundary, session
  • Trust policy: who can assume a role
Defence order
  1. Roles and SSO, no long keys
  2. Least privilege
  3. Boundaries
  4. SCPs and RCPs
  5. CloudTrail, GuardDuty
Show it
  • sts get-caller-identity
  • One escalation path, in a test account
  • Which data the role can reach
Incorrect ideas
  • An SCP grants access
  • Rotation alone fixes a leak
  • A role ARN is a secret
  • SCPs cover the management account
  • Deleting a key from git removes the leak
Done! Next classes: Linux privilege escalation, JWT attacks and the TLS handshake.

Did you find an error? Tell me on X. Paper versions: the AWS Security Guide and the AWS Identity, Keys + Ops Security zines.

Get the next one by email

New posters land in the Security Zines newsletter on Substack. Free, no spam.