Security and Compliance · Topic 1 of 5

IAM Policies, Roles and Access

Understand IAM policy types, evaluation logic, roles and STS, MFA and access analysis, and how to troubleshoot AccessDenied errors for the SOA-C03 exam.

  • 5 min
In a nutshell
  • IAM defaults to deny, and an explicit Deny always wins.
  • Roles give temporary credentials through STS, and are preferred over long lived access keys.
  • A role has a trust policy (who) and a permissions policy (what).

What it is

AWS Identity and Access Management (IAM) controls who can do what in your account. A principal (a user, role or application) sends a request, and IAM decides whether to allow it by evaluating policies.

The main identities are IAM users (long lived credentials, avoid where possible), groups of users, and roles. A role has no password or access key of its own. Instead, a trusted principal assumes it and receives temporary credentials from the AWS Security Token Service (STS).

Principaluser or serviceassumesIAM roletrust policy checksgetsTemporary credentialsSTScallsAWS APIpermission policy checks

How it works

Policy types

Policy typeAttached toEffect
Identity basedUser, group or roleGrants permissions to that identity
Resource basedResource such as S3 bucket, SQS queue, KMS keyGrants access to named principals, including other accounts
Permissions boundaryUser or roleSets the maximum permissions the identity can have
Service control policy (SCP)Organization, OU or accountSets the maximum for all principals in the account
Session policyA role sessionNarrows permissions for that session

A permissions boundary and an SCP never grant anything by themselves. They only limit what other policies can grant.

Evaluation logic

IAM starts from an implicit deny. Then it applies these rules.

  1. An explicit Deny in any applicable policy always wins.
  2. Otherwise, the request needs an Allow, and the allow must also fit within any SCP, permissions boundary and session policy.
  3. If there is no allow, the request is denied.

In the same account, an allow in either the identity policy or the resource policy is enough. For cross account access, both the resource's account (through its resource policy) and the caller's account (through an identity policy) must allow.

A small identity policy that follows least privilege:

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["s3:GetObject"],
    "Resource": "arn:aws:s3:::reports-bucket/*",
    "Condition": { "Bool": { "aws:MultiFactorAuthPresent": "true" } }
  }]
}

Conditions refine when a statement applies. Common keys include aws:SourceIp, aws:RequestedRegion, aws:PrincipalOrgID and aws:MultiFactorAuthPresent.

Roles

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

EC2 instances use a role through an instance profile, and Lambda functions use an execution role. This removes the need to store access keys on servers.

# AWS CLI: assume a role and receive temporary credentials
aws sts assume-role \
  --role-arn arn:aws:iam::111122223333:role/ReadOnlyAudit \
  --role-session-name audit-check

Cross account access uses a role in the target account that trusts the other account. For workforce sign in to many accounts, IAM Identity Center provides single sign on with permission sets.

Hardening the account

  • Protect the root user with MFA (multi factor authentication), and do not use it for daily work or create access keys for it.
  • Require MFA for people with console access, and set a password policy.
  • Rotate or remove unused access keys. The credential report lists users and the age of their passwords and keys.
  • IAM Access Advisor shows when a service was last used by an identity, which helps you trim permissions.
  • IAM Access Analyzer finds resources shared outside your zone of trust, validates policies and can highlight unused access.

Troubleshooting AccessDenied

Work through the layers in order.

1. Is there an explicit Deny in any policy?
2. Does an SCP or permissions boundary block the action?
3. Does the identity policy allow the action on this resource ARN?
4. For cross account access, does the resource policy also allow?
5. For KMS or S3 encrypted data, does the key policy allow use?
6. Do conditions (MFA, IP, Region, tags) match the request?

The IAM policy simulator tests what a policy would allow. CloudTrail shows the denied call and who made it. For some services, an encoded failure message can be decoded with aws sts decode-authorization-message.

Exam tip

An explicit Deny beats every Allow, and an SCP can only restrict. If a user has AdministratorAccess but still cannot act, look for an SCP or boundary.

What to remember for the exam

  • IAM defaults to deny, and an explicit Deny always wins.
  • Roles give temporary credentials through STS, and are preferred over long lived access keys.
  • A role has a trust policy (who) and a permissions policy (what).
  • Same account: identity or resource policy allow is enough. Cross account: both sides must allow.
  • Permissions boundaries and SCPs set maximums and do not grant permissions.
  • Use instance profiles for EC2 and execution roles for Lambda.
  • The credential report and Access Advisor support audits and least privilege.
  • IAM Access Analyzer reports external access to resources.
  • Root user: enable MFA and avoid daily use.

Common mistakes

Embedding access keys on instances. Use a role on the instance, so credentials are temporary and rotate automatically.

Thinking an SCP grants access. It does not. The identity still needs its own allow.

Forgetting the trust policy. A role with the right permissions cannot be assumed if the principal is not trusted.

Using wildcards for convenience. Action: * on Resource: * breaks least privilege.

Ignoring resource policies for cross account. Both accounts need to agree for most services.

Watch out

The management account of an organization is not limited by SCPs, so do not run workloads there and keep its use to a minimum.

Check yourself

Try these three questions.

  • Which wins, an Allow or an explicit Deny?

    An explicit Deny always wins over any Allow.

  • What do a permissions boundary and an SCP have in common?

    Both set a maximum on permissions and neither grants permissions on its own.

  • How should an EC2 instance get access to S3?

    Through an IAM role attached with an instance profile, which gives temporary credentials.

Topic 1 of 5 in Security and Compliance

Test yourself on Security and Compliance

The full AWS SOA-C03 question bank has 850 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.