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

docs(codepipeline-actions): clarify how to use an encrypted existing Bucket with the S3SourceAction #15310

Conversation

berenddeboer
Copy link
Contributor

@berenddeboer berenddeboer commented Jun 25, 2021

If you import an S3 bucket encrypted with a custom key, it's impossible to give the source action role permission to use that key for decryption as far as I could see. I.e. I was not able to access this source action role.

By adding encryptionKey you can specify it at in the S3 source props, and permissions can then be granted inside this private heavy object.


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 25, 2021

@skinny85 skinny85 self-assigned this Jun 27, 2021
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @berenddeboer, but the way to do that in the CDK is to specify the Key when importing a Bucket:

const bucket = s3.Bucket.fromBucketAttributes(this, 'Bucket', {
  arn: 'arn:aws:s3:...',
  encryptionKey: kms.Key.fromKeyArn(stack, 'MyKey', 'arn:aws:kms:...'),
});

Now, passing bucket to S3SourceAction will grant the action's Role permissions to use that Key.

(BTW, if you want to customize the permissions a Role for a given Action has, you can always pass in a Role when creating the Action by using the role property of the Action class)

Hope this clears this up!

@berenddeboer
Copy link
Contributor Author

Ah that's great, I completely missed that. Shall I just change my pull request to a documentation update? I.e. giving an example?

And would it be better to submit a new pull request for that?

@skinny85
Copy link
Contributor

Ah that's great, I completely missed that. Shall I just change my pull request to a documentation update? I.e. giving an example?

And would it be better to submit a new pull request for that?

Feel free to either repurpose this one to only have a documentation update, or close this one, and open a new one - I'm fine with either, whatever is easier for you 🙂.

@mergify mergify bot dismissed skinny85’s stale review June 28, 2021 23:07

Pull request has been modified.

@dnz-bdeboer
Copy link

Linter now fails as I removed the test file change. Is it possible to change the title to a docs update? It seems I can't change the title myself.

@skinny85 skinny85 changed the title feat(codepipeline): add ability to specify encryption key for imported S3 source bucket docs(codepipeline-actions): clarify how to use an encrypted existing Bucket with the S3SourceAction Jun 30, 2021
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Linter now fails as I removed the test file change. Is it possible to change the title to a docs update? It seems I can't change the title myself.

Done!

Comment on lines 221 to 237
If an imported bucket has been encrypted with a custom key, import the
bucket in your stack with the key as follows:

```ts
const key = kms.Key.fromKeyArn(stack, 'MyKey', 'arn:aws:kms:...');
const sourceBucket = s3.Bucket.fromBucketAttributes(this, 'Bucket', {
BucketName: 'MyBucket',
encryptionKey: key,
});
const sourceAction = new codepipeline_actions.S3SourceAction({
actionName: 'S3Source',
bucket: sourceBucket,
bucketKey: 'path/to/file.zip',
encryptionKey: encryptionKey,
output: sourceOutput,
});
```
Copy link
Contributor

Choose a reason for hiding this comment

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

All of this should be removed.

Comment on lines 81 to 84
* const bucket = s3.Bucket.fromBucketAttributes(this, 'Bucket', {
* BucketName: 'MyBucket',
* encryptionKey: kms.Key.fromKeyArn(stack, 'MyKey', 'arn:aws:kms:...'),
* });
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not put code in the docs (remember that CDK is a multi-language environment).

Just mention the Bucket.fromBucketAttributes() method here, and that you should provide the Key there.

Or move these docs to the ReadMe file (those are automatically translated to other languages).

@mergify mergify bot dismissed skinny85’s stale review July 2, 2021 06:55

Pull request has been modified.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @berenddeboer!

@mergify
Copy link
Contributor

mergify bot commented Jul 8, 2021

Thank you for contributing! Your pull request will be updated from master 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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 90051cb
  • 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 c39d0eb into aws:master Jul 8, 2021
@mergify
Copy link
Contributor

mergify bot commented Jul 8, 2021

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

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
…Bucket with the S3SourceAction (aws#15310)

If you import an S3 bucket encrypted with a custom key, it's impossible to give the source action role permission to use that key for decryption as far as I could see. I.e. I was not able to access this source action role.

By adding `encryptionKey` you can specify it at in the S3 source props, and permissions can then be granted inside this private heavy object. 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants