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

feat(ecr): repo.grantPush #25845

Merged
merged 8 commits into from
Jun 13, 2023
Merged

feat(ecr): repo.grantPush #25845

merged 8 commits into from
Jun 13, 2023

Conversation

watany-dev
Copy link
Contributor

@watany-dev watany-dev commented Jun 4, 2023

For example, I realized that the role given to perform a push from Github Actions to ECR is excessive if using grantPullPush. The Readme was temporarily updated to fulfill the conditions of a 'feat' commit.


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

@gitpod-io
Copy link

gitpod-io bot commented Jun 4, 2023

@github-actions github-actions bot added the p2 label Jun 4, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team June 4, 2023 09:36
@github-actions github-actions bot added the star-contributor [Pilot] contributed between 25-49 PRs to the CDK label Jun 4, 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.

@watany-dev
Copy link
Contributor Author

Do we need a new integ-test?

@aws-cdk-automation aws-cdk-automation dismissed their stale review June 5, 2023 14:53

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 5, 2023
/**
* Grant the given identity permissions to use the images in this repository
*/
public grantPush(grantee: iam.IGrantable) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels reasonable to me but I don't have too much context in ecr so just going to make this comment here.

If we go this route, remember to change grantPullPush to call grantPush -- there's no reason to duplicate the code in both functions.

But then we also have to audit ecr:BatchCheckLayerAvailability, because that's not part of the permissions for grantPullPush. Why is it part of grantPush? And if it is necessary, it should be a part of grantPullPush as well.

Copy link
Contributor Author

@watany-dev watany-dev Jun 7, 2023

Choose a reason for hiding this comment

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

There was an issue of duplication with the getauthorizationtoken when executing grantPull and grantPush within grantPullPush. I have ensured readability by extracting and commonizing other Actions. I am referencing the S3Bucket. I am not fully aware of the details of BatchCheckLayerAvailability, but it is an Action in accordance with the following official documentation. I have made it compatible with both Pull and PullPush.

https://docs.aws.amazon.com/ja_jp/AmazonECR/latest/userguide/image-push.html#image-push-iam

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to confirm if the duplication is really an issue here. iam.Grant is wise enough to get rid of any duplication, e.g. even if you allow ecr:GetAuthorizationToken twice, the policy is synthesized without any error and it has just a single allow policy. Afaik it should be valid and safe to call grantPull and grantPush in grantPullPush.

@watany-dev watany-dev requested a review from kaizencc June 7, 2023 02:26
@@ -0,0 +1,15 @@
export const REPO_PULL_ACTIONS: string[] = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that these constants are implementation details, I would keep them as private variables in repository.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

);
iam.Grant.addToPrincipal({
Copy link
Contributor

Choose a reason for hiding this comment

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

To deal with the duplication issue, you can declare both sets of actions as Set<string>, both of which containing 'ecr:GetAuthorizationToken'. Then you can transform them to arrays before passing them to this.grant().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion. Unfortunately, the ecr:GetAuthorizationToken action is invoked not against a registry, but against the entire ECR service, requiring its resource to be set as '*'. Therefore, I believe it's difficult to handle it along with other Actions within the grant. With this in mind, if there are any necessary refactorings, I would appreciate your guidance.

@corymhall corymhall removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 12, 2023
@mergify mergify bot dismissed otaviomacedo’s stale review June 12, 2023 16:32

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 12, 2023
@mergify
Copy link
Contributor

mergify bot commented Jun 13, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@mergify mergify bot merged commit 01f0d92 into aws:main Jun 13, 2023
@mergify
Copy link
Contributor

mergify bot commented Jun 13, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@watany-dev watany-dev deleted the ecr-grant-push branch June 13, 2023 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants