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
- 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.
How it works
Policy types
| Type | Attached to | Effect |
|---|---|---|
| Identity based policy | User, group or role | Grants permissions |
| Resource based policy | Bucket, key, queue, role trust and others | Grants permissions to named principals, including other accounts |
| Permission boundary | User or role | Sets a ceiling on what identity policies can grant |
| Service control policy (SCP) | Organization, OU or account | Sets a ceiling for all principals in the account |
| Session policy | An assumed role session | Narrows that session |
Only identity and resource policies grant access. Boundaries, SCPs and session policies only limit.
Evaluation logic
- Everything is denied by default.
- An explicit
Denyin any applicable policy ends the evaluation with a deny. - For an allow to stand, every limiting layer that applies (SCP, permission boundary, session policy) must also allow the action.
- 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.
| Control | Scope | Use |
|---|---|---|
| Permission boundary | One user or role | Delegated administration within a ceiling |
| SCP | Whole account or OU | Organization 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
| Key | Purpose |
|---|---|
aws:PrincipalOrgID | Allow any account in your organization in a resource policy |
aws:SourceIp, aws:SourceVpce | Limit to networks or VPC endpoints |
aws:MultiFactorAuthPresent | Require multi factor authentication |
aws:RequestedRegion | Limit Regions |
aws:SecureTransport | Require 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:PassRoleshould be restricted to specific roles.- Permission boundaries allow safe delegation of role creation.
- ABAC with tags scales better than a policy per project.
aws:PrincipalOrgIDsimplifies resource policies across an organization.- Access Analyzer finds external access and builds least privilege policies.
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.
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.