Lesson 4 of 4 IAM Access Analyzer and Authorization Tools

Troubleshooting Access Denied Errors Methodically

This lesson sets out a methodical approach that finds the policy blocking a request quickly, since authorisation failures are common in practice and in exam questions.

Learning outcomes

After completing this lesson, you will be able to:

  • Interpret the reason given in an AccessDenied message.
  • Describe the order in which the possible causes are checked.
  • Recognise encryption and cross-account traps.
  • Use the policy simulator and decode encoded authorisation messages.

Read the error first

Many AccessDenied messages give the reason: "explicit deny in a service control policy", "no identity-based policy allows", "explicit deny in a resource-based policy", "no session policy allows". CloudTrail shows the call, the principal (with session) and errorCode.

Check in order

An unexpected access denial can be diagnosed by checking a sequence of possible causes. The checks should be made in the following order.

  1. Explicit denies anywhere: identity, resource, SCP, RCP, boundary, session and VPC endpoint policies.
  2. An allow exists for the exact action and ARN: watch typos, wrong Region or account, bucket vs object ARNs.
  3. Conditions: Region, tags, MFA, source IP or endpoint, encryption headers, aws:SecureTransport.

The following diagram follows the decoding of an EC2 UnauthorizedOperation error to its fix.

Decoding an EC2 UnauthorizedOperation. sts decode-authorization-message shows an explicit deny from the SCP RequireIMDSv2AtLaunch with ec2:MetadataHttpTokens = optional in the request context. The fix is HttpTokens = required in the launch template; no permission added to the role can override an SCP's explicit deny.
The scenario is illustrative.
Troubleshooting

Finding the blocking policy

Exam skills 4.2.4

Find the cause of each access denial.

Log in to try this activity Interactive activities are free with an account.

Encryption and cross-account traps

Encryption and cross-account access introduce additional requirements that are commonly overlooked

  • SSE-KMS objects and encrypted volumes also need kms:Decrypt / kms:GenerateDataKey in both the key policy and IAM; a missing KMS permission often looks like an S3 denial.
  • Across accounts, both sides must allow; for roles, the trust policy must allow the caller and the caller needs sts:AssumeRole.
True or false

Hidden causes of denials

Exam skills 4.2.4

Check the encryption and cross-account traps behind access denials.

Log in to try this activity Interactive activities are free with an account.

Tools

Three IAM tools help diagnose Access Denied errors. The IAM policy simulator tests whether a principal's identity policies, permissions boundary and the effect of SCPs allow particular actions on particular resources, and shows which statement allowed or denied each one. Access Analyzer policy validation finds mistakes in a policy, such as an invalid action or a condition key that does not apply. Last accessed data shows which services and actions a principal has actually used, which helps decide what is genuinely needed when removing permissions. The error message itself often names the type of policy that denied the request. The following table summarises the tools.

ToolUse
IAM policy simulatorTest identity policies, boundaries and SCP effect against actions and resources
Access Analyzer policy validationFind mistakes
Last accessed dataWhat is actually used
Match the pairs

Tools for access problems

Exam skills 4.2.4

Match each tool with what it helps you find.

Log in to try this activity Interactive activities are free with an account.
Worked example

Decoding an EC2 authorisation failure

An automation role fails to launch instances with UnauthorizedOperation and an encoded message. Decoding it (the caller needs sts:DecodeAuthorizationMessage) reveals which check failed:

aws sts decode-authorization-message --encoded-message "$ENCODED" \
  --query DecodedMessage --output text | jq '{allowed, explicitDeny, matchedStatements: .matchedStatements.items, context: .context.conditions}'

The output shows explicitDeny: true with a matched statement from an SCP named RequireIMDSv2AtLaunch, and the request context shows ec2:MetadataHttpTokens = optional. The fix is in the launch template (set HttpTokens=required), not in the role's IAM policy: adding permissions to the role could never override an explicit deny in an SCP.

Check yourself

How can policies be tested before they are deployed?

Show answer

With the IAM policy simulator.

Exam Tips

Remember for the exam

  • When access to an encrypted S3 object is denied, check the KMS key policy and kms:Decrypt.
  • When IAM allows an action but it is still denied, look for an SCP, RCP, boundary, endpoint policy or explicit deny.
  • To test policies before deploying them, use the IAM policy simulator.
  • When the error says "explicit deny in a service control policy", fix the SCP, not the role.
  • Across accounts, check both the caller's policy and the resource or trust policy.