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: customer-managed encryption keys #1274

Merged
merged 14 commits into from
Mar 20, 2021

Conversation

skuruppu
Copy link
Contributor

@skuruppu skuruppu commented Nov 27, 2020

Supports creating databases and backups, and restoring databases with a customer-managed encryption key.

@skuruppu skuruppu requested review from a team as code owners November 27, 2020 00:24
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/nodejs-spanner API. label Nov 27, 2020
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 27, 2020
@snippet-bot
Copy link

snippet-bot bot commented Nov 27, 2020

Here is the summary of changes.

You are about to add 3 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@skuruppu skuruppu requested a review from olavloite November 27, 2020 00:40
src/database.ts Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 9, 2021

Codecov Report

Merging #1274 (0830aa1) into master (a73f9fc) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1274   +/-   ##
=======================================
  Coverage   98.59%   98.60%           
=======================================
  Files          23       23           
  Lines       21841    21899   +58     
  Branches     1094     1099    +5     
=======================================
+ Hits        21535    21593   +58     
  Misses        297      297           
  Partials        9        9           
Impacted Files Coverage Δ
src/backup.ts 99.82% <100.00%> (+<0.01%) ⬆️
src/database.ts 99.96% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a73f9fc...0830aa1. Read the comment docs.

@skuruppu skuruppu requested a review from stephenplusplus March 9, 2021 05:40
@stephenplusplus stephenplusplus dismissed their stale review March 9, 2021 15:30

Not a breaking change anymore

@skuruppu
Copy link
Contributor Author

PTAL @olavloite


const request = {
encryptionConfig: {
kmsKeyName: keyName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this also include encryptionType: 'CUSTOMER_MANAGED_ENCRYPTION',? Or is it only required for backups?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is confusing. But CreateDatabaseRequest has an EncryptionConfig field which only lets you specify the kms_key_name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this might be because by default, it uses GOOGLE_DEFAULT_ENCRYPTION. But if the customer specifies an encryption key, then it has to be CUSTOMER_MANAGED_ENCRYPTION.

src/database.ts Outdated Show resolved Hide resolved
@@ -893,6 +1013,29 @@ describe('Spanner', () => {
);
});

// restore_backup_with_encryption_key
it('should restore database from a backup using an encryption key', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

For the Java client we have merged all backup/restore system tests into one as backups and restores are very slow. Is that something that we should consider for Node as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wish we could do that but I guess the samples were designed such that we take a separate backup and do a separate restore for CMEK. That means I have to test them separately here :( But if it becomes too flaky over time, then I may have to end up skipping these.

* const [, restoreOperation] = await database.restore(
* backupName,
* {
* encryptionConfig: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Depending on how often we think that users will use encrypted backups, I would consider leaving the encryption information out of this example. As it is now, it at first hand seems to be something that is required for all restore operations, while it is only required if you actually have an encrypted backup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think it's reasonable to remove this as it's not something you have to specify by default. Sometimes we have multiple examples so I may consider adding a separate one.

BTW, for restoring with an encryption key, it's not a requirement to specify the encryption key if the backup was encrypted. If the backup was encrypted, then the restored database is automatically encrypted with the same key as the backup. You only have to specify the key here if you want to encrypt it with a different key.

@skuruppu skuruppu added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 17, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 17, 2021
@skuruppu skuruppu merged commit 51cabc7 into googleapis:master Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/nodejs-spanner API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants