Skip to content

Cross Account Iam Pass Role is not allowed

1

Scenario Trying to import pinpoint user endpoints from Account A ( stored in s3 bucket ) to Account B. Both AWS accounts resides inside same organization. Using NodeJS AWS V2 SDK

This function is called in the context of Account B (Where the Pinpoint project is created, We want to import endpoints to this project)

Pinpoint.createImportJob({
...params,
RoleArn: <ARN of role in Account A>
})

Also Created Trust policy in Account A to allow Services from Account B (to AssumeRole)

1 Answer
0

Greeting

Hi Aslam,

Thank you for your thoughtful question about cross-account IAM role permissions when importing Pinpoint endpoints. This type of scenario is common when working within AWS multi-account setups, and I’m happy to guide you through the solution. 😊


Clarifying the Issue

If I understand correctly, you’re trying to import Amazon Pinpoint user endpoints from Account A (where the data is stored in an S3 bucket) to Account B (where the Pinpoint project resides). The process involves using the AWS SDK for Node.js (v2) and specifying the IAM role in Account A to assume from Account B. However, you're encountering an error: "cross-account IAM Pass Role is not allowed."

This issue arises when IAM permissions or trust policies are not fully configured for cross-account access. It’s great that you’ve already set up a trust policy in Account A. Let’s fine-tune the permissions and your setup to resolve this problem effectively. By the end, you’ll have a working solution for seamless endpoint imports!


Key Terms

  • IAM PassRole Permission: Allows a user or service to pass an IAM role to an AWS service.
  • AssumeRole: Lets a principal in one account assume a role in another account to gain specific permissions.
  • Trust Policy: A JSON policy attached to an IAM role that defines which entities can assume it.
  • Amazon Pinpoint: A service that helps engage users across multiple communication channels.

The Solution (Our Recipe)

Steps at a Glance:

  1. Add iam:PassRole permission in Account B for the role in Account A.
  2. Update the trust policy in Account A to allow Account B to assume the role.
  3. Modify the Node.js code to use the correct role and session credentials.
  4. Test the import process for successful endpoint migration.

Step-by-Step Guide:

  1. Add PassRole Permission in Account B:
    Update the IAM policy for the role or user in Account B to include the iam:PassRole permission for the role in Account A.

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "iam:PassRole",
                "Resource": "arn:aws:iam::ACCOUNT_A_ID:role/RoleName"
            }
        ]
    }

  1. Update the Trust Policy in Account A:
    Ensure the IAM role in Account A has a trust policy that allows Account B to assume the role.

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

  1. Modify Node.js Code:
    Use the AWS SDK to assume the role in Account A and create the Pinpoint import job in Account B. Here’s an example with detailed comments:

    const AWS = require('aws-sdk');
    
    // Step 1: Assume the role in Account A
    const sts = new AWS.STS();
    const assumeRoleParams = {
        RoleArn: 'arn:aws:iam::ACCOUNT_A_ID:role/RoleName', // Role ARN in Account A
        RoleSessionName: 'PinpointImportSession' // Session name for tracking
    };
    
    sts.assumeRole(assumeRoleParams, (err, data) => {
        if (err) {
            console.error('Error assuming role:', err); // Log errors for debugging
        } else {
            // Step 2: Use the temporary credentials to initialize Pinpoint
            const pinpoint = new AWS.Pinpoint({
                accessKeyId: data.Credentials.AccessKeyId,
                secretAccessKey: data.Credentials.SecretAccessKey,
                sessionToken: data.Credentials.SessionToken,
                region: 'your-region'
            });
    
            // Step 3: Set up parameters for the import job
            const importJobParams = {
                ApplicationId: 'PinpointApplicationId', // Pinpoint App ID in Account B
                RoleArn: 'arn:aws:iam::ACCOUNT_A_ID:role/RoleName', // Role ARN in Account A
                S3Url: 's3://your-bucket-name/your-file' // S3 bucket and object location
            };
    
            // Step 4: Create the import job
            pinpoint.createImportJob(importJobParams, (error, response) => {
                if (error) {
                    console.error('Error creating import job:', error); // Log errors for debugging
                } else {
                    console.log('Import job created successfully:', response); // Confirm success
                }
            });
        }
    });

    After implementing the above code, test the workflow end-to-end and verify all IAM permissions to ensure everything is working as expected.


  1. Test the Import Process:
    Run the updated code and verify that the import job completes successfully. Check the Amazon Pinpoint console for the imported endpoints.

Closing Thoughts

Cross-account IAM configurations can be challenging, but by properly configuring permissions and trust policies, you can enable seamless collaboration between AWS accounts. Below are helpful documentation links to guide you further:

Aslam, you’re on the right track! Let me know if you have additional questions or need further assistance—I’m happy to help. 😊


Farewell

Best of luck with your Pinpoint project, Aslam! By tackling this, you’re developing skill in advanced AWS configurations. Keep testing, keep learning, and feel free to reach out anytime—you’re doing great! 🚀


Cheers,

Aaron 😊

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.