Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IAM: Cannot create Principal of ARN role in trust relationship #26482

Closed
malatep opened this issue Jul 24, 2023 · 2 comments
Closed

IAM: Cannot create Principal of ARN role in trust relationship #26482

malatep opened this issue Jul 24, 2023 · 2 comments
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@malatep
Copy link

malatep commented Jul 24, 2023

Describe the bug

I would like to create a trust relationship with a specific role in a different account and not use the account principal.

The final result I want is this trust relationship (as in this example)

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::111111111111:role/my-lambda-execution-role"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

This is what I am doing

...

        new Role(this,'my-role',{
                assumedBy: new ArnPrincipal(`arn:aws:iam::111111111111:role/my-lambda-execution-role`)

...

This fails with the following error

Invalid principal in policy: "AWS":"arn:aws:iam::111111111111:role/my-lambda-execution-role" (Service: AmazonIdentityManagement; Status Code: 400; Error Code: MalformedPolicyDocument; Request ID: 3ee72085-639
7-4110-808a-be9bf5b1ae73; Proxy: null)

Expected Behavior

I would expect to see the trust relationship policy with the IAM role as Principal.

This should work as the CDK docs say:

You can specify AWS accounts, IAM users, Federated SAML users, IAM roles, and specific assumed-role sessions. You cannot specify IAM groups or instance profiles as principals


Note that if I use the account Principal ARN like this it works:

...

        new Role(this,'my-role',{
                assumedBy: new ArnPrincipal(`arn:aws:iam::111111111111:root`)

...

But I don't want to give permission to the entire account and want to restrict to the individual role.

Current Behavior

Invalid principal in policy: "AWS":"arn:aws:iam::111111111111:role/my-lambda-execution-role" (Service: AmazonIdentityManagement; Status Code: 400; Error Code: MalformedPolicyDocument; Request ID: 3ee72085-639
7-4110-808a-be9bf5b1ae73; Proxy: null)

Reproduction Steps

Deploy this stack to replicate the issue

import { Stack, StackProps } from 'aws-cdk-lib'
import { Construct } from 'constructs';
import { Role, ArnPrincipal } from 'aws-cdk-lib/aws-iam';

export class IamStack extends Stack{
    constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);

        new Role(this,'my-role',{
                assumedBy: new ArnPrincipal('arn:aws:iam::111111111111:role/my-lambda-execution-role');,
            }
        ) 
                
    }

}

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.88.0

Framework Version

No response

Node.js Version

v16.20.1

OS

Mac OS Ventura 13.4.1

Language

Typescript

Language Version

No response

Other information

No response

@malatep malatep added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 24, 2023
@github-actions github-actions bot added the @aws-cdk/aws-iam Related to AWS Identity and Access Management label Jul 24, 2023
@malatep
Copy link
Author

malatep commented Jul 24, 2023

This happens when the IAM role does not exist in the other account. Closing as this is not a CDK issue

@malatep malatep closed this as completed Jul 24, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant