Lesson 4 of 4 AWS IAM and Access Troubleshooting

Troubleshooting and Auditing Access

This lesson explains how CloudTrail, IAM Access Analyzer and the IAM policy simulator, the tools that the exam guide names for troubleshooting and auditing access, each answer a different question.

Learning outcomes

After completing this lesson, you will be able to:

  • Find why a request was denied.
  • Test policies with the IAM policy simulator.
  • Use IAM Access Analyzer findings.
  • Audit credentials with credential reports and last accessed information.

Finding why a request was denied

Error messages are the first clue. Many AccessDenied messages now include the principal, the action, the resource and the type of policy that caused the denial, for example "with an explicit deny in a service control policy" or "because no identity-based policy allows the action". EC2 returns an encoded message that aws sts decode-authorization-message expands into the full context (the caller needs sts:DecodeAuthorizationMessage). CloudTrail records the failed call with its errorCode, principal and source, which shows whether the denied caller was the user or a role acting on their behalf.

aws sts decode-authorization-message --encoded-message <message> \
  --query DecodedMessage --output text | jq '.context.action, .matchedStatements, .explicitDeny'

The following diagram shows the diagnostic tools in the order they are usually used.

Finding why a request was denied. The AccessDenied message often names the principal, action, resource and the policy type that denied it. EC2's encoded message is expanded with sts decode-authorization-message. CloudTrail records the failed call with its error code, and the IAM policy simulator tests the policies that apply.
Starting from the message usually narrows the problem to one policy before any tool is needed.
Sort into groups

Read the error message

Exam skills 4.1.2

Decide which policy to change from the denial message.

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

IAM policy simulator

The IAM policy simulator evaluates the policies attached to a user, group or role, plus optional resource policies, permissions boundaries and SCPs, against chosen actions, resources and context keys (such as a source IP or MFA state), and shows allowed, explicitDeny or implicitDeny with the matching statement. It makes no real API calls, so it is safe for testing a new policy before attaching it or answering "can this role do X?". It is available in the console and through simulate-principal-policy and simulate-custom-policy.

IAM Access Analyzer

IAM Access Analyzer provides several analyses. External access findings list resources (S3 buckets, IAM roles, KMS keys, Lambda functions, SQS queues, Secrets Manager secrets, SNS topics, EBS and RDS snapshots, ECR repositories, EFS file systems and others) that are shared with principals outside the zone of trust, the account or organisation. Internal access findings show which principals inside the organisation can reach critical resources. Unused access findings report unused roles, access keys, passwords and permissions. Policy validation checks policies for errors, security warnings and best-practice suggestions, custom policy checks verify that a policy grants no new or public access, and policy generation creates a least-privilege policy from a role's CloudTrail activity.

Match the pairs

Which access tool?

Exam skills 4.1.2

Match each audit question with the tool that answers it.

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

Credential reports and last accessed information

The credential report is a CSV listing every IAM user with password and access key status, last use and rotation dates, and MFA status, useful for audits. Last accessed information (access advisor) shows when a user, role, group or policy last used each service, and for some services each action, and in Organizations shows service use per OU or account to help write SCPs. The following table summarises which tool answers which question.

QuestionTool
Why was this call denied?Error message, decode-authorization-message, CloudTrail
Would this policy allow this action?IAM policy simulator
Which resources are shared outside the organisation?Access Analyzer external access
Which permissions and credentials are unused?Access Analyzer unused access, last accessed information
Which users lack MFA or have old keys?Credential report
Is this new policy valid and safe?Access Analyzer policy validation and custom checks
Worked example

A Lambda function that cannot read a bucket

A Lambda function in account A gets AccessDenied reading objects from a bucket in account B. CloudTrail in account B shows the call from the function's assumed role with errorCode AccessDenied. The policy simulator confirms the execution role allows s3:GetObject, so the denial is on the resource side. The bucket policy allows the role, but the objects are encrypted with a customer managed KMS key in account B whose key policy does not include account A. Adding the role to the key policy, and kms:Decrypt to the execution role, resolves it.

Check yourself

Which tool tests policies without making real calls?

Show answer

The IAM policy simulator.

Exam Tips

Remember for the exam

  • AccessDenied messages often name the policy type that denied the call.
  • Decode EC2 encoded authorisation messages with sts decode-authorization-message.
  • The policy simulator tests policies without making real calls.
  • Access Analyzer finds external sharing, unused access and policy problems.
  • Cross-account S3 access to KMS-encrypted objects also needs the key policy.