Cloud & Infrastructure Bug Report

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.

Daniel Tran Daniel Tran @fun_dev · November 26, 2026 · 8 min read · 125 Views
626-aws-iam-accessdenied-explicit-deny-scp-boundary

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-policies and list-role-policies showed 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-policy returned PolicyNotFoundException).

  • 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:

  1. 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.

  2. Organizations policies. Service control policies (for principals) and resource control policies (for resources) must allow the action. They never grant on their own.

  3. Resource-based policy. It can grant access within the same account.

  4. Identity-based policy. Must allow the action (unless a resource policy already did for the principal).

  5. 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.

  6. Session policy. If the session was created with one (AssumeRole with Policy or PolicyArns), 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

because no identity-based policy allows the ... action

Identity policy missing the allow

because no permissions boundary allows the ... action

Boundary missing the allow

with an explicit deny in a service control policy

SCP deny

because no service control policy allows the ... action

SCP allow list lacks the action

with an explicit deny in an identity-based policy

Deny statement on the role

because no session policy allows the ... action

Session policy narrower than the role

with an explicit deny in a resource-based policy

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 order-export-worker

SDK

boto3 1.35 (Python 3.12)

IaC

Terraform 1.9, AWS provider 5.x

Guardrails

AWS Organizations SCPs, permissions boundary workload-boundary on all workload roles

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-policy for every workload role against the resource ARNs declared in its Terraform module, and fails the plan if any expected action is implicitDeny.

  • The platform module rejects table names that do not match the boundary prefix with a Terraform validation block, 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

Add a label

#aws #dynamodb #iam #cloudtrail #permissions-boundary
Written by
Daniel Tran @fun_dev

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.

Advertisement

Comments

0

No comments yet. Be the first to comment!

Sign In to post a comment.