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

(codedeploy): Incorrect codedeploy service principal for isolated regions #19399

Closed
mattphan8264 opened this issue Mar 15, 2022 · 8 comments · Fixed by #19729
Closed

(codedeploy): Incorrect codedeploy service principal for isolated regions #19399

mattphan8264 opened this issue Mar 15, 2022 · 8 comments · Fixed by #19729
Assignees
Labels
@aws-cdk/aws-codedeploy Related to AWS CodeDeploy bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@mattphan8264
Copy link

mattphan8264 commented Mar 15, 2022

General Issue

Incorrect CodeDeploy service principal for isolated regions (us-iso-east-1 and us-isob-east-1).

The Question

Code deploy service role is being set to codedeploy.us-isob-east-1.amazonaws.com and codedeploy.us-iso-east-1.amazonaws.com for LCK and DCA regions.

It should be codedeploy.amazonaws.com.

Output we are getting:

    "ApiLambdaCodeDeployDeploymentDeploymentGroupServiceRole45D217E3": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": "codedeploy.us-isob-east-1.amazonaws.com"
              }
            }
          ],
          "Version": "2012-10-17"
        },
        "ManagedPolicyArns": [
          {
            "Fn::Join": [
              "",
              [
                "arn:",
                {
                  "Ref": "AWS::Partition"
                },
                ":iam::aws:policy/service-role/AWSCodeDeployRoleForLambdaLimited"
              ]
            ]
          }
        ]
      },
      "Metadata": {
        "aws:cdk:path": "GammaLCK/ApiLambda/CodeDeployDeployment/DeploymentGroup/ServiceRole/Resource"
      }
    },

CDK CLI Version

2.10.0 (build e5b301f)

Framework Version

No response

Node.js Version

No response

OS

No response

Language

Typescript

Language Version

No response

Other information

No response

@mattphan8264 mattphan8264 added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Mar 15, 2022
@ryparker ryparker changed the title (module name): short issue description (codedeploy): Incorrect codedeploy service principal for LCK and DCA Mar 15, 2022
@peterwoodworth
Copy link
Contributor

The convention for standard regions seems to have the region included - if this isn't true for LCK/DCA regions then you can work around this with escape hatches to override the service property set by CDK

    const ldg = new LambdaDeploymentGroup(this, 'LDG', {
      alias,
    })

    const cfnRole = ldg.role.node.defaultChild as CfnRole;
    cfnRole.addPropertyOverride('AssumeRolePolicyDocument.Statement.0.Principal.Service', 'codedeploy.amazonaws.com')

@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Mar 24, 2022
@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.

@peterwoodworth
Copy link
Contributor

Ping me if you have any more concerns

@skinny85
Copy link
Contributor

I think we should actually handle this correctly in the CodeDeploy library.

@peterwoodworth let me know if you disagree.

@skinny85 skinny85 reopened this Mar 31, 2022
@skinny85 skinny85 added the @aws-cdk/aws-codedeploy Related to AWS CodeDeploy label Mar 31, 2022
@peterwoodworth
Copy link
Contributor

@skinny85 I have nothing against that! I'm curious if there's any precedent for doing something like this - I can't say I've seen any piece of code ever take restricted regions into consideration

@peterwoodworth peterwoodworth added bug This issue is a bug. p1 effort/small Small work item – less than a day of effort and removed guidance Question that needs advice or information. labels Mar 31, 2022
@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 1, 2022

This where the magic happens:

function determineConfiguration(service: string): (service: string, region: string, urlSuffix: string) => string {

It's hard though. Too many ifs on the dance floor...

skinny85 added a commit to skinny85/aws-cdk that referenced this issue Apr 1, 2022
Turns out, the Service Principal for CodeDeploy in the isolated regions is not regional like in all other regions,
but rather universal (`codedeploy.amazonaws.com`).

Fixes aws#19399
@skinny85
Copy link
Contributor

skinny85 commented Apr 1, 2022

This where the magic happens:

function determineConfiguration(service: string): (service: string, region: string, urlSuffix: string) => string {

It's hard though. Too many ifs on the dance floor...

Thanks @rix0rrr! Super helpful. I was able to submit #19729 thanks to your tip.

@skinny85 skinny85 changed the title (codedeploy): Incorrect codedeploy service principal for LCK and DCA (codedeploy): Incorrect codedeploy service principal for isolated regions Apr 1, 2022
@mergify mergify bot closed this as completed in #19729 Apr 2, 2022
mergify bot pushed a commit that referenced this issue Apr 2, 2022
…19729)

Turns out, the Service Principal for CodeDeploy in the isolated regions is not regional like in all other regions,
but rather universal (`codedeploy.amazonaws.com`).

Fixes #19399

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Apr 2, 2022

⚠️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.

This was referenced Apr 7, 2022
mergify bot added a commit that referenced this issue Apr 7, 2022
See [CHANGELOG](https://github.com/aws/aws-cdk/blob/bump/1.152.0/CHANGELOG.md)

For convenience, extracted the relevant CHANGELOG entry:

## [1.152.0](v1.151.0...v1.152.0) (2022-04-06)


### Features

* **cfnspec:** cloudformation spec v63.0.0 ([#19679](#19679)) ([dba96a9](dba96a9))
* **cfnspec:** cloudformation spec v65.0.0 ([#19745](#19745)) ([796fc64](796fc64))
* **cli:** add --build option ([#19663](#19663)) ([eb9b8e2](eb9b8e2)), closes [#19667](#19667)
* **cli:** preview of `cdk import` ([#17666](#17666)) ([4f12209](4f12209))
* **core:** throw error when stack name exceeds max length ([#19725](#19725)) ([1ffd45e](1ffd45e))
* **eks:** add k8s v1.22 ([#19756](#19756)) ([9a518c5](9a518c5))
* **opensearch:** Add latest Opensearch Version 1.2 ([#19749](#19749)) ([a2ac36e](a2ac36e))
* add new integration test runner ([#19754](#19754)) ([1b4d010](1b4d010))
* **eks:** alb-controller v2.4.1 ([#19653](#19653)) ([1ec08df](1ec08df))
* **lambda:** add support for ephemeral storage ([#19552](#19552)) ([f1d9b6a](f1d9b6a)), closes [#19605](#19605)
* **s3:** EventBridge bucket notifications ([#18614](#18614)) ([d8e602b](d8e602b)), closes [#18076](#18076)
* **synthetics:** new puppeteer 3.5 runtime ([#19673](#19673)) ([ce2b91b](ce2b91b)), closes [#19634](#19634)


### Bug Fixes

* **aws_applicationautoscaling:** Add missing members to PredefinedMetric enum ([#18978](#18978)) ([75a6fa7](75a6fa7)), closes [#18969](#18969)
* **cli:** apps with many resources scroll resource output offscreen ([#19742](#19742)) ([053d22c](053d22c)), closes [#19160](#19160)
* **cli:** support attributes of DynamoDB Tables for hotswapping ([#19620](#19620)) ([2321ece](2321ece)), closes [#19421](#19421)
* **cloudwatch:** automatic metric math label cannot be suppressed ([#17639](#17639)) ([7fa3bf2](7fa3bf2))
* **codedeploy:** add name validation for Application, Deployment Group and Deployment Configuration ([#19473](#19473)) ([9185042](9185042))
* **codedeploy:** the Service Principal is wrong in isolated regions ([#19729](#19729)) ([7e9a43d](7e9a43d)), closes [#19399](#19399)
* **core:** `Fn.select` incorrectly short-circuits complex expressions ([#19680](#19680)) ([7f26fad](7f26fad))
* **core:** detect and resolve stringified number tokens ([#19578](#19578)) ([7d9ab2a](7d9ab2a)), closes [#19546](#19546) [#19550](#19550)
* **core:** reduce CFN template indent size to save bytes ([#19656](#19656)) ([fd63ca3](fd63ca3))
* **ecs:** 'desiredCount' and 'ephemeralStorageGiB' cannot be tokens ([#19453](#19453)) ([c852239](c852239)), closes [#16648](#16648)
* **ecs:** remove unnecessary error when adding volume to external task definition ([#19774](#19774)) ([5446ded](5446ded)), closes [#19259](#19259)
* **iam:** policies aren't minimized as far as possible ([#19764](#19764)) ([876ed8a](876ed8a)), closes [#19751](#19751)
* **logs:** Faulty Resource Policy Generated ([#19640](#19640)) ([1fdf122](1fdf122)), closes [#17544](#17544)
mergify bot added a commit that referenced this issue Apr 7, 2022
See [CHANGELOG](https://github.com/aws/aws-cdk/blob/bump/2.20.0/CHANGELOG.md)

For convenience, extracted the relevant CHANGELOG entry:

## [2.20.0](v2.19.0...v2.20.0) (2022-04-07)


### Features

* **cfnspec:** cloudformation spec v63.0.0 ([#19679](#19679)) ([dba96a9](dba96a9))
* **cfnspec:** cloudformation spec v65.0.0 ([#19745](#19745)) ([796fc64](796fc64))
* **cli:** add --build option ([#19663](#19663)) ([eb9b8e2](eb9b8e2)), closes [#19667](#19667)
* **cli:** preview of `cdk import` ([#17666](#17666)) ([4f12209](4f12209))
* **core:** throw error when stack name exceeds max length ([#19725](#19725)) ([1ffd45e](1ffd45e))
* **eks:** add k8s v1.22 ([#19756](#19756)) ([9a518c5](9a518c5))
* **opensearch:** Add latest Opensearch Version 1.2 ([#19749](#19749)) ([a2ac36e](a2ac36e))
* add new integration test runner ([#19754](#19754)) ([1b4d010](1b4d010))
* **eks:** alb-controller v2.4.1 ([#19653](#19653)) ([1ec08df](1ec08df))
* **lambda:** add support for ephemeral storage ([#19552](#19552)) ([f1d9b6a](f1d9b6a)), closes [#19605](#19605)
* **s3:** EventBridge bucket notifications ([#18614](#18614)) ([d8e602b](d8e602b)), closes [#18076](#18076)


### Bug Fixes

* **aws_applicationautoscaling:** Add missing members to PredefinedMetric enum ([#18978](#18978)) ([75a6fa7](75a6fa7)), closes [#18969](#18969)
* **cli:** apps with many resources scroll resource output offscreen ([#19742](#19742)) ([053d22c](053d22c)), closes [#19160](#19160)
* **cli:** support attributes of DynamoDB Tables for hotswapping ([#19620](#19620)) ([2321ece](2321ece)), closes [#19421](#19421)
* **cloudwatch:** automatic metric math label cannot be suppressed ([#17639](#17639)) ([7fa3bf2](7fa3bf2))
* **codedeploy:** add name validation for Application, Deployment Group and Deployment Configuration ([#19473](#19473)) ([9185042](9185042))
* **codedeploy:** the Service Principal is wrong in isolated regions ([#19729](#19729)) ([7e9a43d](7e9a43d)), closes [#19399](#19399)
* **core:** `Fn.select` incorrectly short-circuits complex expressions ([#19680](#19680)) ([7f26fad](7f26fad))
* **core:** detect and resolve stringified number tokens ([#19578](#19578)) ([7d9ab2a](7d9ab2a)), closes [#19546](#19546) [#19550](#19550)
* **core:** reduce CFN template indent size to save bytes ([#19656](#19656)) ([fd63ca3](fd63ca3))
* **ecs:** 'desiredCount' and 'ephemeralStorageGiB' cannot be tokens ([#19453](#19453)) ([c852239](c852239)), closes [#16648](#16648)
* **ecs:** remove unnecessary error when adding volume to external task definition ([#19774](#19774)) ([5446ded](5446ded)), closes [#19259](#19259)
* **iam:** policies aren't minimized as far as possible ([#19764](#19764)) ([876ed8a](876ed8a)), closes [#19751](#19751)
* **logs:** Faulty Resource Policy Generated ([#19640](#19640)) ([1fdf122](1fdf122)), closes [#17544](#17544)
StevePotter pushed a commit to StevePotter/aws-cdk that referenced this issue Apr 27, 2022
…ws#19729)

Turns out, the Service Principal for CodeDeploy in the isolated regions is not regional like in all other regions,
but rather universal (`codedeploy.amazonaws.com`).

Fixes aws#19399

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codedeploy Related to AWS CodeDeploy bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants