Cross-Account CodePipeline Role not Authorized to Access CodeCommit in Same-Region Separate Account

0

Hi, I have an account called "Dev" and an Account called "Stage1". Dev hosts my codecommit repos and each repo has a branch corresponding to the deployment environment (e.g. development, stage1, prod, etc.)

Dev has a role called deployer and an associated IAM Role Policy with the following rules.

Role
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "codecommit.amazonaws.com",
                    "codepipeline.amazonaws.com"
                ]
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

Associated Policy
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "ec2:*",
                "s3:*",
                "codecommit:*",
                "codedeploy:*",
                "codepipeline:*",
                "secretsmanger:*",
                "rds:*",
                "cloudformation:*",
                "appsync:*",
                "sts:AssumeRole"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:iam::<stage-account-number>:role/stage-adminportal-dev_codepipeline_role"
        }
    ]
}

Stage has a CodePipeline project with a source stage like so:

       stage {
          name = "Source"

          action {
              category         = "Source"
              configuration    = {
                  "BranchName"     = "stage1"
                  "RepositoryName" = "Dev-AdminPortal"
                }
              name             = "Source"
              output_artifacts = [
                  "source_output",
                ]
              owner            = "AWS"
              provider         = "CodeCommit"
              region           = "us-east-1"
              role_arn         = "arn:aws:iam::<dev-account-number>:role/it-deployer-role"
              run_order        = (known after apply)
              version          = "1"
            }
        }

Stage has a role policy like so that is attached to the codepipeline role

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "codecommit.amazonaws.com",
                    "codepipeline.amazonaws.com"
                ]
            },
            "Action": "sts:AssumeRole"
        }
    ]
}
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectVersion",
                "s3:GetBucketVersioning",
                "s3:PutObject",
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKey*",
                "kms:DescribeKey",
                "sts:AssumeRole"
            ],
            "Resource": [
                "arn:aws:s3:::stage-adminportal-dev-codepipeline-bucket",
                "arn:aws:s3:::stage-adminportal-dev-codepipeline-bucket/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "codebuild:*",
                "codecommit:*",
                "codepipeline:*",
                "sts:AssumeRole"
            ],
            "Resource": [
                "arn:aws:iam::<dev-account-number>:role/fl-stage-adminportal-dev_codepipeline_role",
                "arn:aws:iam::<dev-account-number>:role/fl-it-deployer-role",
                "arn:aws:kms::<dev-account-number>",
                "arn:aws:codecommit::<dev-account-number>"
            ]
        }
    ]
}

No matter where I add permissions for stage codepipeline to access dev code commit, I get the following error

Error: Error creating CodePipeline: InvalidStructureException: arn:aws:iam::<stage-account-number>:role/stage-adminportal-dev_codepipeline_role is not authorized to perform AssumeRole on role arn:aws:iam::<dev-account-number>:role/it-deployer-role

I'm obviously missing something, but not seeing it at the moment. Please advise if you can. Thanks.

질문됨 일 년 전367회 조회
1개 답변
0

One thing I noticed - The Dev role should allow the Stage1 account to assume the role. Hence, Principal should be the Stage1 account number.

The following AWS blog: https://aws.amazon.com/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ has a similar architecture wherein CodeCommit is in a Dev AWS account while CodePipeline is in another. You can refer to this blog and corresponding CloudFormation templates to check the IAM role and policy configuration used.

profile picture
joahna
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠