AWS AccessDenied although the IAM policy allows it: permissions boundary and explicit deny
A new DynamoDB table returned AccessDeniedException even though the role's policy allowed dynamodb:PutItem on it. The role carried a permissions boundary scoped to old table names. How we read the error reason, traced the evaluation chain and fixed it.
On a Tuesday afternoon the new order-export worker went live in staging and every write failed. The role's identity policy clearly allowed dynamodb:PutItem on the new table, the Terraform plan showed it, and the engineer who wrote it could point at the exact line. The worker log said:
botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the
PutItem operation: User: arn:aws:sts::111122223333:assumed-role/order-export-worker/i-0a1b2c3d4e
is not authorized to perform: dynamodb:PutItem on resource:
arn:aws:dynamodb:eu-west-1:111122223333:table/orders-export-v2 because no permissions boundary
allows the dynamodb:PutItem action
The first two people who looked at it read only up to "is not authorized" and started editing the identity policy. The useful part was at the end of the line.
Reproducing it
From a shell with the same role (we used an EC2 instance profile in staging):
aws sts get-caller-identity
aws dynamodb put-item \
--table-name orders-export-v2 \
--item '{"pk":{"S":"test#1"},"sk":{"S":"v0"}}'
The call failed every time with the same message. Writing to the older app-orders table with the same role worked.
What we ruled out
Wrong table or region. The ARN in the error matched the table, and the region matched the endpoint. A wrong region gives
ResourceNotFoundException, not an access error.Policy not attached yet.
aws iam list-attached-role-policiesandlist-role-policiesshowed the new inline policy. IAM changes are eventually consistent, but we were well past a few seconds.Resource policy on the table. DynamoDB supports resource-based policies since 2024. The table had none (
aws dynamodb get-resource-policyreturnedPolicyNotFoundException).Service control policy. An SCP denial says so in the message ("with an explicit deny in a service control policy"). Ours did not, but we still listed the SCPs on the account to be sure.
Root cause
The platform team creates every workload role with a permissions boundary called workload-boundary. A boundary does not grant anything; it sets the maximum permissions an identity-based policy can give. Ours allowed DynamoDB actions only on tables whose name starts with app-. The new table was named orders-export-v2. The identity policy said yes, the boundary said nothing, and in IAM "nothing" means no. The error message told us exactly that: "because no permissions boundary allows".
What is happening under the hood
For a request inside a single account, AWS evaluates a chain of policy types. In simplified order:
Explicit deny anywhere. If any applicable policy (SCP, RCP, resource policy, identity policy, boundary, session policy) has a matching
Deny, the request is denied. Nothing can override it.Organizations policies. Service control policies (for principals) and resource control policies (for resources) must allow the action. They never grant on their own.
Resource-based policy. It can grant access within the same account.
Identity-based policy. Must allow the action (unless a resource policy already did for the principal).
Permissions boundary. If one is attached, it must also allow the action. The effective permission is the intersection of the identity policy and the boundary.
Session policy. If the session was created with one (
AssumeRolewithPolicyorPolicyArns), it must allow the action too.
So an Allow in the identity policy is necessary but not sufficient. Every gate that applies has to agree, and any single Deny wins.
Since 2021 AWS includes the reason in many access-denied messages for requests within the same account or organisation. The reason phrases map directly to the gates:
Message ending | Gate that stopped the request |
|---|---|
| Identity policy missing the allow |
| Boundary missing the allow |
| SCP deny |
| SCP allow list lacks the action |
| Deny statement on the role |
| Session policy narrower than the role |
| Resource policy deny |
Cross-account requests usually get a shorter message without the reason, to avoid leaking policy details to the other account.
Environment
Component | Version / value |
|---|---|
Service | Amazon DynamoDB, eu-west-1 |
Caller | EC2 instance profile role |
SDK | boto3 1.35 (Python 3.12) |
IaC | Terraform 1.9, AWS provider 5.x |
Guardrails | AWS Organizations SCPs, permissions boundary |
Minimal reproduction
Identity policy attached to the role:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["dynamodb:PutItem", "dynamodb:GetItem", "dynamodb:Query"],
"Resource": "arn:aws:dynamodb:eu-west-1:111122223333:table/orders-export-v2"
}]
}
Boundary attached to the same role:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "dynamodb:*",
"Resource": "arn:aws:dynamodb:*:111122223333:table/app-*"
}]
}
The intersection of the two is empty for orders-export-v2, so the request is denied.
Who is affected
Any account that uses permissions boundaries for delegated role creation, which is the pattern AWS recommends when developers may create their own roles. Teams hit this when a new resource breaks a naming convention the boundary relies on, or when a new service is used that the boundary never listed. It also bites when a team copies a role definition from another account that has a stricter boundary.
The fix
We had two choices: rename the table or widen the boundary. The naming convention exists so the boundary can stay short, so we renamed the table to app-orders-export and recreated it (it was still empty in staging).
resource "aws_dynamodb_table" "orders_export" {
- name = "orders-export-v2"
+ name = "app-orders-export"
billing_mode = "PAY_PER_REQUEST"
hash_key = "pk"
range_key = "sk"
}
The identity policy referenced the table by its Terraform attribute, so it followed the rename:
resource "aws_iam_role_policy" "orders_export_rw" {
role = aws_iam_role.order_export_worker.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = ["dynamodb:PutItem", "dynamodb:GetItem", "dynamodb:Query"]
Resource = aws_dynamodb_table.orders_export.arn
}]
})
}
When renaming is not possible (production data, shared tables), the boundary owner adds the ARN pattern instead. Keep that change in the platform repository with its own review, because the boundary is a security control. Never remove the boundary from a role to "unblock" it: the platform's guardrail that stops developers from escalating their own permissions depends on it.
Alternatives and trade-offs
Tag-based boundary. Instead of name prefixes, allow actions on resources tagged with the team's tag (
aws:ResourceTag/team). Not every action supports resource tag conditions, so check the service authorisation reference first.Per-team boundaries. More precise, but more policies to maintain.
Removing the boundary. Fast and wrong. It silently re-enables the privilege-escalation path the boundary was blocking.
How to test the fix
Run the IAM policy simulator against the role. It evaluates the identity policies together with the permissions boundary, so it reproduces the denial without touching the table:
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::111122223333:role/order-export-worker \
--action-names dynamodb:PutItem \
--resource-arns arn:aws:dynamodb:eu-west-1:111122223333:table/app-orders-export \
--query 'EvaluationResults[].{action:EvalActionName,decision:EvalDecision,boundary:PermissionsBoundaryDecisionDetail}'
Before the rename, the same command against orders-export-v2 returned implicitDeny with the boundary detail AllowedByPermissionsBoundary: false. After the rename it returned allowed. Then repeat the put-item call from the instance.
Confirming in production
PutItem is a CloudTrail data event, so it is only recorded when the trail logs DynamoDB data events. Our staging trail does, so we queried the Athena table over the trail for access errors on the role:
SELECT eventTime, eventName, errorCode, errorMessage
FROM cloudtrail_logs
WHERE userIdentity.sessionContext.sessionIssuer.userName = 'order-export-worker'
AND errorCode IN ('AccessDenied', 'AccessDeniedException')
AND eventTime > '2027-01-26T00:00:00Z'
ORDER BY eventTime DESC
LIMIT 50;
After the deploy the query returned no rows, and the worker's own export_write_failed counter stayed at zero for a full export cycle.
Regression guard
A CI step runs
simulate-principal-policyfor every workload role against the resource ARNs declared in its Terraform module, and fails the plan if any expected action isimplicitDeny.The platform module rejects table names that do not match the boundary prefix with a Terraform
validationblock, so the error shows at plan time with a clear message.
Security implications
The bug made access stricter, not looser, so nothing was exposed. The risk is in the response: under time pressure, teams remove boundaries or attach AdministratorAccess to debug. That creates a lasting hole. The boundary stayed, and changes to it go through the platform team.
Prevention checklist
Read the whole access-denied message; the reason phrase names the gate.
Document naming or tag conventions that boundaries depend on, next to the module that creates resources.
Simulate role permissions in CI for the actions each service needs.
Keep boundary changes in a separate, reviewed repository.
Use IAM Access Analyzer policy validation for new policies before they merge.
References
AWS: Policy evaluation logic — https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic.html
AWS: Permissions boundaries for IAM entities — https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html
AWS: Troubleshoot access denied error messages — https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_access-denied.html
AWS CLI: simulate-principal-policy — https://docs.aws.amazon.com/cli/latest/reference/iam/simulate-principal-policy.html
AWS: Service authorization reference — https://docs.aws.amazon.com/service-authorization/latest/reference/reference.html
Add a label
Embed this post
<iframe src="https://hibug.me/aws-iam-accessdenied-explicit-deny-scp-boundary" width="700" height="420" frameborder="0" loading="lazy"></iframe>
I have spent most of my career on the side of software that pages people at night: payment integrations, web platforms with real traffic, CI/CD pipelines, Kubernetes clusters and the databases underneath them. Somewhere along the way I started keeping a notebook of every bug that cost more than an hour — the exact error, what we ruled out, the real root cause and how we proved the fix. Hibug is where those notes live. Every post follows the same path: Investigate, Explain, Fix, Verify — with the environment spelled out, the fix tested, and the security angle checked.
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.