Skip to content

Every AWS request starts as denied. An explicit Allow in an identity or resource policy carves an exception into that implicit deny, and an explicit Deny anywhere cancels every allow. Guardrails such as permissions boundaries, SCPs and session policies never grant anything: they cap the maximum, so the effective permission is the intersection of all of them.

PrincipalWhat it is
IAM userLong-lived identity with keys or a password
IAM roleIdentity with no credentials; assumed for a session
Role sessionTemporary credentials from STS
Service principalAn AWS service, e.g. lambda.amazonaws.com

A policy is a JSON document of statements. Each statement has an Effect, a list of Actions, the Resource ARNs it applies to, and optional Conditions. Attach managed policies for reuse; inline policies live and die with one principal.

{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::media/uploads/*"
}]
}

Gotcha: "Version": "2012-10-17" is the policy-language version, not a date to update. Omit it and policy variables such as ${aws:username} are treated as literal strings.

StepResult if it matches
Explicit Deny in any policyDeny, final
SCP or RCP lacks an allowDeny
Resource policy allows (same account)Usually allow
Boundary or session policy lacks an allowDeny
Identity policy allowsAllow
Nothing allowsImplicit deny

AWS gathers every applicable policy and evaluates them together; statement order and policy order do not matter. Within one account, an allow in either the identity policy or the resource policy is enough for most services. Role trust policies and KMS key policies are exceptions: they must allow the principal explicitly.

final = no explicit Deny
AND allowed by SCPs and RCPs
AND (identity policy allows
OR resource policy allows)
AND allowed by boundary
AND allowed by session policy

Gotcha: A Deny cannot be overridden by any Allow, even AdministratorAccess. When an admin is denied, search for a Deny statement before adding more allows.

PolicyAttached toHas Principal?
Identity-basedUser, group or roleNo
Resource-basedBucket, queue, key, functionYes
Trust policyA roleYes

A resource policy names who may act on the resource. Cross-account access needs both sides: the resource policy in account A must allow the principal from B, and the identity policy in B must allow the action on A’s resource.

{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111122223333:role/app"
},
"Action": "sqs:SendMessage",
"Resource":
"arn:aws:sqs:eu-west-1:444455556666:jobs"
}]
}
SettingValue
Max session duration1–12 hours, default 1 hour
DurationSeconds900 s up to the role’s maximum
Role chainingCapped at 1 hour

A role has two policies: the trust policy says who may call sts:AssumeRole, and the permission policies say what the session may do. For cross-account access the caller also needs sts:AssumeRole on the role in its own identity policy.

Terminal window
aws sts assume-role \
--role-arn arn:aws:iam::444455556666:role/deploy \
--role-session-name ci-run-81 \
--duration-seconds 3600
aws sts get-caller-identity # who am I now?

Gotcha: Using one role’s session to assume another role is role chaining, limited to one hour. Asking for a longer --duration-seconds fails even if the target role allows 12 hours.

ComputeTrusted service principal
Lambdalambda.amazonaws.com
EC2 (via instance profile)ec2.amazonaws.com
ECS task roleecs-tasks.amazonaws.com

Your code never holds long-lived keys: the platform assumes the role and the SDK picks up rotating temporary credentials automatically. Give each function or service its own role so one bug cannot reach another workload’s data.

{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}]
}

Warning: Access keys in environment variables or code outlive the person who created them. If something runs on AWS, give it a role.

GuardrailScopeGrants?
Permissions boundaryOne user or roleNever
Service control policy (SCP)Accounts in an organizationNever
Resource control policy (RCP)Resources in member accountsNever
Session policyOne assumed-role sessionNever

A boundary is a managed policy that sets the most a principal can ever have; effective permissions are the intersection of the boundary and the identity policies. Use it to let developers create roles without letting them create a role more powerful than themselves.

{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:*", "dynamodb:*", "logs:*"],
"Resource": "*"
}]
}

Gotcha: Attaching this boundary grants nothing. A role with this boundary and no identity policy can do nothing at all.

Condition keyChecks
aws:PrincipalTag/teamTag on the calling principal
aws:ResourceTag/teamTag on the target resource
aws:SourceArnWhich resource made a service call
aws:PrincipalOrgIDCaller’s organization
aws:SecureTransportRequest used TLS

Conditions narrow a statement to requests whose context matches. Matching principal tags to resource tags is attribute-based access control (ABAC): one policy covers every team, and access follows tags instead of growing lists of ARNs.

{
"Effect": "Allow",
"Action": "dynamodb:*",
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/team":
"${aws:PrincipalTag/team}"
}
}
}

Tip: When a service principal such as sns.amazonaws.com writes to your resource, add an aws:SourceArn or aws:SourceAccount condition. Without it, any account’s topic can use that grant.

Message fragmentMeaning
no identity-based policy allowsImplicit deny: add an allow
explicit deny in an identity-based policyRemove or scope the Deny
explicit deny in a service control policyAn SCP blocks it
no permissions boundary allowsBoundary lacks the action

The AccessDenied message names the principal, action and resource, then the policy type that decided; explicit denials often include that policy’s ARN. Some services return an encoded message instead, which decode-authorization-message turns into JSON. IAM Access Analyzer generates a policy from up to 90 days of CloudTrail activity, validates policy grammar, and reports unused roles, keys and permissions.

Terminal window
aws sts get-caller-identity
aws iam simulate-principal-policy \
--policy-source-arn \
arn:aws:iam::111122223333:role/app \
--action-names s3:GetObject \
--resource-arns arn:aws:s3:::media/a.png
aws sts decode-authorization-message \
--encoded-message "$MSG"

Gotcha: Many denials are the wrong principal, not the wrong policy. Run get-caller-identity first: a stale profile or an unexpected assumed role explains the error faster than reading policies.