Certopolis

AWS Certified Solutions Architect – Associate

IAM policy evaluation: explicit deny, SCPs and boundaries

AWS denies a request unless a policy allows it, and an explicit deny in any applicable policy overrides every allow. Within one account, identity-based and resource-based policies add together. SCPs, permissions boundaries and session policies grant nothing: they set a ceiling, so the action must also be allowed by each of them.

Identity-based and resource-based policies

In the same account, the permissions are the union of the identity-based policy on the user or role and the resource-based policy on the resource, such as a bucket policy. If either one allows the action, AWS allows it. An explicit deny in either one overrides the allow.

Across accounts, the rule changes. AWS evaluates the request in both accounts. The caller's identity-based policy in its own account must allow the request, and the resource-based policy in the resource's account must allow the caller. The request is allowed only if both evaluations return Allow.

Guardrails that grant nothing

A service control policy (SCP) never grants permissions. It sets the maximum for IAM users and roles in member accounts, including each member account's root user. SCPs need an organization with all features enabled. A permission must be allowed at every level from the root through each OU down to the account. Remove FullAWSAccess without putting an allow in its place and every action in the affected accounts fails.

SCPs do not affect users or roles in the management account, and they do not affect service-linked roles. Member accounts that are delegated administrators are still affected.

A permissions boundary is a managed policy that sets the most an identity-based policy can grant a user or role. The effective permissions are the intersection of the two. If a boundary allows only S3, CloudWatch and EC2, an attached policy that allows iam:CreateUser still fails. When an SCP, a boundary and an identity-based policy all apply, all three must allow the action.

Where resource policies bypass a boundary

In the same account, a resource-based policy that grants access to an IAM user ARN is not limited by an implicit deny in that user's identity-based policy or permissions boundary. A user whose boundary allows only S3 can still read a Secrets Manager secret whose resource policy names the user.

A resource-based policy that grants access to an IAM role ARN is limited by an implicit deny in the role's permissions boundary or session policy. One that grants access to a role session ARN in the same account is not.

This only covers implicit denies. If the boundary explicitly denies the logs bucket, a bucket policy that allows the user still does not get them in.

Where the exam catches people

  • Believing an SCP grants permissions: it only limits them, and users and roles still need IAM policies that allow the action.
  • Believing an SCP attached at the root restricts the management account: SCPs do not affect users or roles in the management account.
  • Believing an extra Allow cancels a Deny: an explicit deny in any applicable policy overrides every allow, so the deny itself has to change.
  • Believing a permissions boundary gives access: it sets the maximum and grants nothing on its own.
  • Believing a bucket policy alone gives another account access: the caller's identity-based policy in its own account must also allow the request.

Written from Amazon Web Services's documentation

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. An application in a member account of an organization must write to an Amazon DynamoDB table in the same account. The IAM role it uses has an identity-based policy that allows dynamodb:PutItem on the table, and the table has no resource-based policy. The writes are denied. A service control policy on the account's organizational unit denies dynamodb:PutItem. Which approach will meet these requirements?

    Right. In the game that’s Renown for your Design Secure Architectures building.

    Not that one: C is right. In the game your Design Secure Architectures building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Policy evaluation begins with the deny step: the enforcement code "evaluates all policies within the account that apply to the request", including SCPs, resource-based policies, identity-based policies, boundaries and session policies, and "if the enforcement code finds even one explicit deny that applies, the enforcement code returns a final decision of Deny". Everything the other options add is evaluated after that step. It is true that an SCP must also contain an applicable Allow - "If the enforcement code does not find any applicable Allow statements in the SCPs, the enforcement code returns a final decision of Deny" - and that is what makes A the tempting repair, but an Allow beside a Deny for the same action leaves the Deny in force. Removing it, or narrowing it with a condition so that it no longer matches this role, is the only change that reaches the request.

    Written from docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic_policy-eval-denyallow.html

  2. Developers create IAM roles for AWS Lambda functions in a member account of an organization. No principal in the account, including the root user, may use any service outside an approved list. The roles that developers create must never be able to use more than Amazon S3 and Amazon DynamoDB, even if a developer attaches a broader policy to a role. Which combination of steps should a solutions architect take to meet these requirements? (Select TWO.)

    Right. In the game that’s Renown for your Design Secure Architectures building.

    Not that one: D,E is right. In the game your Design Secure Architectures building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    (https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html). A permissions boundary caps a role whatever its policies grant: "An entity's permissions boundary allows it to perform only the actions that are allowed by both its identity-based policies and its permissions boundaries." With both in place, "the request is allowed only if all three policy types allow it", so a broader policy attached by a developer cannot lift a role past Amazon S3 and Amazon DynamoDB.

    Written from docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html

  3. An IAM user in a company's account has a permissions boundary that allows only Amazon S3 and Amazon CloudWatch actions. The security team will not change the boundary. The user must be able to read one AWS Secrets Manager secret in the same account. Which solution meets these requirements?

    Right. In the game that’s Renown for your Design Secure Architectures building.

    Not that one: C is right. In the game your Design Secure Architectures building would lose a little Renown, and this question would come back later.