-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
azurerm_key_vault not setting purge protection and error when attempting to purge keys. #9984
Comments
Same here. When creating a key vault using the defaults, creating a secret, and then destroying the secret, the above mentioned error occurs. with |
I'll have to run a test to know if it is a permission problem or is in relation to the Key Vault itself, but for consideration be aware a breaking change was recently enforced in which Soft Delete is now required to be enabled. From the FAQ, have you granted Purge permissions to the necessary identity? #9988 opened, as soft_delete_enabled should no longer be allowed to set to false |
I gave my service principal the purge permission as documented here and I still get the error posted in the opening notes. My key vault sp permissions creation code is now resource "azurerm_key_vault_access_policy" "sp-key_vault_access_policy" {
key_vault_id = azurerm_key_vault.key_vault.id
object_id = data.azurerm_client_config.current_client_config.object_id
tenant_id = data.azurerm_client_config.current_client_config.tenant_id
key_permissions = ["get", "list", "create", "encrypt", "delete", "purge"]
secret_permissions = ["get", "list", "set", "delete", "purge"]
depends_on = [azurerm_key_vault.key_vault]
} Also, soft delete is enabled. "createMode": null,
"enablePurgeProtection": null,
"enableRbacAuthorization": false,
"enableSoftDelete": true,
"enabledForDeployment": false,
"enabledForDiskEncryption": false,
"enabledForTemplateDeployment": false,
"networkAcls": null,
"privateEndpointConnections": null,
"provisioningState": "Succeeded", Edit: When I posted the above I had forgot to enable soft delete. I enabled that in the key vault and when running terraform destroy I now see... Error: purging Secret "sql-1-password" (Key Vault "https://my-key-vault.vault.azure.net/"): keyvault.BaseClient#PurgeDeletedSecret: Failure responding to request: StatusCode=409 --
Original Error: autorest/azure: Service returned an error. Status=409 Code="Conflict" Message="Secret is currently being deleted." InnerError={"code":"ObjectIsBeingDeleted"}
Which seems like it would be obvious during a destroy that the secret is being deleted. |
Using hashicorp/azurerm v2.41.0 When running terraform destroy again after the first attempt, it destroys the key vault, but gives the following error: |
Hi all - just looking at a possibly related issue and thought I should chip in with a couple things:
The behaviour for controlling whether a Key Vault item (Key / Secret etc) is purged when deleted is controlled by the
This setting defaults to The 409 Conflict is of interest, @jwshive is that consistent? We explicitly check the item is deleted before attempting to purge it, so this may indicate a bug or inconsistency between the read and purge operations. |
Same for me on an apply: Using azurem 2.41.0 and not setting purge_protection_enabled (so should have default of false). Cert was removed though in above run (not unexpected due to code change) and subsequent attempt re-created it. |
My KeyVault has SoftDelete and Purge Protection enabled. But I am getting this error, using a Service Principal after updating to version terraform-provider-azurerm: 2.43.0. The config. file was working fine before |
I am getting the same error on azurerm 2.43.0. I'm using a module to deploy virtual machines in Azure using GitLab CI and a service principal. I used to store the storage account access key in the module, but I've removed that feature. When I try to run the module again it attempts to delete the secret in the key vault (not the key vault itself), I get the following: Error: purging Secret "sa-access-key" (Key Vault "https://...vault.azure.net/"): keyvault.BaseClient#PurgeDeletedSecret: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="Forbidden" Message="The user, group or application 'appid=xxx;oid=xxx;iss=https://sts.windows.net/xxx/' does not have secrets purge permission on key vault '...;location=westeurope'. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125287" InnerError={"code":"ForbiddenByPolicy"} This is even though I am certain the service principal has the right access to the key vault: I'm using the following config:
And for the provider configuration:
|
+1 I get it too with terraform 0.14.6 and azure provider 2.46.1. On first run of destroy i get this error when running destroy again i dont get this error Update: Actually with 2.46.1 i have given Purge permissions (which was missing before) and it worked fine. I think this is a new requirement with 2.41.0 ( https://github.com/terraform-providers/terraform-provider-azurerm/releases/tag/v2.41.0 ) |
For us this is very consistent since this morning at least. Create environment, then destroy and we get this error. If we simply run destroy again we get a permission error (presumably the policy access was deleted successfully) and running a 3rd and all consecutive times reports the key vault cannot be found. Rerun create again and then destroy and the 409 error comes back. So to summarise, the first destroy we run always gets a 409 on the key vault secrets now. We are running azurerm 2.47.0 and terraform 0.14.7. But I bumped the versions hoping it would fix it. This morning we were on azurerm 2.44.0 and terraform 0.14.4 with the exact same problem. |
My previous problem seems to be resolved after upgrading to terraform 0.14.7 and azurerm 2.48.0, but I'm experiencing the 409 error now as well:
My provider settings are the following:
Setting purge_soft_delete_on_destroy to false solves my issue but this doesn't solve my issue. It seems @jackofallops is on the right track with the comment about a potential bug or inconsistency between the read and purge operations |
Our pipelines are dead in the water due to this bug and our heavy reliance on azure key vault. :( |
I just ran into this issue too (azurerm 2.50, terraform 0.13.6). My keyvaults have soft delete enabled. Running a destroy successfully deletes the secrets, but throws a 403 Forbidden when trying to purge them and ultimately fails. If I re-run terraform, instead of creating the secret with the values of the applied plan, the deleted secrets are restored in the keyvault with their previous values. The permission model used is vault access policy. |
Using terraform 0.14.6 and azurerm v2.5.0. On recent attempts to destroy we received following error when it tries to delete a keyvault, the weird bit was that it did manage to delete the keys just not the keyvault itself, Error: Error purging of Secret "<SECRET_NAME>" (Key Vault "https://<KEYVAULT_NAME>.vault.azure.net/") : keyvault.BaseClient#PurgeDeletedSecret: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="NotSupported" Message="Operation "purge" is not enabled for this vault." Similar to @tommydejong we added following and our http/400 issue is now resolved, provider "azurerm" { We did initially think issue #10707 was related but its now looking like a separate one that still need resolution |
Im getting this error as well. But left purge protection from the resource blockfor they keyvault which would default to "no purge protection" But then I start getting errors destroying the environment and I see sometimes the KeyVault with Purge protection enabled. But it's been inconsistent. Trying to reproduce This is my provider:
and then my key vault: So kept the purge protection off as stated on another comment in this thread. After doing tf plan and tf apply. It's created, but it has purge protection active. EDIT: |
@daguito81 have you tried with both set to false in the provider and false in the resource from a brand new environment, provider "azurerm" { resource "azurerm_key_vault" "azure" { also this article has some information on soft delete/purge protection for azure keyvaults -> https://docs.microsoft.com/en-us/azure/key-vault/general/soft-delete-change |
@mattduguid Yeah, i tested it with both and the behaviour was still funy. I did some tests just now. And terraform is deploying the KeyVault the right way. The problem was basically that attaching a KeyVault to an Azure Machine Learning workspace, automatically activates Purge Protection on that Keyvault. So Terraform deploys without Purge, then AzureML turns on the purge and then terraform tries to turn purge protection from true to nil, and it can't do that because purge protection can't be deactivated. Then when destroying the environment, if you have the option "purge deleted keyvaults" set to true. Then AzureML (and maybe other attached services have this behaviour as well) turns on purge protection, terraform tries to purge on delete, and everything fails. I'm trying to figure out why AzureML is activating purge protection on the attached key vault. |
same problem: using The KV was created with
|
Has someone found a solution for this? |
Can confirm this behavior when deploying Azure ML workspaces, they broke our current CI pipelines. |
Yeah, I don't think this a terraform problem. This is an Azure problem as they auto activate purge protection on Key Vaults when attached to a Machine Learning Workspace. If you do it "by hand" the result is the same. I changed my architecture to basically keep the AML Key Vault so assuming it's purge protected from the beginning. So I enable the recovery of purged key vaults in terraform instead. Not perfect, but it works and if I need to have a different key vault I just switch the name and purge them once the 90 days are done. |
For those following this issue, we ran into the same problem (not in Terraform, but using Bicep). After a few back and forth tickets, it appears Microsoft have now rolled out a change so that linking a KV to an ML workspace via ARM does NOT auto activate purge protection. I have tested this in From the support ticket we raised
Hopefully this helps some of you with your own use cases! |
👋 Since this has been fixed in the upstream API I'm going to close this issue out - #10273 is tracking support for more granular purge protection for resources, as such if your interested in that would you mind subscribing to that issue for updates? Thanks! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Terraform (and AzureRM Provider) Version
I am using azurerm provider 2.41.0 and terraform binary 0.14.3
Affected Resource(s)
azurerm_key_vault
Terraform Configuration Files
Debug Output
Error: purging Secret "sql-1-password" (Key Vault "https://my-key-vault.vault.azure.net/"): keyvault.BaseClient#PurgeDeletedSecret: Failure responding to request: StatusCode=400 --
Original Error: autorest/azure: Service returned an error. Status=400 Code="NotSupported" Message="Operation "purge" is not enabled for this vault."
Panic Output
Expected Behaviour
I expect the key vault to be created with enablePurgeProtection: false and a terraform destroy to not error out when removing a key vault.
Actual Behaviour
The key vault is created, but purge protection is null and not false.
...
"enablePurgeProtection": null,
"enableRbacAuthorization": false,
"enableSoftDelete": false,
"enabledForDeployment": false,
"enabledForDiskEncryption": false,
"enabledForTemplateDeployment": false,
....
A terraform destroy results in the error in debug output.
Steps to Reproduce
terraform destroy
Important Factoids
This was working last week as of Thursday or Friday.
References
This may be related to
The text was updated successfully, but these errors were encountered: