-
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
feat(s3): add allowedActionPatterns
parameter to grantWrite
#24211
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.
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.
Exemption Request. The S3 README doesn't contain references to the |
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.
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.
✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.
allowedActions
parameter to grantWrite
Pull request has been modified.
@TheRealAmazonKendra |
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.
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[] = []) { |
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.
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; |
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.
grantWrite(identity: iam.IGrantable, objectsKeyPattern?: any, allowedActions?: string[]): iam.Grant; | |
grantWrite(identity: iam.IGrantable, objectsKeyPattern?: any, ...allowedActionPatterns?: string[]): iam.Grant; |
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.
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?
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, 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 |
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.
* @param allowedActions: Include only certain actions in the permissions | |
* @param allowedActionPatterns: Restrict the permissions to certain list of action patterns (default '*') |
Pull request has been modified.
allowedActions
parameter to grantWriteallowedActionPatterns
parameter to grantWrite
Go ahead and change that back to an optional array. It becomes a breaking change if the field is required. |
allowedActionPatterns
parameter to grantWriteallowedActionPatterns
parameter to grantWrite
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 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 main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
I've added an optional parameter
allowedActionPatterns
that will restrict the permissions to a certain list of action patterns for thegrantWrite
method.Closes #24074
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license