Skip to content

fix(keyvault): serve deleted vaults so terraform destroy can purge - #634

Merged
hectorvent merged 1 commit into
mainfrom
fix/keyvault-deleted-vaults
Nov 5, 2026
Merged

hectorvent merged 1 commit into
mainfrom
fix/keyvault-deleted-vaults

Conversation

@hectorvent

Copy link
Copy Markdown
Member

Summary

Since #624 a vault reports enableSoftDelete: true. azurerm purges a vault after deleting it when that flag is set, and floci-az had no deletedVaults route, so terraform destroy failed and left the resource group behind. The Terraform and OpenTofu suites ignored the failed destroy, so CI stayed green.

  • Deleting a vault with soft delete on keeps a deleted vault record. Vaults_GetDeleted, Vaults_ListDeleted and Vaults_PurgeDeleted are served, and a PUT with createMode: recover restores the vault.
  • ManagedHsms_ListDeleted answers an empty list, because az keyvault list-deleted fails without it.
  • Each IaC suite now ends with a full destroy that must succeed and remove the resource group.

Type of change

  • Bug fix (fix:)
  • New feature (feat:)
  • Breaking change (feat!: or fix!:)
  • Docs / chore

Azure Compatibility

Incorrect behaviour: the purge POST to deletedVaults/{name}/purge answered 404, so terraform destroy exited 1 with default provider settings.

Before #624, destroy exited 0 and the resource group answered 404. On main, destroy exits 1 and the resource group still answers 200.

Verified with real clients: Terraform 31 of 31, OpenTofu 33 of 33, Terraform at parity=azure 31 of 31, and Azure CLI 44 of 45 (one az vm test skipped). The IaC runs predate only the empty managed HSM list, which those suites do not call.

Known deviations are documented in docs/services/key-vault.md: a deleted vault holds no name, a plain PUT is allowed, records never expire, and managed HSMs have no deleted state.

Checklist

  • ./mvnw test passes locally: not run in full, it does not fit the available runners. The 548 affected unit tests pass; CI runs the full suite.
  • New or updated integration test added
  • Commit messages follow Conventional Commits
  • I have no more than 2 open, non-draft pull requests and no more than 4 open pull requests in total (drafts included) in this repository (maintainers and dependency bots are exempt).

Since #624 a vault reports enableSoftDelete: true, as Azure does. azurerm
purges a vault after deleting it when that flag is set, and floci-az had no
deletedVaults route, so the purge answered 404 and terraform destroy failed
with default provider settings, leaving the resource group behind.

Keep a deleted vault record on delete, and serve Vaults_GetDeleted,
Vaults_ListDeleted and Vaults_PurgeDeleted. A PUT with createMode: recover
restores the vault. ManagedHsms_ListDeleted answers an empty list, because
az keyvault list-deleted fails without it.

The Terraform and OpenTofu suites ignored a failed destroy, so they stayed
green. Each now ends with a full destroy that must succeed and remove the
resource group.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
@hectorvent
hectorvent requested a review from fredpena as a code owner November 5, 2026 03:55
@greptile-apps

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect Key Vault deletion and infrastructure teardown workflows.

Fix the recovery/delete race before merging because it can remove all recoverable vault state.

Findings

  1. P1 Recovery can lose deleted state ▶

Summary

Adds deleted-vault read, list, purge, and recovery support so Terraform can finish destroying a vault.

  • Deleted vaults can now be recovered or purged.

Known intentional behavior acknowledged by hectorvent: plain PUT succeeds and discards deleted state, including the purge-protection bypass through recreation. hectorvent also identifies released deleted names, records that never expire, and empty deleted managed HSM lists as known deviations. Recovery without a deleted record is explicitly described and tested as an ordinary create.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Active[Active vault] -->|DELETE| Deleted[Deleted vault record]
  Deleted -->|PUT createMode recover| Active
  Deleted -->|POST purge; protection off| Removed[Record removed]
  Deleted -->|POST purge; protection on| Conflict[409 Conflict]
Loading

Reviews (1) · Last reviewed commit: "fix(keyvault): serve deleted vaults so t..." · Reviewed by Greptile

existing.map(document -> String.valueOf(document.get("name"))).orElse(id.name()),
listed.orElseGet(() -> existing.map(document -> accessPolicies(ArmJson.cast(document.get("properties"))))
.orElse(List.of())), defaults.defaultLocation(req.scope()))).stored().value();
deleted.forEach(stored -> deletedVaults.delete(stored.id()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Recovery can lose deleted state

A concurrent DELETE can erase a recovered vault completely. Recovery reads the deleted record, writes the active vault, then removes the deleted record by ID. Between those last two steps, DELETE can remove the newly recovered vault and write a fresh deleted record at the same ID. This cleanup then deletes that fresh record, leaving neither an active vault nor anything to recover, even though both requests succeed.

Use one shared lock for the full recovery/delete sequence, and batch the related stored changes so a restart cannot split them.

Knowledge Base Used:

@hectorvent hectorvent added arm Azure Resource Manager (ARM) bug Something isn't working documentation Improvements or additions to documentation keyvault Azure Key Vault labels Nov 5, 2026
@hectorvent
hectorvent merged commit f90d590 into main Nov 5, 2026
18 checks passed
@hectorvent
hectorvent deleted the fix/keyvault-deleted-vaults branch November 5, 2026 13:54
@hectorvent

Copy link
Copy Markdown
Member Author

🎉 This PR is included in version 0.17.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

McFizh pushed a commit to McFizh/floci-az that referenced this pull request Nov 16, 2026
# [0.17.0](floci-io/floci-az@0.16.0...0.17.0) (2026-11-15)

### Bug Fixes

* **aci:** report a failed container group action on the POST ([floci-io#623](floci-io#623)) ([b9ab61c](floci-io@b9ab61c))
* **apim:** keep child resources in the storage layer, keyed case-insensitively ([floci-io#651](floci-io#651)) ([d70496f](floci-io@d70496f))
* **blob:** answer Append Block with Last-Modified and x-ms-request-server-encrypted ([floci-io#631](floci-io#631)) ([f440fce](floci-io@f440fce)), closes [floci-io#587](floci-io#587)
* **blob:** apply SAS response-header overrides on read ([floci-io#629](floci-io#629)) ([04ec99e](floci-io@04ec99e))
* **containerapps:** drop an empty keyVaultUrl from a plain secret ([floci-io#649](floci-io#649)) ([68a9e13](floci-io@68a9e13)), closes [floci-io#576](floci-io#576)
* **containerapps:** report a managed environment's customDomainVerificationId ([floci-io#630](floci-io#630)) ([6b2b76f](floci-io@6b2b76f)), closes [floci-io#573](floci-io#573)
* **deployments:** list a nested deployment's resources in its parent ([floci-io#636](floci-io#636)) ([87c08bd](floci-io@87c08bd))
* **deployments:** read a parameter with a null reference as a plain value ([floci-io#635](floci-io#635)) ([e29d909](floci-io@e29d909))
* **eventgrid:** refuse a destination type floci-az cannot deliver to ([floci-io#622](floci-io#622)) ([aec34bd](floci-io@aec34bd))
* **eventhub:** skip discarded journal disk tuning ([floci-io#614](floci-io#614)) ([284f3fc](floci-io@284f3fc)), closes [floci-io#606](floci-io#606)
* **keyvault:** serve deleted vaults so terraform destroy can purge ([floci-io#634](floci-io#634)) ([f90d590](floci-io@f90d590)), closes [floci-io#624](floci-io#624)
* **keyvault:** store a vault's properties and support PATCH ([floci-io#624](floci-io#624)) ([9b8b44f](floci-io@9b8b44f))
* **monitor:** answer the deleted workspaces list ([floci-io#625](floci-io#625)) ([b60d698](floci-io@b60d698))
* **monitor:** keep the tags of workspaces and data collection endpoints and rules ([floci-io#660](floci-io#660)) ([df23147](floci-io@df23147)), closes [floci-io#659](floci-io#659)
* **queue:** accept Update Message without a body (visibility-only update) ([floci-io#621](floci-io#621)) ([c3215c8](floci-io@c3215c8)), closes [floci-io#620](floci-io#620)
* **queue:** return messages in the order they were sent ([floci-io#647](floci-io#647)) ([37b0f46](floci-io@37b0f46))
* **servicebus,eventhub:** wait for Artemis to answer AMQP before reporting a namespace ready ([floci-io#615](floci-io#615)) ([6fa9511](floci-io@6fa9511))
* **servicebus:** balance source accounting after explicit dead-letter ([floci-io#648](floci-io#648)) ([16f5f74](floci-io@16f5f74))
* **servicebus:** bound TCP connect by the readiness deadline ([floci-io#604](floci-io#604)) ([b06f481](floci-io@b06f481)), closes [floci-io#603](floci-io#603)
* **servicebus:** count deliveries after session lock expiry ([floci-io#645](floci-io#645)) ([ff31e3d](floci-io@ff31e3d))
* **servicebus:** restore stored entities when a broker starts ([floci-io#643](floci-io#643)) ([0d8dbab](floci-io@0d8dbab)), closes [floci-io#642](floci-io#642)
* **servicebus:** skip discarded journal disk tuning ([floci-io#606](floci-io#606)) ([db31031](floci-io@db31031)), closes [floci-io#605](floci-io#605)
* **storage:** answer an ARM container GET with the container's stored ETag and Last-Modified ([floci-io#617](floci-io#617)) ([f58abb4](floci-io@f58abb4))
* **storage:** answer an ARM container PUT with the container's stored ETag and Last-Modified ([floci-io#602](floci-io#602)) ([c5bbac8](floci-io@c5bbac8))
* **storage:** return the sku, kind and properties a PUT set ([floci-io#646](floci-io#646)) ([afc79e6](floci-io@afc79e6)), closes [floci-io#571](floci-io#571)
* **vm:** preserve request origin in polling URLs ([floci-io#628](floci-io#628)) ([9560864](floci-io@9560864)), closes [floci-io#626](floci-io#626)
* **vm:** report each power action's real outcome on its operation status ([floci-io#655](floci-io#655)) ([183f63d](floci-io@183f63d)), closes [floci-io#626](floci-io#626) [floci-io#626](floci-io#626)

### Features

* **arm:** refuse a token from another tenant under strict-tokens ([floci-io#619](floci-io#619)) ([fb76ca4](floci-io@fb76ca4))
* **arm:** refuse invalid Bearer tokens under strict-tokens ([floci-io#616](floci-io#616)) ([d6af59c](floci-io@d6af59c))
* **arm:** report each public region's physicalLocation ([floci-io#653](floci-io#653)) ([874b552](floci-io@874b552))
* **authorization:** serve role definitions and store role assignments ([floci-io#656](floci-io#656)) ([003a53c](floci-io@003a53c)), closes [floci-io#567](floci-io#567)
* **blob:** serve Set Blob Properties ([floci-io#654](floci-io#654)) ([d09366d](floci-io@d09366d))
* **deployments:** resolve Key Vault parameter references ([floci-io#641](floci-io#641)) ([3bcb475](floci-io@3bcb475)), closes [floci-io#635](floci-io#635) [floci-io#635](floci-io#635)
* **deployments:** serve deployments at management-group scope ([floci-io#640](floci-io#640)) ([0fe757d](floci-io@0fe757d))
* **deployments:** serve symbolic resource names (languageVersion 2.0) ([floci-io#637](floci-io#637)) ([17f00a3](floci-io@17f00a3))
* **deployments:** serve the CIDR functions and deployer ([floci-io#639](floci-io#639)) ([7fd4ade](floci-io@7fd4ade))
* **deployments:** serve the lambda functions and flatten ([floci-io#638](floci-io#638)) ([cddc4e0](floci-io@cddc4e0))
* **entra:** validate directory passwords and issue ROPC refresh tokens ([floci-io#633](floci-io#633)) ([9b2a464](floci-io@9b2a464)), closes [floci-io#632](floci-io#632)
* **tls:** answer for Azure's public hosts behind an opt-in setting ([floci-io#650](floci-io#650)) ([457de34](floci-io@457de34))
* **tls:** keep a trusted CA, accept your own, and warn when a client rejects the certificate ([floci-io#662](floci-io#662)) ([bac63e9](floci-io@bac63e9))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arm Azure Resource Manager (ARM) bug Something isn't working documentation Improvements or additions to documentation keyvault Azure Key Vault released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant