-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Add customer-managed encryption key (KMS) support to GCS backend #31786
Conversation
5102b1e
to
c38f8e8
Compare
I had another go implementing the new config fields as a nested block instead of a string and investigated the problem I had before:
I think I've tracked down the problem to this comment: terraform/internal/configs/synth_body.go Lines 76 to 77 in a29fefb
And because of this I'm inclined to leave the new kms_encryption_key attribute as a string |
ebc7ae5
to
1615407
Compare
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.
@SarahFrench Thanks very much for your contribution with this PR. I have some suggestions for wording changes, but overall things look good to me.
This means that default values are supplied later by TF instead of supplied as config from the user This also avoids issues related to making field conflicts explicit with `ConflictsWith`
Removing the Default from `encryption_key` does not appear to be a breaking change when tested manually
Co-authored-by: Matthew Garrell <[email protected]>
a2d078e
to
9d22426
Compare
Note: just force pushed to squash a few commits and clean up commit messages @mgarrell777 - Thanks for all your help, I'll watch out for using passive voice in future! |
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.
These changes look good to me!
I like the choice to make the two encryption options conflict rather than attempt to support automatic migration between the two. That kind of change ought to be rare and I think it's better to ask our users to carefully handle it manually than take responsibility for doing it ourselves.
Thanks for your help @alisdair ! I'm feeling a lot more confident about getting this merged. And also I'm glad that you agree that we should leave changing between encryption methods as a manual steps for users, instead of automating it 😅 What should the next steps for this PR be? Is it ok for me to merge, and should I update CHANGELOG.md afterwards? Or should I leave that to the core team? Here's a proposed enhancement entry:
|
Yep, it's fine for you to merge, and please do update the CHANGELOG after doing so. That looks good to me—house style is to end the sentence with a period, and don't forget the GitHub issue at the end (i.e. |
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Description
Closes #24967
Currently the gcs backend allows users the option of supplying an encryption key from the client side, customer-supplied encryption keys, which is used as an additional layer of encryption in addition to Google-managed encryption keys. If a key isn't supplied in this way then Google-managed encryption keys are used in the GCS bucket by default.
This PR adds the alternative option of using a customer-managed KMS key to encrypt the state files in the bucket (in addition to Google's own encryption). Details of the KMS key are included in Storage API calls, and retrieving the key is internal to the GCS service.
Things to note
The new encryption method conflicts with the customer-supplied encryption feature that already exists in the backend BUT there isn't a risk of data being lost due to this. When switching between the two types of encryption, in either direction, the running
terraform init -migrate-state
results in errors returned from the API and state being OK and accessible in the 'old' encryption style, still.Users will need to remove the old method of encryption from the state file before beginning to use the other type of encryption. There needs to be an explicit write to state to remove the old encryption method, and after that the new encryption method can start to be used.
I've updated documentation to give guidance about this, but I could use a review specifically about technical writing. This is the altered page in the deployment of this PR: https://terraform-8l6jf7ots-hashicorp.vercel.app/language/settings/backends/gcs
Due to the conflict between different encryption methods, this PR changes the schema to mark these fields as conflicting. As a result of this, I've needed to stop the
encryption_key
field having a default value of""
. This isn't a breaking change because the (schema.ResourceData).Get function will supply the zero value for that field when it is not defined in the config (or ENV).Open questions
Can I improve my use of contexts in the new tests?
Do we need to add any code to help handle the transition between different configurations of the GCS backend?
Technical writing review needed? See changes in deployment here✅