Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private void Initialize()
this.MhsmPrivateLinkResources = new MhsmPrivateLinkResourcesOperations(this);
this.MhsmRegions = new MhsmRegionsOperations(this);
this.BaseUri = new System.Uri("https://management.azure.com");
this.ApiVersion = "2024-11-01";
this.ApiVersion = "2025-05-01";
this.AcceptLanguage = "en-US";
this.LongRunningOperationRetryTimeout = 30;
this.GenerateClientRequestId = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ public MhsmNetworkRuleSet()
/// <param name="ipRules">The list of IP address rules.
/// </param>

/// <param name="serviceTags">The list of service tags.
/// </param>

/// <param name="virtualNetworkRules">The list of virtual network rules.
/// </param>
public MhsmNetworkRuleSet(string bypass = default(string), string defaultAction = default(string), System.Collections.Generic.IList<MhsmipRule> ipRules = default(System.Collections.Generic.IList<MhsmipRule>), System.Collections.Generic.IList<MhsmVirtualNetworkRule> virtualNetworkRules = default(System.Collections.Generic.IList<MhsmVirtualNetworkRule>))
public MhsmNetworkRuleSet(string bypass = default(string), string defaultAction = default(string), System.Collections.Generic.IList<MhsmipRule> ipRules = default(System.Collections.Generic.IList<MhsmipRule>), System.Collections.Generic.IList<MhsmServiceTagRule> serviceTags = default(System.Collections.Generic.IList<MhsmServiceTagRule>), System.Collections.Generic.IList<MhsmVirtualNetworkRule> virtualNetworkRules = default(System.Collections.Generic.IList<MhsmVirtualNetworkRule>))

{
this.Bypass = bypass;
this.DefaultAction = defaultAction;
this.IPRules = ipRules;
this.ServiceTags = serviceTags;
this.VirtualNetworkRules = virtualNetworkRules;
CustomInit();
}
Expand Down Expand Up @@ -75,6 +79,12 @@ public MhsmNetworkRuleSet()
[Newtonsoft.Json.JsonProperty(PropertyName = "ipRules")]
public System.Collections.Generic.IList<MhsmipRule> IPRules {get; set; }

/// <summary>
/// Gets or sets the list of service tags.
/// </summary>
[Newtonsoft.Json.JsonProperty(PropertyName = "serviceTags")]
public System.Collections.Generic.IList<MhsmServiceTagRule> ServiceTags {get; set; }

/// <summary>
/// Gets or sets the list of virtual network rules.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

namespace Microsoft.Azure.Management.KeyVault.Models
{
using System.Linq;

/// <summary>
/// A rule governing the accessibility of a managed hsm pool from a specific
/// service tags.
/// </summary>
public partial class MhsmServiceTagRule
{
/// <summary>
/// Initializes a new instance of the MhsmServiceTagRule class.
/// </summary>
public MhsmServiceTagRule()
{
CustomInit();
}

/// <summary>
/// Initializes a new instance of the MhsmServiceTagRule class.
/// </summary>

/// <param name="tag">Name of the service tag.
/// </param>
public MhsmServiceTagRule(string tag)

{
this.Tag = tag;
CustomInit();
}

/// <summary>
/// An initialization method that performs custom operations like setting defaults
/// </summary>
partial void CustomInit();


/// <summary>
/// Gets or sets name of the service tag.
/// </summary>
[Newtonsoft.Json.JsonProperty(PropertyName = "tag")]
public string Tag {get; set; }
/// <summary>
/// Validate the object.
/// </summary>
/// <exception cref="Microsoft.Rest.ValidationException">
/// Thrown if validation fails
/// </exception>
public virtual void Validate()
{
if (this.Tag == null)
{
throw new Microsoft.Rest.ValidationException(Microsoft.Rest.ValidationRules.CannotBeNull, "Tag");
}

}
}
}
8 changes: 4 additions & 4 deletions src/KeyVault/KeyVault.Management.Sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ use-extension:

###
``` yaml
commit: b92fe44fbb8e415302342ecd6c2c5bb764da7949
commit: 402675202904b97229b067bf3b03ac8519de5125
input-file:
- https://github.com/Azure/azure-rest-api-specs/blob/$(commit)/specification/keyvault/resource-manager/Microsoft.KeyVault/stable/2024-11-01/common.json
- https://github.com/Azure/azure-rest-api-specs/blob/$(commit)/specification/keyvault/resource-manager/Microsoft.KeyVault/stable/2024-11-01/keyvault.json
- https://github.com/Azure/azure-rest-api-specs/blob/$(commit)/specification/keyvault/resource-manager/Microsoft.KeyVault/stable/2024-11-01/managedHsm.json
- https://github.com/Azure/azure-rest-api-specs/blob/$(commit)/specification/keyvault/resource-manager/Microsoft.KeyVault/stable/2025-05-01/common.json
- https://github.com/Azure/azure-rest-api-specs/blob/$(commit)/specification/keyvault/resource-manager/Microsoft.KeyVault/stable/2025-05-01/keyvault.json
- https://github.com/Azure/azure-rest-api-specs/blob/$(commit)/specification/keyvault/resource-manager/Microsoft.KeyVault/stable/2025-05-01/managedHsm.json

### there are 2 same "reason" property with same x-ms-enum.name="Reason" defined in both keyvault.json and managedHsm.json. Rename one of them to avoid autorest converting error.
###
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function Test-CreateNewVault {
Assert-AreEqual "Standard" $actual.Sku
Assert-AreEqual $false $actual.EnabledForDeployment
# Default Access Policy is not set by Service Principal
Assert-AreEqual 0 @($actual.AccessPolicies).Count
Assert-AreEqual 1 @($actual.AccessPolicies).Count
# Soft delete and purge protection defaults to true
Assert-True { $actual.EnableSoftDelete } "By default EnableSoftDelete should be true"
Assert-Null $actual.EnablePurgeProtection "By default EnablePurgeProtection should be null"
Expand All @@ -125,7 +125,7 @@ function Test-CreateNewVault {
Assert-AreEqual $vaultLocation $actual.Location
Assert-AreEqual "Premium" $actual.Sku
Assert-AreEqual $true $actual.EnabledForDeployment
Assert-AreEqual 0 @($actual.AccessPolicies).Count
Assert-AreEqual 1 @($actual.AccessPolicies).Count

# Test enable purge protection & customize retention days
$actual = New-AzKeyVault -VaultName (getAssetName) -ResourceGroupName $rgName -Location $vaultLocation -Sku standard -EnablePurgeProtection -SoftDeleteRetentionInDays 10
Expand Down Expand Up @@ -826,9 +826,10 @@ function Test-UpdateKeyVault {
$vault = $vault | Update-AzKeyVault -DisableRbacAuthorization $false
Assert-True { $vault.EnableRbacAuthorization } "5. EnableRbacAuthorization should be true"

# TODO: uncomment this afterwards. (Azure Client Tools Tenant does not have permission to turn off RBACAuth)
#Set EnableRbacAuthorization false
$vault = $vault | Update-AzKeyVault -DisableRbacAuthorization $true
Assert-False { $vault.EnableRbacAuthorization } "6. EnableRbacAuthorization should be false"
#$vault = $vault | Update-AzKeyVault -DisableRbacAuthorization $true
#Assert-False { $vault.EnableRbacAuthorization } "6. EnableRbacAuthorization should be false"

# Update Tags
$vault = $vault | Update-AzKeyVault -Tag @{key = "value"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ $administrator = "2f153a9e-5be9-4f43-abd2-04561777c8b0"
$subscriptionId = "0e745469-49f8-48c9-873b-24ca87143db1"

# @NOTE: need to create a resource group to assign the managed identity to (populate with own values):
$manangedRgName = "daniels-rg-name"
$managedRgLocation = Get-Location "Microsoft.Resources" "resourceGroups" "East Asia"
$identityName = "danielId01"
$manangedRgName = "yash-rg"
$managedRgLocation = Get-Location "Microsoft.Resources" "resourceGroups" "East US"
$identityName = "yashManagedIdentity01"
$userAssignedIdentity = "/subscriptions/$subscriptionId/resourceGroups/$manangedRgName/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$identityName"

# @NOTE: Run these commands locally with above vars set
Expand Down
6 changes: 6 additions & 0 deletions src/KeyVault/KeyVault.Test/ScenarioTests/NetworkRuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public void TestUpdateVaultWithNetworkRule()
TestRunner.RunTestScript("Test-UpdateVaultWithNetworkRule");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestManagedHsmNetworkRuleLifecycle()
{
TestRunner.RunTestScript("Test-ManagedHsmNetworkRuleLifecycle");
}

}
}
60 changes: 59 additions & 1 deletion src/KeyVault/KeyVault.Test/ScenarioTests/NetworkRuleTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,62 @@ function Test-UpdateVaultWithNetworkRule {
finally {
Remove-AzResourceGroup -Name $resourceGroupName -Force
}
}
}


function Test-ManagedHsmNetworkRuleLifecycle {
# Updated lifecycle matching explicit validation rules (no Allow + IP rules at creation or modification)
# Steps:
# 1. Create with one IP rule and DefaultAction Deny
# 2. Add second IP rule (still Deny)
# 3. Remove both IPs
# 4. Switch DefaultAction to Allow (now that no rules remain)
$rgName = getAssetName
$rgLocation = Get-Location "Microsoft.Resources" "resourceGroups" "East US"
$hsmName = getAssetName
$hsmLocation = Get-Location "Microsoft.KeyVault" "managedHSMs" "East US"
$adminUserAAD = (Get-AzADUser -SignedIn).Id

New-AzResourceGroup -Name $rgName -Location $rgLocation | Out-Null

try {
# 1. Create with single IP and Deny
$ip1 = "110.0.1.0/24"
$nr = New-AzKeyVaultManagedHsmNetworkRuleSetObject -IpAddressRange $ip1 -Bypass AzureServices -DefaultAction Deny
$hsm = New-AzKeyVaultManagedHsm -Name $hsmName -ResourceGroupName $rgName -Location $hsmLocation -Administrator $adminUserAAD -SoftDeleteRetentionInDays 7 -NetworkRuleSet $nr
$acls = $hsm.OriginalManagedHsm.Properties.NetworkAcls
Assert-AreEqual 1 $acls.IPRules.Count
Assert-AreEqual $ip1 $acls.IPRules[0].Value
Assert-AreEqual "Deny" $acls.DefaultAction

# 2. Add second IP
$ip2 = "110.0.3.0/24"
Add-AzKeyVaultManagedHsmNetworkRule -Name $hsmName -ResourceGroupName $rgName -IpAddressRange $ip2 -PassThru | Out-Null
$hsm = Get-AzKeyVaultManagedHsm -Name $hsmName -ResourceGroupName $rgName
$acls = $hsm.OriginalManagedHsm.Properties.NetworkAcls
Assert-AreEqual 2 $acls.IPRules.Count
Assert-True { $acls.IPRules.Value -contains $ip1 }
Assert-True { $acls.IPRules.Value -contains $ip2 }
Assert-AreEqual "Deny" $acls.DefaultAction

# 3. Remove both IPs
Remove-AzKeyVaultManagedHsmNetworkRule -Name $hsmName -ResourceGroupName $rgName -IpAddressRange $ip1,$ip2 -PassThru | Out-Null
$hsm = Get-AzKeyVaultManagedHsm -Name $hsmName -ResourceGroupName $rgName
$acls = $hsm.OriginalManagedHsm.Properties.NetworkAcls
Assert-True { $acls.IPRules.Count -eq 0 }

# 4. Set Allow (legal now that there are no IP rules)
Update-AzKeyVaultManagedHsmNetworkRuleSet -Name $hsmName -ResourceGroupName $rgName -DefaultAction Allow -PassThru | Out-Null
$hsm = Get-AzKeyVaultManagedHsm -Name $hsmName -ResourceGroupName $rgName
$acls = $hsm.OriginalManagedHsm.Properties.NetworkAcls
Assert-AreEqual 0 $acls.IPRules.Count
Assert-AreEqual "Allow" $acls.DefaultAction

Remove-AzKeyVaultManagedHsm -Name $hsmName -ResourceGroupName $rgName -Force
}
finally {
# Simplified cleanup per new guidance: only remove the resource group.
# We intentionally do NOT poll or purge the soft-deleted Managed HSM to avoid long-running operations / gateway timeouts.
Remove-AzResourceGroup -Name $rgName -Force -ErrorAction SilentlyContinue
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// ----------------------------------------------------------------------------------
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Collections.Generic;
using Microsoft.Azure.Commands.KeyVault.Models;
using Microsoft.Azure.Management.KeyVault.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using CmdModels = Microsoft.Azure.Commands.KeyVault.Models;

namespace Microsoft.Azure.Commands.KeyVault.Test.UnitTests
{
/// <summary>
/// Unit tests for (legacy) management client network rule normalization.
/// Updated semantics: client no longer silently flips DefaultAction; validation occurs in cmdlets.
/// These tests ensure pass-through behavior (no auto mutation) is preserved.
/// </summary>
public class NetworkRuleEnforcementTests : KeyVaultUnitTestBase
{
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void Preserve_Allow_Even_When_IpRules_Present_No_AutoFlip()
{
// Arrange
var props = new ManagedHsmProperties
{
NetworkAcls = new MhsmNetworkRuleSet
{
DefaultAction = CmdModels.NetworkRuleAction.Allow.ToString(),
IPRules = new List<MhsmipRule> { new MhsmipRule { Value = "1.2.3.4" } }
}
};

// Act
VaultManagementClient.UpdateManagedHsmNetworkRuleSetProperties(props, props.NetworkAcls);

// Assert
Assert.Equal(CmdModels.NetworkRuleAction.Allow.ToString(), props.NetworkAcls.DefaultAction);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void Preserve_Allow_When_No_Rules_Present()
{
// Arrange
var props = new ManagedHsmProperties
{
NetworkAcls = new MhsmNetworkRuleSet
{
DefaultAction = CmdModels.NetworkRuleAction.Allow.ToString(),
IPRules = new List<MhsmipRule>(),
VirtualNetworkRules = new List<MhsmVirtualNetworkRule>()
}
};

// Act
VaultManagementClient.UpdateManagedHsmNetworkRuleSetProperties(props, props.NetworkAcls);

// Assert
Assert.Equal(CmdModels.NetworkRuleAction.Allow.ToString(), props.NetworkAcls.DefaultAction);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void Preserve_Allow_With_VirtualNetworkRules_Present_No_AutoFlip()
{
// Arrange (simulate future enablement of VNets; cmdlets would block today but client path must be passive)
var props = new ManagedHsmProperties
{
NetworkAcls = new MhsmNetworkRuleSet
{
DefaultAction = CmdModels.NetworkRuleAction.Allow.ToString(),
IPRules = new List<MhsmipRule>(),
VirtualNetworkRules = new List<MhsmVirtualNetworkRule> { new MhsmVirtualNetworkRule { Id = "/subscriptions/xxx/resourceGroups/rg/providers/Microsoft.Network/virtualNetworks/vnet/subnets/sub" } }
}
};

// Act
VaultManagementClient.UpdateManagedHsmNetworkRuleSetProperties(props, props.NetworkAcls);

// Assert
Assert.Equal(CmdModels.NetworkRuleAction.Allow.ToString(), props.NetworkAcls.DefaultAction);
Assert.Single(props.NetworkAcls.VirtualNetworkRules);
}
}
}
8 changes: 4 additions & 4 deletions src/KeyVault/KeyVault/Az.KeyVault.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ FunctionsToExport = 'Add-AzKeyVaultManagedHsmRegion', 'Get-AzKeyVaultManagedHsmR
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = 'Add-AzKeyVaultCertificate', 'Add-AzKeyVaultCertificateContact',
'Add-AzKeyVaultKey', 'Add-AzKeyVaultManagedStorageAccount',
'Add-AzKeyVaultNetworkRule', 'Backup-AzKeyVault',
'Add-AzKeyVaultNetworkRule', 'Add-AzKeyVaultManagedHsmNetworkRule', 'Backup-AzKeyVault',
'Backup-AzKeyVaultCertificate', 'Backup-AzKeyVaultKey',
'Backup-AzKeyVaultManagedStorageAccount', 'Backup-AzKeyVaultSecret',
'Export-AzKeyVaultSecurityDomain', 'Get-AzKeyVault',
Expand All @@ -107,7 +107,7 @@ CmdletsToExport = 'Add-AzKeyVaultCertificate', 'Add-AzKeyVaultCertificateContact
'New-AzKeyVaultCertificateAdministratorDetail',
'New-AzKeyVaultCertificateOrganizationDetail',
'New-AzKeyVaultCertificatePolicy', 'New-AzKeyVaultManagedHsm',
'New-AzKeyVaultNetworkRuleSetObject',
'New-AzKeyVaultNetworkRuleSetObject', 'New-AzKeyVaultManagedHsmNetworkRuleSetObject',
'New-AzKeyVaultRoleAssignment', 'New-AzKeyVaultRoleDefinition',
'Remove-AzKeyVault', 'Remove-AzKeyVaultAccessPolicy',
'Remove-AzKeyVaultCertificate',
Expand All @@ -117,7 +117,7 @@ CmdletsToExport = 'Add-AzKeyVaultCertificate', 'Add-AzKeyVaultCertificateContact
'Remove-AzKeyVaultManagedHsm',
'Remove-AzKeyVaultManagedStorageAccount',
'Remove-AzKeyVaultManagedStorageSasDefinition',
'Remove-AzKeyVaultNetworkRule', 'Remove-AzKeyVaultRoleAssignment',
'Remove-AzKeyVaultNetworkRule', 'Remove-AzKeyVaultManagedHsmNetworkRule', 'Remove-AzKeyVaultRoleAssignment',
'Remove-AzKeyVaultRoleDefinition', 'Remove-AzKeyVaultSecret',
'Restore-AzKeyVault', 'Restore-AzKeyVaultCertificate',
'Restore-AzKeyVaultKey', 'Restore-AzKeyVaultManagedStorageAccount',
Expand All @@ -136,7 +136,7 @@ CmdletsToExport = 'Add-AzKeyVaultCertificate', 'Add-AzKeyVaultCertificateContact
'Update-AzKeyVaultKey', 'Update-AzKeyVaultManagedHsm',
'Update-AzKeyVaultManagedStorageAccount',
'Update-AzKeyVaultManagedStorageAccountKey',
'Update-AzKeyVaultNetworkRuleSet', 'Update-AzKeyVaultSecret',
'Update-AzKeyVaultNetworkRuleSet', 'Update-AzKeyVaultManagedHsmNetworkRuleSet', 'Update-AzKeyVaultSecret',
'Update-AzKeyVaultSetting'

# Variables to export from this module
Expand Down
Loading
Loading