Security and Compliance · Topic 1 of 6

IAM Policies, Roles and Evaluation

Master IAM policy evaluation, roles and STS, trust policies, external IDs, permission boundaries, attribute based access control and least privilege.

  • 5 min
In a nutshell
  • Default deny; explicit deny always wins.
  • SCPs, permission boundaries and session policies limit but never grant.
  • Cross account access needs an allow on both sides, unless a role is assumed.

What it is

AWS Identity and Access Management (IAM) decides whether a request is allowed. At professional level the questions are less about writing one policy and more about predicting the outcome when several policy types apply at once.

The safest model for people and machines is short lived credentials from roles, not long lived access keys. Roles are assumed through the AWS Security Token Service (STS), which returns temporary credentials.

Principaluser, role, serviceRequestAPI callPolicy evaluationall policy typesDecisionallow or deny

How it works

Policy types

TypeAttached toEffect
Identity based policyUser, group or roleGrants permissions
Resource based policyBucket, key, queue, role trust and othersGrants permissions to named principals, including other accounts
Permission boundaryUser or roleSets a ceiling on what identity policies can grant
Service control policy (SCP)Organization, OU or accountSets a ceiling for all principals in the account
Session policyAn assumed role sessionNarrows that session

Only identity and resource policies grant access. Boundaries, SCPs and session policies only limit.

Evaluation logic

  1. Everything is denied by default.
  2. An explicit Deny in any applicable policy ends the evaluation with a deny.
  3. For an allow to stand, every limiting layer that applies (SCP, permission boundary, session policy) must also allow the action.
  4. An allow from an identity policy or a resource policy then grants access.

Within one account, a resource policy that names the principal can grant access even if the identity policy says nothing. Across accounts, both sides must allow: the identity policy in the caller's account and the resource policy in the owner's account. When a role is assumed in the other account, the request is evaluated in that account as the role.

Roles and trust

A role has two policy parts. The trust policy says who may assume the role. The permissions policy says what the role can do after it is assumed.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": {"AWS": "arn:aws:iam::111122223333:root"},
    "Action": "sts:AssumeRole",
    "Condition": {"StringEquals": {"sts:ExternalId": "example-id-123"}}
  }]
}

An external ID protects a role that a third party assumes on your behalf against the confused deputy problem, where another customer of the third party tricks it into assuming your role on that customer's behalf.

aws sts assume-role --role-arn arn:aws:iam::444455556666:role/AuditRole \
  --role-session-name audit-check

Services use roles too: an EC2 instance profile, a Lambda execution role, an ECS task role. To let a user or service hand a role to a service, they need iam:PassRole for that role, which is a common privilege escalation path, so scope it to specific role ARNs.

Permission boundaries

A permission boundary is a managed policy that caps a role or user. It lets you delegate role creation safely: a developer may create roles, but only if the new role carries the boundary, so it can never exceed the ceiling.

ControlScopeUse
Permission boundaryOne user or roleDelegated administration within a ceiling
SCPWhole account or OUOrganization wide guardrail

Attribute based access control

Attribute based access control (ABAC) uses tags to scale permissions. One policy applies to many resources, and access follows tags on the principal and the resource.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["ec2:StartInstances", "ec2:StopInstances"],
    "Resource": "*",
    "Condition": {
      "StringEquals": {"aws:ResourceTag/Team": "${aws:PrincipalTag/Team}"}
    }
  }]
}

New teams and projects need only tags, not new policies. Session tags can pass attributes from an identity provider into the assumed role.

Useful condition keys

KeyPurpose
aws:PrincipalOrgIDAllow any account in your organization in a resource policy
aws:SourceIp, aws:SourceVpceLimit to networks or VPC endpoints
aws:MultiFactorAuthPresentRequire multi factor authentication
aws:RequestedRegionLimit Regions
aws:SecureTransportRequire TLS

Least privilege tools

  • IAM Access Analyzer finds resources shared outside your account or organization, flags unused access, validates policies and can generate a policy from CloudTrail activity.
  • Last accessed information shows which services and actions a role actually used.
  • The policy simulator tests what a principal can do before you deploy.
  • Credential reports list users and the age of their keys and passwords.

What to remember for the exam

  • Default deny; explicit deny always wins.
  • SCPs, permission boundaries and session policies limit but never grant.
  • Cross account access needs an allow on both sides, unless a role is assumed.
  • A role has a trust policy (who) and a permissions policy (what).
  • Use an external ID for third party role access.
  • iam:PassRole should be restricted to specific roles.
  • Permission boundaries allow safe delegation of role creation.
  • ABAC with tags scales better than a policy per project.
  • aws:PrincipalOrgID simplifies resource policies across an organization.
  • Access Analyzer finds external access and builds least privilege policies.
Exam tip

When a question has several policy layers, check for an explicit deny first, then check whether each ceiling allows the action.

Common mistakes

Believing an SCP grants access. It only filters what identity and resource policies can give.

Using long lived access keys for automation. Roles with temporary credentials remove the risk of leaked keys.

Granting iam:PassRole on *. A user can then attach a more powerful role to a service they control.

Forgetting the resource side across accounts. The identity policy alone is not enough.

Watch out

A role trust policy that names an account root principal trusts every principal in that account that has permission to assume the role, so combine it with conditions where you can.

Check yourself

  • What happens when one policy allows and another explicitly denies?

    The explicit deny wins and the request is denied.

  • What is the purpose of an external ID?

    It stops another customer of a third party from tricking that party into assuming your role on their behalf.

  • Why use ABAC?

    One tag based policy covers many resources, so new projects need tags rather than new policies.

Topic 1 of 6 in Security and Compliance

Test yourself on Security and Compliance

The full AWS DOP-C02 question bank has 844 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.