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

fix(eks): policy does not exist or is not attachable in China regions #24759

Closed
wants to merge 4 commits into from

Conversation

pahud
Copy link
Contributor

@pahud pahud commented Mar 23, 2023

As ECR Public is not available in China regions and govcloud, AmazonElasticContainerRegistryPublicReadOnly is not available and should not be attached to the role. This PR implements a RegionInfo method to determine if ECR public is available in current region and conditionally attach AmazonElasticContainerRegistryPublicReadOnly policy to the role.

Closes #24743 #24808


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p1 labels Mar 23, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team March 23, 2023 05:39
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 23, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: c675f43
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@pahud pahud marked this pull request as ready for review March 30, 2023 16:47
@pahud
Copy link
Contributor Author

pahud commented Mar 30, 2023

Exemption Request

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Mar 30, 2023
@aws-cdk-automation
Copy link
Collaborator

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

import { RegionInfo } from '@aws-cdk/region-info';

export function EcrPublicAvailable(region: any): boolean {
if (region && !Token.isUnresolved(region)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any handling we can do for when a token is being used? It seems like it's a fairly common use case and this fix would still result in an error for those users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thank you for the heads up. I will fix this soon.

Copy link
Contributor Author

@pahud pahud Mar 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealAmazonKendra Correct me if I am wrong. We probably can't conditionally attach the managed policy if we can't tell the region in the synth stage(region agnostic). In this case, we probably should always assume EcrPublicAvailable to be false and not attach the AmazonElasticContainerRegistryPublicReadOnly policy:

export function EcrPublicAvailable(region: any): boolean {
  if (region && !Token.isUnresolved(region)) {
    return RegionInfo.get(region).ecrPublicAvailable;
  } else {
    // we can't determine region in the synth time, assuming false.
    return false;
  }
}

And we should not run this as well:

f"aws ecr-public get-login-password --region us-east-1 | " \

Another option is to throw an error if stack.region is not specified just like below. But this will make stack.region always required when we create the eks.Cluster(breaking changes?).

if (Token.isUnresolved(stack.region)) {
throw new Error(`region (${stack.region}) cannot be a token and must be configured to one of: ${supportedRegions}`);
}

What do you think?

@pahud
Copy link
Contributor Author

pahud commented Apr 18, 2023

close in favor of #25170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort p1 pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eks: policy does not exist or is not attachable in China regions
3 participants