- 
                Notifications
    You must be signed in to change notification settings 
- Fork 4.3k
feat(s3-deployment): apply least privilege to destination bucket policies #35663
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
c352176
              db0d1d0
              b6a92f3
              f17cf5b
              c6b1794
              7db67ef
              15a29fe
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -470,7 +470,7 @@ | |
| "Arn" | ||
| ] | ||
| }, | ||
| "/*" | ||
| "/deploy/here/*" | ||
| ] | ||
| ] | ||
| } | ||
|  | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -400,9 +400,13 @@ | |
|  | ||
| this.sources = props.sources.map((source: ISource) => source.bind(this, { handlerRole: this.handlerRole })); | ||
|  | ||
| this.destinationBucket.grantReadWrite(handler); | ||
| const objectPattern = props.destinationKeyPrefix | ||
| ? `${this.normalizePrefix(props.destinationKeyPrefix)}*` | ||
| : '*'; | ||
|  | ||
| this.destinationBucket.grantReadWrite(handler, objectPattern); | ||
| if (props.accessControl) { | ||
| this.destinationBucket.grantPutAcl(handler); | ||
| this.destinationBucket.grantPutAcl(handler, objectPattern); | ||
| } | ||
| if (props.distribution) { | ||
| handler.addToRolePolicy(new iam.PolicyStatement({ | ||
|  | @@ -645,6 +649,15 @@ | |
| const uuid = `BucketDeploymentEFS-VPC-${fileSystemProps.vpc.node.addr}`; | ||
| return stack.node.tryFindChild(uuid) as efs.FileSystem ?? new efs.FileSystem(scope, uuid, fileSystemProps); | ||
| } | ||
| /** | ||
| * Normalize the prefix for S3 object keys. | ||
| * @param prefix prefix string | ||
| * @returns normalized prefix string | ||
| */ | ||
| normalizePrefix(prefix?: string): string { | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can make this a private method. | ||
| if (!prefix) return ''; | ||
| return prefix.replace(/^\/+/, '').replace(/\/+$/, '') + '/'; | ||
|          | ||
| } | ||
| } | ||
|  | ||
| export interface DeployTimeSubstitutedFileProps { | ||
|  | ||
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.
By default
pruneis true, which means when we remove source files from the CDK app, the lambda tries to clean up the corresponding files in S3. But it fails because it doesn't have delete permissions for paths that are no longer in the app.I tested this by:
app/frontendandapp/backendapp/backendsource and deploying it againWe should give the lambda delete permissions for the whole bucket (
*) to make deletion work properly.