Skip to content

[KeyVault] Fix New-AzKeyVault RequestDisallowedByPolicy error by explicitly setting enableSoftDelete in the request body#29497

Open
rahulalapati43 wants to merge 2 commits intoAzure:mainfrom
rahulalapati43:fix/keyvault-soft-delete-policy
Open

[KeyVault] Fix New-AzKeyVault RequestDisallowedByPolicy error by explicitly setting enableSoftDelete in the request body#29497
rahulalapati43 wants to merge 2 commits intoAzure:mainfrom
rahulalapati43:fix/keyvault-soft-delete-policy

Conversation

@rahulalapati43
Copy link
Copy Markdown

@rahulalapati43 rahulalapati43 commented May 4, 2026

Description

Explicitly set EnableSoftDelete=true in the request body for New-AzKeyVault to satisfy Azure Policy checks that require the property to be present.

While soft delete is already enabled by default on the service side, Azure Policy checks may require the property to be explicitly present in the request body. Without it, New-AzKeyVault fails with a RequestDisallowedByPolicy error when such policies are enforced.

This is a non-breaking fix — no new parameters are exposed and customer behavior is unchanged.

Related CLI PR

Azure/azure-cli#33265

Testing Guide

Basic vault creation (should succeed without RequestDisallowedByPolicy)

New-AzKeyVault -Name -ResourceGroupName -Location

Verify soft delete is enabled on the created vault

(Get-AzKeyVault -VaultName ).EnableSoftDelete

Expected: True

Changes

  • \src/KeyVault/KeyVault/Commands/KeyVault/NewAzureKeyVault.cs\ — Changed EnableSoftDelete = null to EnableSoftDelete = true
  • \src/KeyVault/KeyVault.Test/UnitTests/NewAzureKeyVaultSoftDeleteTests.cs\ — Added unit test verifying the property is explicitly set
  • \src/KeyVault/KeyVault/ChangeLog.md\ — Added changelog entry

This checklist is used to make sure that common guidelines for a pull request are followed.

…ableSoftDelete

Explicitly set EnableSoftDelete=true in the request body for New-AzKeyVault
to satisfy Azure Policy checks that require the property to be present.
While soft delete is already enabled by default on the service side, Azure
Policy checks may require the property to be explicitly present in the
request body. Without it, New-AzKeyVault fails with a
RequestDisallowedByPolicy error when such policies are enforced.

This is a non-breaking fix - no new parameters are exposed and customer
behavior is unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 4, 2026 21:13
@azure-client-tools-bot-prd
Copy link
Copy Markdown

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the KeyVault module so New-AzKeyVault explicitly sends enableSoftDelete=true during vault creation, matching Azure Policy expectations and the related Azure CLI fix. It is a small, targeted change in the SDK-based KeyVault cmdlet plus accompanying release-note and test updates.

Changes:

  • Set EnableSoftDelete = true in New-AzKeyVault request construction.
  • Add a new unit test intended to validate soft-delete request behavior.
  • Add an upcoming release note for the policy-related fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/KeyVault/KeyVault/Commands/KeyVault/NewAzureKeyVault.cs Forces EnableSoftDelete into the create request body for new vaults.
src/KeyVault/KeyVault.Test/UnitTests/NewAzureKeyVaultSoftDeleteTests.cs Adds test coverage around soft-delete handling in vault creation.
src/KeyVault/KeyVault/ChangeLog.md Documents the fix for the next KeyVault release notes.

Comment thread src/KeyVault/KeyVault/Commands/KeyVault/NewAzureKeyVault.cs
@VeryEarly
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

Add a proper regression test that exercises NewAzureKeyVault.ExecuteCmdlet()
end-to-end and verifies that EnableSoftDelete=true is always present in the
outgoing SDK request body. This ensures Azure Policy checks requiring the
property to be present are satisfied.

The previous test only verified the pass-through client layer with
EnableSoftDelete already set to true in the input, so it would keep passing
even if the cmdlet's hardcoded assignment regressed.

New tests:
- ExecuteCmdlet_Sets_EnableSoftDelete_True_In_Request: full cmdlet path test
- VaultManagementClient_Does_Not_Default_EnableSoftDelete: proves client is
  a pure pass-through (null in = null out), establishing that only the
  cmdlet provides the value

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@VeryEarly
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

@notyashhh notyashhh added this to the Az 16.0.0 (06/02/2026) milestone May 5, 2026
@notyashhh notyashhh self-assigned this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants