-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(region-info): ssm service principal is wrong in majority of regions #17984
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, except it's not 100% clear the Lambda insights stuff is 1:1 compatible.
* To get around this limitation, this is the mapping structure: | ||
* LambdaInsightsVersions10980 // for version 1.0.98.0 | ||
* - us-east-1 | ||
* -- {'arn': 'arn1'}, | ||
* - us-east-2 | ||
* -- {'arn': 'arn2'} | ||
* LambdaInsightsVersions10890 // a separate mapping version 1.0.89.0 | ||
* - us-east-1 | ||
* -- {'arn': 'arn3'}, | ||
* - us-east-2 | ||
* -- {'arn': 'arn4'} | ||
*/ | ||
|
||
const mapName = DEFAULT_MAPPING_PREFIX + insightsVersion.split('.').join(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing where this was replicated/replaced. If I'm reading the above comment correctly, that means the new mappings won't actually deploy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will deploy, the mapping name will just be different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok. FWIW, I checked out this branch locally and ran the aws-lambda tests, and got several failures (looks related to the rename).
Co-authored-by: Nick Lynch <[email protected]>
Co-authored-by: Nick Lynch <[email protected]>
Co-authored-by: Nick Lynch <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment about a potential breaking change; everything else is peachy.
this.accountExpression = account ?? core.Fn.findInMap(mappingName, core.Aws.REGION, 'repositoryAccount'); | ||
this.imageId = `${this.accountExpression}.dkr.ecr.${core.Aws.REGION}.${core.Aws.URL_SUFFIX}/${repositoryName}:${tag}`; | ||
private constructor(private readonly repositoryName: string, private readonly tag: string, private readonly account: string | undefined) { | ||
this.imageId = core.Lazy.string({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a potentially breaking change, no?
const myImage = codebuild.LinuxGpuBuildImage.DLC_TENSORFLOW_1_14_0;
createCBJob(myImage);
// ...
function createCBJob(myImage: codebuild.IBindableBuildImage) {
const jobId = myImage.imageId.includes('pytorch-training') ? 'pytorchjob' : 'tensorflowjob';
new codebuild.Project(this, jobId, { ... });
}
Obviously, a fabricated example, but can we really convert a string from a concrete to Lazy, tokenized value in a stable module and guarantee we won't break customers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh. I suppose not, and it's a good catch. But based on those kinds of arguments I don't think we can't make any changes at all because anybody anywhere might have taken a dependency on anything.
I want to say how big is the chance people have actually done that... and I think not too big?
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
The #17984 (big kudos to @rix0rrr for that) introduced a fix for the SSM service principal format which depends on the region. However, due to a typo in that PR some of regions still don't have correct SSM service principal. Currently the SSM service principal for the following regions incorrectly include region, while according to the [issue #16188](#16188) it should be only added to all regions since `ap-east-1`. ``` cn-north-1 us-iso-east-1 eu-central-1 ap-northeast-2 ap-south-1 us-east-2 ca-central-1 eu-west-2 us-isob-east-1 cn-northwest-1 eu-west-3 ap-northeast-3 us-gov-east-1 eu-north-1 ``` It works like that because by accident `RULE_SSM_PRINCIPALS_ARE_REGIONAL` has the same value as `RULE_S3_WEBSITE_REGIONAL_SUBDOMAIN`. This causes incorrect results returned by the `aws-entities/before` function. This PR fixes that issue. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
This brings in two fixes which is reflected in the snapshot changes. See: - aws/aws-cdk#17984 - aws/aws-cdk#18011 BREAKING CHANGE: Update aws-cdk libraries to 1.137.0
This brings in two fixes which is reflected in the snapshot changes. See: - aws/aws-cdk#17984 - aws/aws-cdk#18011 BREAKING CHANGE: Update aws-cdk libraries to 1.137.0
In #17984, mappings were altered so that non-alphanumeric values were replaced with `_`. However, the names in the name-value pairs must be fully alphanumeric according to the [docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html). The result was potentially invalid mappings generated at `cdk synth` that would fail at `cdk deploy`. One such example is the mappings generated for `lambda-insights` in #18789. In this PR, the replacement value is updated from `_` to `x`. The mapping is not surfaced anywhere other than the template, so we just need a value that satisfies cloudformation. Thus we're okay with the slight loss of readability. In addition, `CfnMapping` is updated to validate the names in the name-value pair and ensure that it is alphanumeric. Fixes #18789. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…ns (aws#17984) The SSM service principal format depends on the region. Older regions have a "global" service principal (`ssm.amazonaws.com`), while newer regions have only regional service principals (`ssm.ap-east-1.amazonaws.com`). A number of things have been changed to address this: * Add the notion of a "region order" into the `region-info` library. This allows us to express things like "does this region predate or postdate the change of some convention", and allows us to express that certain regions are *after* SSM introduced this change. * For region-agnostic stacks, it is no longer possible to supply a single value for the template that will suffice in all regions, as the *format itself* will have changed (neither `"ssm.amazonaws.com"` nor `"ssm.$REGION.amazonaws.com"` will work in all regions). That means we must always introduce a lookup map for region-agnostic stacks. Add `stack.regionalFact()` to generate lookup maps from facts in case it is necessary. * Detect if all map values are just an instantiation of a token pattern, and return the simplification if possible (e.g.: if the lookup values are `service.us-east-1.amazonaws.com`, `service.us-east-2.amazonaws.com`, etc, then simplify to `service.$REGION.$URL_SUFFIX` and avoid emitting a lookup). * Simplify existing usage sites of `RegionInfo.regionMap()` in Lambda and CodeBuild to use the new `stack.regionalFact()`. * Because lookup maps would always include information for all regions, including GovCloud regions, and those are only rarely necessary: add the infrastructure for users to restrict what partitions they want to include information for, by means of a context flag. Defaults to all regions if not specified (so we don't break old templates), but for new projects restricts itself to `['aws', 'aws-cn']`. Set to just `['aws']` for integration tests so we don't break all of our snapshot tests. Fixes aws#16188, fixes aws#17646. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
The aws#17984 (big kudos to @rix0rrr for that) introduced a fix for the SSM service principal format which depends on the region. However, due to a typo in that PR some of regions still don't have correct SSM service principal. Currently the SSM service principal for the following regions incorrectly include region, while according to the [issue aws#16188](aws#16188) it should be only added to all regions since `ap-east-1`. ``` cn-north-1 us-iso-east-1 eu-central-1 ap-northeast-2 ap-south-1 us-east-2 ca-central-1 eu-west-2 us-isob-east-1 cn-northwest-1 eu-west-3 ap-northeast-3 us-gov-east-1 eu-north-1 ``` It works like that because by accident `RULE_SSM_PRINCIPALS_ARE_REGIONAL` has the same value as `RULE_S3_WEBSITE_REGIONAL_SUBDOMAIN`. This causes incorrect results returned by the `aws-entities/before` function. This PR fixes that issue. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
In aws#17984, mappings were altered so that non-alphanumeric values were replaced with `_`. However, the names in the name-value pairs must be fully alphanumeric according to the [docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html). The result was potentially invalid mappings generated at `cdk synth` that would fail at `cdk deploy`. One such example is the mappings generated for `lambda-insights` in aws#18789. In this PR, the replacement value is updated from `_` to `x`. The mapping is not surfaced anywhere other than the template, so we just need a value that satisfies cloudformation. Thus we're okay with the slight loss of readability. In addition, `CfnMapping` is updated to validate the names in the name-value pair and ensure that it is alphanumeric. Fixes aws#18789. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
The SSM service principal format depends on the region. Older regions have a "global" service principal (
ssm.amazonaws.com
), while newer regions have only regional service principals (ssm.ap-east-1.amazonaws.com
).A number of things have been changed to address this:
region-info
library. This allows us to express things like "does this region predate or postdate the change of some convention", and allows us to express that certain regions are after SSM introduced this change."ssm.amazonaws.com"
nor"ssm.$REGION.amazonaws.com"
will work in all regions). That means we must always introduce a lookup map for region-agnostic stacks. Addstack.regionalFact()
to generate lookup maps from facts in case it is necessary.service.us-east-1.amazonaws.com
,service.us-east-2.amazonaws.com
, etc, then simplify toservice.$REGION.$URL_SUFFIX
and avoid emitting a lookup).RegionInfo.regionMap()
in Lambda and CodeBuild to use the newstack.regionalFact()
.['aws', 'aws-cn']
. Set to just['aws']
for integration tests so we don't break all of our snapshot tests.Fixes #16188, fixes #17646.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license