×


Not authorized to perform iam:PassRole error - Tips to fix it ?

IAM roles can be used to delegate access to your AWS resources across different AWS accounts that you own. For example, you can share resources in one account with users in a different account. This is made possible by establishing trust relationships between the trusting account and your other AWS trusted accounts.

Basically, To configure many AWS services, you must pass an IAM role to the service. This allows the service to later assume the role and perform actions on your behalf.

Sometimes, user cannot perform this function due to not having enough permission to do so.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related AWS queries.

In this context, we shall look into methods to resolve AWS AccessDenied error.


Nature of Not authorized to perform iam:PassRole error

When this issue happens, you will see the below error message:

An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam:::user is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::user:role/role

When you create a service-linked role, you must have permission to pass that role to the service.

Some services automatically create a service-linked role in your account when you perform an action in that service.

For example, Amazon EC2 Auto Scaling creates the AWSServiceRoleForAutoScaling service-linked role for you the first time that you create an Auto Scaling group.

If you try to create an Auto Scaling group without the PassRole permission, you receive the above error.

To fix this error, the administrator need to add the iam:PassRole permission for user.


Ways to resolve "not authorized to perform iam:PassRole" error ?

In order to pass a role to an AWS service, a user must have permissions to pass the role to the service.

To allow a user to pass a role to an AWS service, you must grant the PassRole permission to the user's IAM user, role, or group.

A user can pass a role ARN as a parameter in any API operation that uses the role to assign permissions to the service.

The service then checks whether that user has the iam:PassRole permission.

In order to grant a user the ability to pass any of an approved set of roles to the Amazon EC2 service upon launching an instance.

You need three elements:


1. Firstly, an IAM permissions policy attached to the role that determines what the role can do.

Scope permissions to only the actions that the role must perform, and to only the resources that the role needs for those actions.

You can use AWS managed or customer-created IAM permissions policy:

{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": [ "A list of the permissions the role is allowed to use" ], "Re


2. A trust policy for the role that allows the service to assume the role.

For example, you could attach the following trust policy to the role with the UpdateAssumeRolePolicy action.

This trust policy allows Amazon EC2 to use the role and the permissions attached to the role:

{
"Version": "2012-10-17",
"Statement": {
"Sid": "TrustPolicyStatementThatAllowsEC2ServiceToAssumeTheAttachedRole",
"Effect": "Allow",
"Principal": { "Service": "ec2.amazonaws.com" },
"Action": "sts:AssumeRole"
}
}


3. An IAM permissions policy attached to the IAM user that allows the user to pass only those roles that are approved.

iam:PassRole usually is accompanied by iam:GetRole so that the user can get the details of the role to be passed.

Please find the example below:

{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"iam:GetRole",
"iam:PassRole"
],
"Resource": "arn:aws:iam::<account-id>:role/EC2-roles-for-XYZ-*" }]

Now the user can start an Amazon EC2 instance with an assigned role.

The permissions policies attached to the role determine what the instance can do.


[Need help to fix this AWS error? We'd be happy to assist. ]


Conclusion

This article covers ways to resolve AWS AccessDeniedException – I Can't Assume a Role error which happens when you try to create an Auto Scaling group without the PassRole permission. In fact, To pass a role (and its permissions) to an AWS service, a user must have permissions to pass the role to the service. This helps administrators ensure that only approved users can configure a service with a role that grants permissions. To allow a user to pass a role to an AWS service, you must grant the PassRole permission to the user's IAM user, role, or group.


Cause of AWS AccessDeniedException – I Can't Assume a Role error:

There are two possible causes for this AccessDenied error: the user in your development account doesn't have permission to call sts:AssumeRole, or the trust relationship in the production account is not configured correctly.


To create a role for Amazon RDS enhanced monitoring:

  • Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
  • Choose Roles, and then choose Create role.
  • Choose the AWS Service role type, and then choose the Amazon RDS Role for Enhanced Monitoring service. Then choose Next: Permissions.
  • Choose the AmazonRDSEnhancedMonitoringRole, permissions policy.
  • Choose Next: Tags.
  • (Optional) Add metadata to the user by attaching tags as key-value pairs. For more information about using tags in IAM.
  • Choose Next: Review.
  • For Role name, type a role name that helps you identify the purpose of this role. Role names must be unique within your AWS account. They are not distinguished by case. For example, you cannot create roles named both PRODROLE and prodrole. Because various entities might reference the role, you cannot edit the name of the role after it has been created.
  • (Optional) For Role description, type a description for the new role.
  • Review the role and then choose Create role.