Policies
Overview
An IAM policy is a JSON document that defines permissions. It lists statements, each of which says whether an Effect (Allow or Deny) applies to certain Actions on certain Resources, optionally under certain Conditions. Policies are attached to identities (users, groups, roles) or to resources (S3 buckets, SQS queues, KMS keys) and are evaluated every time you make a request.
By default everything is denied. A request is allowed only if some policy explicitly allows it and nothing explicitly denies it. This simple rule — default deny, explicit allow, explicit deny overrides — is the core of IAM and appears on the exam in many disguises.
You will meet several kinds of policy: identity-based, resource-based, permissions boundaries, Service Control Policies (SCPs) and session policies. Understanding how they combine is the difference between guessing and knowing the answer.
Key Concepts
- Policy elements: Version (use
2012-10-17), Statement with Sid, Effect, Principal (resource policies only), Action/NotAction, Resource/NotResource and Condition. - Default deny -> an explicit Allow is needed -> an explicit Deny always wins.
- Identity-based policies attach to users, groups and roles; resource-based policies attach to resources and include a Principal.
- AWS managed policies are maintained by AWS; customer managed policies are yours and versionable (up to 5 versions); inline policies are embedded in a single identity.
- Permissions boundary: maximum permissions an identity-based policy can grant a user or role; it never grants by itself.
- SCPs (AWS Organizations) set the maximum available permissions for accounts; they never grant by themselves and don't affect the management account.
- Session policies limit a role/federated session further when it is assumed.
- Size limits: managed policy 6,144 characters; inline policy for a user 2,048, group 5,120, role 10,240 characters.
- Conditions use keys such as
aws:SourceIp,aws:RequestedRegion,aws:MultiFactorAuthPresent,aws:PrincipalOrgID,aws:PrincipalTagands3:prefix.
Detailed Notes
Anatomy of a policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadReportsBucket",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": [
"arn:aws:s3:::acme-reports",
"arn:aws:s3:::acme-reports/*"
],
"Condition": {
"IpAddress": { "aws:SourceIp": "203.0.113.0/24" }
}
}
]
}
| Element | Meaning |
|---|---|
| Version | Policy language version; always 2012-10-17 |
| Sid | Optional statement id |
| Effect | Allow or Deny |
| Principal | Who — only in resource-based and trust policies |
| Action / NotAction | API operations such as s3:GetObject, wildcards allowed (s3:*) |
| Resource / NotResource | ARNs the actions apply to (identity policies require them except for actions that don't support resource-level permissions) |
| Condition | Extra tests (IP, time, MFA, tags, encryption, Region) |
Bucket-level actions like
s3:ListBucketapply to the bucket ARN; object actions likeGetObjectapply to bucket/* — a classic source of errors.
Policy types
| Type | Attached to | Grants permissions? | Notes |
|---|---|---|---|
| Identity-based | User, group, role | Yes | AWS managed, customer managed, inline |
| Resource-based | S3, SQS, SNS, KMS, Lambda, secrets, etc. | Yes, with a Principal | Enables cross-account without role assumption |
| Permissions boundary | User or role | No — sets a maximum | Used to delegate admin safely |
| SCP | Organization root, OU or account | No — sets a maximum for accounts | Affects all principals in member accounts including root |
| Session policy | Passed at AssumeRole/federation | No — further restricts session | Intersection with role policies |
| ACLs | S3, VPC (legacy / NACL) | Limited | Not JSON |
Policy evaluation logic
- Start with implicit deny.
- Look for any explicit Deny in all applicable policies (SCPs, boundaries, session, identity, resource). If found -> DENY.
- Organizations SCPs: if there is an SCP, the action must be allowed by it, otherwise DENY.
- Resource-based policy allow? (Same-account requests are allowed here if the principal ARN is named — no identity allow needed.)
- Permissions boundary, if present, must allow.
- Session policy, if present, must allow.
- Identity-based policy must allow.
- If none allow -> implicit DENY.
Effective permission (same account, identity policy path)
= Identity policy AND Permissions boundary AND SCP AND Session policy
(and no explicit Deny anywhere)
For cross-account requests both accounts must allow: the resource owner's resource policy (or role trust) and an identity policy in the caller's account.
Managed vs. inline
| AWS managed | Customer managed | Inline | |
|---|---|---|---|
| Maintained by | AWS | You | You |
| Reusable | Yes | Yes | No — 1:1 with the identity |
| Versioning | AWS updates | Up to 5 versions, rollback | None; deleted with the identity |
| Best for | Common job functions | Org-specific least-privilege | Strict 1:1 relationships |
Conditions in action
Deny access outside approved Regions and without MFA
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyOtherRegions",
"Effect": "Deny",
"NotAction": ["iam:*", "sts:*", "cloudfront:*", "route53:*", "support:*"],
"Resource": "*",
"Condition": { "StringNotEquals": { "aws:RequestedRegion": ["eu-west-1", "us-east-1"] } }
},
{
"Sid": "DenyIfNoMfa",
"Effect": "Deny",
"Action": "ec2:TerminateInstances",
"Resource": "*",
"Condition": { "BoolIfExists": { "aws:MultiFactorAuthPresent": "false" } }
}
]
}
Policy variables: give each user a private S3 folder
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::acme-home/${aws:username}/*"
}]
}
Attribute-based access control (ABAC)
Allow actions only when the principal's tag matches the resource's tag (e.g. aws:PrincipalTag/Project equals aws:ResourceTag/Project). ABAC lets one policy scale to many projects.
Resource-based policy example (cross-account S3)
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::444455556666:role/PartnerReader" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::acme-shared/*"
}]
}
Tools for writing and validating policies
- IAM Policy Simulator — test what a principal can do before deploying.
- IAM Access Analyzer — policy validation, unused access findings and least-privilege policy generation from CloudTrail.
- Access Advisor — last-accessed data to remove unused services.
Real World Example
Scenario — a bank enforces guardrails for 200 AWS accounts.
A bank gives each business unit its own AWS account under AWS Organizations. The security team must ensure no one can disable CloudTrail, use unapproved Regions or leave data unencrypted, yet developers must be able to create their own roles.
At the organisation level they apply SCPs: one denying cloudtrail:StopLogging and cloudtrail:DeleteTrail, and another denying all actions outside eu-west-1 and eu-central-1. Inside accounts, team leads can create IAM roles for applications, but every new role must carry a permissions boundary (enforced with an iam:PermissionsBoundary condition) that caps it to approved services and blocks IAM administration.
Application teams write customer managed identity policies with least privilege, and use ABAC with a CostCentre tag so a single policy covers every team's resources. S3 buckets holding shared data use resource-based policies with aws:PrincipalOrgID so any account in the organisation can read but nobody outside can. Policies are checked with Access Analyzer in the CI pipeline before deployment.
Architecture Diagram
A request must pass every applicable layer; an explicit Deny anywhere ends the evaluation.
- 1The request starts as an implicit deny.
- 2Any explicit Deny in any applicable policy ends evaluation with a denial.
- 3SCPs and permissions boundaries must both allow the action, as guardrails around what can be granted.
- 4An identity-based or resource-based Allow then grants access; with no Allow the request is denied.
Best Practices
- ✓Start from least privilege: grant only the actions and resources required, then widen if needed — use Access Analyzer to generate policies from CloudTrail.
- ✓Prefer customer managed policies over inline, so they are reusable, versioned and easier to audit.
- ✓Avoid
"Action": "*"with"Resource": "*"; scope to specific ARNs and add conditions (MFA, source VPC endpoint, Region, org ID). - ✓Use explicit Deny guardrails (SCPs, boundaries) for things that must never happen, such as disabling CloudTrail or leaving the approved Regions.
- ✓Use ABAC with tags to scale permissions without writing a policy per project.
- ✓Validate with the IAM Policy Simulator and Access Analyzer before deployment; put policy checks into CI/CD.
- ✓Use
aws:PrincipalOrgIDin resource policies instead of listing every account. - ✓Review unused permissions with Access Advisor and Access Analyzer unused-access findings; remove what isn't used.
Common Interview Questions
Exam Tips
SAA-C03 focus
- Default deny -> explicit allow -> explicit deny overrides. Memorise this order.
- SCPs and permission boundaries never grant permissions — they only set a maximum. The effective permission is the intersection.
- SCPs affect all accounts' principals, including root, but not the management account.
- Cross-account: both sides must allow (resource policy or role trust and caller's identity policy), unless a resource policy names the principal and same-account rules apply.
- Know the size limits: managed 6,144; inline user 2,048, group 5,120, role 10,240 characters.
- A customer managed policy can have up to 5 versions; inline policies have no versions.
- "Allow only from corporate IP / VPC endpoint / with MFA / in one Region" -> Condition keys
aws:SourceIp,aws:SourceVpce,aws:MultiFactorAuthPresent,aws:RequestedRegion. - "Test policies without making real calls" -> IAM Policy Simulator; "find resources shared externally" -> Access Analyzer.
Finished this lesson?
0 of 64 lessons done · 0% of the course

