Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can IAM user assume a role, if the user is not described in the Trust policy of the role?

Can a role be assumed if it does not have a Trust policy? If a given IAM user has an attached identity based policy saying that he/she can call sts:AssumeRole for a given role (inside the same account), but the user is not described in the Trust policy of this role, will he/she be able to assume the role?

Usually only the resource based policy or the identity based policy should be enough to give rights for the user, but is it different for the roles?

Thanks

like image 296
Jaxx Avatar asked Feb 28 '21 23:02

Jaxx


People also ask

Who can not assume IAM roles?

If your account number is not listed in the Principal element of the role's trust policy, then you cannot assume the role. It does not matter what permissions are granted to you in access policies.

Can anyone assume an IAM role?

Create the IAM role and attach the policy Because this IAM role is assumed by an IAM user, you must specify a principal that allows IAM users to assume that role. For example, a principal similar to arn:aws:iam::123456789012:root allows all IAM identities of the account to assume that role.

Can AWS user Assume role?

You can assume a role by calling an AWS CLI or API operation or by using a custom URL. The method that you use determines who can assume the role and how long the role session can last. ¹ Using the credentials for one role to assume a different role is called role chaining.

What entities can assume IAM roles?

A role can be assumed by a human user or a machine principal, such as an Amazon Elastic Computer Cloud (Amazon EC2) instance or an AWS Lambda function.


1 Answers

will he/she be able to assume the role?

Yes, of course she/he will be able to do it, as long the trust policy allows the account to assume the role. For example, a role has to have the trust policy of:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "<account-number>"
      },
      "Action": "sts:AssumeRole",
      "Condition": {}
    }
  ]
}

This way, your IAM user does not need to be explicitly listed in the trust policy, but trust policy is required and at least you should specify the account which can assume it. But the drawback is that any IAM user or role from the <account-number> account that has sts:AssumeRole permissions can assume the role.

it does not have a Trust policy?

Trust policy is required, so you can't have a role without such such a policy.

Update

Lets assume you have a role with a trust policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::xxxxxx:user/UserA"
      },
      "Action": "sts:AssumeRole",
      "Condition": {}
    }
  ]
}

The role can be assumed only by userA. UserB will not be able to assume this policy, regardless of his permissions.

like image 137
Marcin Avatar answered Sep 28 '22 19:09

Marcin