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(s3): add allowedActionPatterns parameter to grantWrite #24211

Merged
merged 10 commits into from
Mar 28, 2023

Conversation

lpizzinidev
Copy link
Contributor

@lpizzinidev lpizzinidev commented Feb 17, 2023

I've added an optional parameter allowedActionPatterns that will restrict the permissions to a certain list of action patterns for the grantWrite method.

Closes #24074


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 Feb 17, 2023

@github-actions github-actions bot added repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. labels Feb 17, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team February 17, 2023 11:36
@github-actions github-actions bot added the p2 label Feb 17, 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.

@lpizzinidev
Copy link
Contributor Author

The pull request linter fails with the following errors:

❌ Features must contain a change to a README file.

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.

Exemption Request.

The S3 README doesn't contain references to the grantWrite method so there is nothing to change there.
Let me know if you'd like me to add an explanation of the method.

@aws-cdk-automation aws-cdk-automation added pr/reviewer-clarification-requested The contributor has requested clarification on feedback, a failing build, or a failing PR Linter run pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. labels Feb 17, 2023
Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Adding an exclusion filter doesn't really fit the pattern of any of the rest of these functions. I would prefer to see a function that explicitly adds the patterns a user wants than one that filters out patterns.

@TheRealAmazonKendra TheRealAmazonKendra added pr-linter/exempt-readme The PR linter will not require README changes and removed pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. pr/reviewer-clarification-requested The contributor has requested clarification on feedback, a failing build, or a failing PR Linter run labels Feb 20, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review February 20, 2023 22:00

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

@lpizzinidev lpizzinidev changed the title feat(s3): added excludedKeyActions parameter to grantWrite feat(s3): added allowedActions parameter to grantWrite Feb 22, 2023
@mergify mergify bot dismissed TheRealAmazonKendra’s stale review February 22, 2023 08:33

Pull request has been modified.

@lpizzinidev
Copy link
Contributor Author

@TheRealAmazonKendra
Thanks for the feedback!
I've changed the parameter to allowedActions, granting permission only to specified actions.
Please let me know if this is ok or if you need more changes.

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Just a few suggested changes to the contract here.

@@ -771,8 +772,9 @@ export abstract class BucketBase extends Resource implements IBucket {
this.arnForObjects(objectsKeyPattern));
}

public grantWrite(identity: iam.IGrantable, objectsKeyPattern: any = '*') {
return this.grant(identity, this.writeActions, perms.KEY_WRITE_ACTIONS,
public grantWrite(identity: iam.IGrantable, objectsKeyPattern: any = '*', allowedActions: string[] = []) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public grantWrite(identity: iam.IGrantable, objectsKeyPattern: any = '*', allowedActions: string[] = []) {
public grantWrite(identity: iam.IGrantable, objectsKeyPattern: any = '*', allowedActions: string[] = ['*']) {

*/
grantWrite(identity: iam.IGrantable, objectsKeyPattern?: any): iam.Grant;
grantWrite(identity: iam.IGrantable, objectsKeyPattern?: any, allowedActions?: string[]): iam.Grant;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
grantWrite(identity: iam.IGrantable, objectsKeyPattern?: any, allowedActions?: string[]): iam.Grant;
grantWrite(identity: iam.IGrantable, objectsKeyPattern?: any, ...allowedActionPatterns?: string[]): iam.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.

The problem with using a rest parameter is that it cannot be marked as optional, nor given a default value.
So I opted for a required rest parameter allowedActionPatterns that will default to this.writeActions if empty.
However, with the current implementation, I'm getting this error at CodeBuild:

err  - METHOD aws-cdk-lib.aws_s3.Bucket.grantWrite: argument allowedActionPatterns, newly required argument. [new-argument:aws-cdk-lib.aws_s3.Bucket.grantWrite]
err  - METHOD aws-cdk-lib.aws_s3.BucketBase.grantWrite: argument allowedActionPatterns, newly required argument. [new-argument:aws-cdk-lib.aws_s3.BucketBase.grantWrite]
err  - METHOD aws-cdk-lib.aws_s3.IBucket.grantWrite: argument allowedActionPatterns, newly required argument. [new-argument:aws-cdk-lib.aws_s3.IBucket.grantWrite]

Any suggestion on how I could fix this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that's right. Fine as is.

@@ -204,8 +204,9 @@ export interface IBucket extends IResource {
*
* @param identity The principal
* @param objectsKeyPattern Restrict the permission to a certain key pattern (default '*')
* @param allowedActions: Include only certain actions in the permissions
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param allowedActions: Include only certain actions in the permissions
* @param allowedActionPatterns: Restrict the permissions to certain list of action patterns (default '*')

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review February 23, 2023 08:31

Pull request has been modified.

@lpizzinidev lpizzinidev changed the title feat(s3): added allowedActions parameter to grantWrite feat(s3): added allowedActionPatterns parameter to grantWrite Feb 23, 2023
@TheRealAmazonKendra
Copy link
Contributor

Go ahead and change that back to an optional array. It becomes a breaking change if the field is required.

@TheRealAmazonKendra TheRealAmazonKendra changed the title feat(s3): added allowedActionPatterns parameter to grantWrite feat(s3): add allowedActionPatterns parameter to grantWrite Mar 2, 2023
@mergify
Copy link
Contributor

mergify bot commented Mar 28, 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: 3d79254
  • 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 5b5c36f into aws:main Mar 28, 2023
@mergify
Copy link
Contributor

mergify bot commented Mar 28, 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 pr-linter/exempt-readme The PR linter will not require README changes repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iam: add more granular grant permissions
3 participants