37

I'm confused as to what the purpose of AssumeRolePolicyDocument is.
It seems like to create a role all you need is a parent name that you can attach policies to.

It seems like AssumeRolePolicyDocument is that parent name but somehow there's more to it.

What is this doing?

"AssumeRolePolicyDocument": {
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": ["lambda.amazonaws.com"]
            },
            "Action": ["sts:AssumeRole"]
        }
    ]
}

4 Answers 4

16

The purpose of the AssumeRolePolicyDocument is to contain the trust relationship policy that grants an entity permission to assume the role.

In your example it's granting the Lambda service the ability to assume

References

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html

https://docs.aws.amazon.com/cli/latest/reference/iam/create-role.html

4
  • 4
    I guess I'm confused as to why it has to assume a role? Why cant a policy just be assigned to it? Commented Oct 2, 2018 at 23:55
  • @mutant_city, You need to allow Lambda permission to assume a role. Without doing so Lambda wouldn't be able to do anything in your environment. The role has policies assigned to it that give Lambda the privileges it needs to do its work.
    – kenlukas
    Commented Oct 3, 2018 at 0:49
  • 1
    Ok. So you allow the lambda to assume the role that you have attached your policies to...basically? Commented Oct 3, 2018 at 1:58
  • yes, in a nutshell that's it.
    – kenlukas
    Commented Oct 3, 2018 at 12:22
13

For anyone who is scratching their head at the naming convention:

AssumeRolePolicyDocument (in CloudFormation yaml) = Trust Relationships (in AWS Console web GUI)

Policies (in CloudFormation yaml) = Permissions (in AWS Console web GUI)

2
  • 2
    Is a "Trust Policy" as described here: docs.aws.amazon.com/IAM/latest/UserGuide/… the same thing as the JSON file that you pass to the --assume-role-policy-document flag in the aws iam create-role subcommand? My main confusion is because AWS insists on inventing new phrases and then airdropping the word "policy" or "role" in the phrase like: resource-based policy, role policy, JSON policy document, trust relationship policy document, assume-role-policy-document, it always seems like the phrases might be pointing to the same thing but I can't be sure.
    – mbigras
    Commented Apr 8, 2021 at 2:42
  • 1
    @mbigras Yes, I think that is the case. IAM CLI (based on the linked document) expects JSON and the linked document also expects a JSON document.
    – Tony Sepia
    Commented Apr 9, 2021 at 15:02
10

The purpose of assume role policy document is to grants an IAM entity permission to assume a role. It is also known as a "role trust policy".

In other words, for given permissions you set, it allow users from certain AWS account to assume this role and access that account.

It is recommended that you update the role trust policy to restrict access to only authorized users, otherwise any AWS account could assume the role and access that account.

By specifying Principal using Amazon Resource Name (ARN) of the AWS account, IAM user, IAM role, federated user, or assumed-role user, you allow or deny access to assume that role (sts:AssumeRole).

8

I think it's much clearer when considering the user that creates a role isn't necessarily the one attaching it for use somewhere:

  • AssumeRolePolicyDocument is a restriction placed by the user that creates the role - e.g. possibly an admin. It prevents other users from attaching it to any AWS service / user they like. Also, it tells nothing about where it's actually used. It's a protection on the Role-side (treating Role as a resource that should also be protected).

  • OTOH, actually assigning a role to a service / user, is done by users that actually need now some service to have permissions. And they're allowed to do it only if the Role's AssumeRolePolicyDocument allows it.

Granted, when you're the sole user you might not care much about it. It does, though, add more security and documents (forcibly :) ) how the role is intended to be used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.