DynamoDB resource-based policy: wildcard Principal with Condition keys – precedence uncertainty
0 reputation · 06 Nov 2021, 09:24 UTC
0 reputation · 06 Nov 2021, 09:24 UTC
In DynamoDB, resource-based policies allow direct table permissions. A common pattern is to set Principal: "*" and then constrain access with a Condition such as aws:PrincipalOrgID. AWS evaluation states that an explicit Denys in any policy overrides an Allow. However, when a resource-based policy uses a wildcard Principal with a Condition that restricts to a specific organization, and an identity-based policy grants broader access, the effective decision is unclear.
It is not documented whether the Condition on a wildcard Principal is evaluated before the statement is considered part of the policy or whether the statement is treated as a blanket allow that can be overridden by a Deny elsewhere. The interaction between resource-based Deny statements and identity-based Allow statements has been observed to vary across services, and DynamoDB’s current documentation leaves the precedence rules ambiguous.
\nPrincipal: "*" with a Condition restricting to aws:PrincipalOrgID, does the Condition effectively limit public access, or is the statement still treated as a global allow?Deny in a DynamoDB resource-based policy always override an Allow in an identity-based policy, even when the resource-based statement uses a wildcard Principal?1. Does a Principal: "*" with an aws:PrincipalOrgID condition actually limit access?
Yes. The statement is treated as a conditional Allow. It is only applied when the condition evaluates to true. If the calling principal’s organization ID does not match the value in the Condition block, the statement is ignored and does not grant a blanket permission.
2. Does an explicit Deny in a DynamoDB resource policy always override an Allow in an identity‑based policy, even with a wildcard principal?
Yes. AWS follows a global “deny‑overrides‑allow” rule. An explicit Deny in any policy (resource‑ or identity‑based) takes precedence over all Allow statements, regardless of the principal or condition used.
3. Recommended pattern to guard against accidental public exposure
Principal: "*" only when you also provide a condition that evaluates to true for the intended principals.Deny that blocks all principals whose aws:PrincipalOrgID does not match the target organization. Example:{
"Sid": "DenyNonOrg",
"Effect": "Deny",
"Principal": "*",
"Action": "dynamodb:*",
"Resource": "arn:aws:dynamodb:region:account-id:table/TableName",
"Condition": {
"StringNotEquals": {
"aws:PrincipalOrgID": "o-xxxxxxxxxx"
}
}
}Allow statements could still expose the table.Principal: "*" and a Condition on aws:PrincipalOrgID.dynamodb:GetItem on the table. The simulator should return AccessDenied.Deny statement that blocks all principals not in the target org. Re‑run the simulation; the result remains denied, confirming the deny overrides any allow.Condition block from the allow statement and repeat the simulation; the request from account B will now succeed, illustrating the importance of the condition.Condition on a wildcard principal is evaluated as part of the statement; it does not create a global allow.Deny statements always win over Allow statements in any policy.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.