Lesson 3 of 3 Deployment Strategies and Troubleshooting

Troubleshooting Permissions Issues in Deployments

This lesson explains how deployments run under many identities, and how to diagnose the permissions failures that are among the most common deployment issues.

Learning outcomes

After completing this lesson, you will be able to:

  • Grant iam:PassRole correctly.
  • Resolve service-linked role, service role and KMS issues.
  • Follow a sequence to diagnose permission failures.

iam:PassRole

When a user or service configures a resource to use an IAM role, for example launching an instance with an instance profile, creating a Lambda function with an execution role, or starting an Automation runbook with an assume role, the caller must have iam:PassRole permission on that role. Without it, the call fails with an AccessDenied error that mentions iam:PassRole, even if the caller has full permissions on EC2 or Lambda. Scoping iam:PassRole to specific role ARNs, optionally with the iam:PassedToService condition, prevents privilege escalation by passing an administrator role.

{
  "Effect": "Allow",
  "Action": "iam:PassRole",
  "Resource": "arn:aws:iam::111122223333:role/app-*",
  "Condition": {"StringEquals": {"iam:PassedToService": "ec2.amazonaws.com"}}
}

The following diagram compares the two teams' launches.

Why a launch fails only for one team. Launching an instance with an instance profile passes a role to EC2, so the caller needs iam:PassRole on that role in addition to ec2:RunInstances. Team A's policy allows PassRole on the role and succeeds; Team B has full EC2 permissions but no PassRole and receives AccessDenied mentioning iam:PassRole.
The role name is illustrative.

Service-linked roles, service roles and KMS

Service-linked roles, such as AWSServiceRoleForAutoScaling, are created automatically and let a service act on your behalf. If an Auto Scaling group launches instances with EBS volumes encrypted by a customer managed key, the key policy must allow that service-linked role to use the key (or a grant must exist); otherwise instances terminate immediately. CloudFormation service roles must have permission for every resource in the template. SCPs can deny actions regardless of IAM permissions, and the AccessDenied message now often states that an SCP was responsible. Permissions boundaries on the deploying role limit what it can do even if its policies allow more.

Sort into groups

Service-linked or service role?

Exam skills 4.1.1 · 3.1.3

Decide which kind of role each statement describes.

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

Diagnosing permission failures

The following sequence identifies the cause of a permission-related deployment failure.

  1. Read the exact error

    The action, resource and, increasingly, the policy type that denied it.

  2. Find the call in CloudTrail

    Look for errorCode AccessDenied or UnauthorizedOperation to see which principal made it, which may be a service role rather than the user.

  3. Decode EC2 messages

    Decode encoded authorisation messages with aws sts decode-authorization-message.

  4. Simulate

    Test the principal's policies with the IAM policy simulator, including SCPs and boundaries.

  5. Check KMS

    For encrypted resources, check the KMS key policy and grants for the calling or service-linked role.

Put in order

Diagnosing an access denied error

Exam skills 3.1.3 · 4.1.2

Put the steps for diagnosing a deployment's access denied error in order.

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

Launch fails only for one team

Developers can create EC2 instances, but launching an instance with the app-reports instance profile fails with You are not authorized to perform this operation and an encoded message. Decoding it shows a missing iam:PassRole on arn:aws:iam::111122223333:role/app-reports. The developers' policy allows PassRole only for roles matching app-web-*. The administrator adds the reports role to the allowed list with the iam:PassedToService condition for EC2.

Check yourself

Which condition key limits the services a role can be passed to?

Show answer

iam:PassedToService.

Exam Tips

Remember for the exam

  • Attaching a role to a resource requires iam:PassRole on that role.
  • Scope PassRole by role ARN and iam:PassedToService.
  • Encrypted launches need the KMS key to allow the service-linked role.
  • CloudTrail shows which principal (user or service role) was denied.
  • SCPs and permissions boundaries can deny even when IAM policies allow.