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

new resource "azurerm_key_vault_key_encrypt" and data source "azurerm_key_vault_key_decrypt" #8895

Closed
wants to merge 6 commits into from

Conversation

njuCZ
Copy link
Contributor

@njuCZ njuCZ commented Oct 15, 2020

fix #7856

resource "azurerm_key_vault_key_encrypt" is similar with "aws_kms_ciphertext"
data source "azurerm_key_vault_key_decrypt" is similar with "aws_kms_secret"

to keep a stable encrypted value, make "azurerm_key_vault_key_encrypt" be a resource but not a data source.
there is no need to support "import" operation for resource "azurerm_key_vault_key_encrypt"

image

@tombuildsstuff
Copy link
Contributor

dependent on #7856 (comment)

@saranshlamba

This comment has been minimized.

@ghost ghost removed the waiting-response label Jan 4, 2021
@@ -0,0 +1,94 @@
package keyvault
Copy link
Contributor

Choose a reason for hiding this comment

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

If the intention is to encrypt secrets, might i suggest that the resource instead be called:
azurerm_key_vault_secret_encrypt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

becasue key vault key and key vault secret are different resource, and the rest api is using key vault key to encrypt and decrypt data. So personally I think azurerm_key_vault_secret_encrypt maybe a little misleading?

@@ -0,0 +1,83 @@
package keyvault
Copy link
Contributor

Choose a reason for hiding this comment

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

If the intention is to decrypt secrets, might i suggest that the resource instead be called:
azurerm_key_vault_secret_decrypt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as above

@@ -0,0 +1,94 @@
package keyvault

Copy link
Contributor

@IanMoroney IanMoroney Mar 2, 2021

Choose a reason for hiding this comment

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

I can see there being a value in having a resource block for encrypting secrets with a static encrypted blob, and a data source for encrypting secrets with a value that changes on every apply, but I only see an encrypt resource.

Could you create an equivalent encrypt data source, as if we're modelling it after aws_kms_ciphertext, we should have the ability for users to choose whether to change the encrypted blob frequently or infrequently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there any scenario that users want to change the encrypted data every time? In the resource, we could also change the encrypted data by changing the property name

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Thanks @njuCZ - left some comments inline

ValidateFunc: azure.ValidateKeyVaultChildId,
},

"payload": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what format are we expecting here? base64?

Suggested change
"payload": {
"encrypted_base64_data": {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as below

}, false),
},

"cipher_text": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this also then be

Suggested change
"cipher_text": {
"encrypted_data_in_base64": {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the result format is base64url, which is slightly different from base64. please refer to RFC: https://tools.ietf.org/html/rfc4648#section-5. I have noted it in the doc. Should I still rename this property?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes lets rename it to match what is expected so people don't have to look at docs and can tell from the property name. as for url in there is this different then any other base64 property for azure?

Copy link
Collaborator

Choose a reason for hiding this comment

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

lets go with encrypted_data_in_base64 and then add a validation function to ensure its the right base64 format

return fmt.Sprintf(`
%s

data "azurerm_key_vault_key_decrypt" "test" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we use the encrypt resource and decrypt to check that the workflow works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, in this data source, we assign the cipher_text of azurerm_key_vault_key_encrypt to payload, and in the check functions, we checked whether the descrypt value is the inital input plaintext.
In this way, we checked the whole encrypt and decrypt workflow

website/docs/d/key_vault_key_decrypt.html.markdown Outdated Show resolved Hide resolved
website/docs/r/key_vault_key_encrypt.html.markdown Outdated Show resolved Hide resolved
@njuCZ
Copy link
Contributor Author

njuCZ commented May 6, 2021

Thanks @katbyte , I have rebased and refine this PR

@ghost ghost removed the waiting-response label May 6, 2021
@njuCZ njuCZ requested a review from katbyte May 6, 2021 08:41
"payload": {
Type: schema.TypeString,
Required: true,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets just use base64 without any url in the property name and then validate it?

}, false),
},

"cipher_text": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets go with encrypted_data_in_base64 and then add a validation function to ensure its the right base64 format

@njuCZ
Copy link
Contributor Author

njuCZ commented May 7, 2021

@katbyte Thanks for your opinion, I have renamed the field and added validation

@ghost ghost removed the waiting-response label May 7, 2021
@IanMoroney
Copy link
Contributor

IanMoroney commented May 7, 2021 via email

@njuCZ
Copy link
Contributor Author

njuCZ commented May 7, 2021

@IanMoroney sorry for late reply. I thought this PR was blocked, but it seems things become better now. I have commented inline. Thanks for your review

@gro1m
Copy link
Contributor

gro1m commented Jul 30, 2021

@njuCZ @IanMoroney What is the status here, actually?

tombuildsstuff added a commit that referenced this pull request Mar 18, 2022
```
$ TF_ACC=1 go test -v ./internal/services/keyvault -run=TestAccEncryptedValueDataSource_
=== RUN   TestAccEncryptedValueDataSource_encryptAndDecrypt
=== PAUSE TestAccEncryptedValueDataSource_encryptAndDecrypt
=== CONT  TestAccEncryptedValueDataSource_encryptAndDecrypt
--- PASS: TestAccEncryptedValueDataSource_encryptAndDecrypt (274.42s)
PASS
ok  	github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault	276.443s
```

This commit supersedes #8895 by converting this into a Data Source rather than a Resource which handles the bi-directional
conversion of encrypted/decrypted values as necessary.
@tombuildsstuff
Copy link
Contributor

hi @njuCZ

Apologies for the delayed re-review of this PR - taking a look through here whilst this is functional these both want to be data sources and since the value can be converted bi-directionally we can make these a singular data source for "encrypted value".

Since there's some larger changes to get this PR in, I hope you don't mind but I've opened #15873 which supersedes this PR and will allow this to ship via the azurerm_key_vault_encrypted_value data source, which as mentioned above allows a bi-directional encryption/decryption of a plain-text/encrypted value as necessary - as such whilst I'd like to thank you for this contribution I'm going to close this in favour of #15873

Thanks!

tombuildsstuff added a commit that referenced this pull request Mar 18, 2022
```
$ TF_ACC=1 go test -v ./internal/services/keyvault -run=TestAccEncryptedValueDataSource_
=== RUN   TestAccEncryptedValueDataSource_encryptAndDecrypt
=== PAUSE TestAccEncryptedValueDataSource_encryptAndDecrypt
=== CONT  TestAccEncryptedValueDataSource_encryptAndDecrypt
--- PASS: TestAccEncryptedValueDataSource_encryptAndDecrypt (274.42s)
PASS
ok  	github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault	276.443s
```

This commit supersedes #8895 by converting this into a Data Source rather than a Resource which handles the bi-directional
conversion of encrypted/decrypted values as necessary.
@github-actions
Copy link

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for decrypt secrets from data encrypted with Azure keyvault key
6 participants