Skip to content

Commit 5098317

Browse files
authored
Merge pull request #6040 from ejarvi/singlepass
Set-AzureRmVmDiskEncryptionExtension makes AAD parameters optional
2 parents a3d6899 + 8f8bba5 commit 5098317

File tree

15 files changed

+7404
-47
lines changed

15 files changed

+7404
-47
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/EnvironmentSetupHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ public virtual Collection<PSObject> RunPowerShellTest(params string[] scripts)
592592
d.Add("Microsoft.Features", null);
593593
d.Add("Microsoft.Authorization", null);
594594
d.Add("Microsoft.Compute", null);
595+
d.Add("Microsoft.Azure.Management.KeyVault", null);
595596
var providersToIgnore = new Dictionary<string, string>();
596597
providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");
597598
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore);

src/ResourceManager/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* Set minimum dependency of module to PowerShell 5.0
2929
* Introduce multiple breaking changes
3030
- Please refer to the migration guide for more details
31+
* `Set-AzureRmVmDiskEncryptionExtension` makes AAD parameters optional
3132

3233
## Version 4.6.0
3334
* `Get-AzureRmVmssDiskEncryptionStatus` supports encryption status at data disk level

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
<Reference Include="Microsoft.Azure.Management.Compute">
6767
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.18.0.0\lib\net452\Microsoft.Azure.Management.Compute.dll</HintPath>
6868
</Reference>
69+
<Reference Include="Microsoft.Azure.Management.KeyVault, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
70+
<SpecificVersion>False</SpecificVersion>
71+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.KeyVault.2.3.0-preview\lib\net452\Microsoft.Azure.Management.KeyVault.dll</HintPath>
72+
</Reference>
6973
<Reference Include="Microsoft.Azure.Management.Network, Version=17.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7074
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.17.0.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
7175
<Private>True</Private>
@@ -393,6 +397,9 @@
393397
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.StrategiesVmssTests\TestSimpleNewVmssWithUserAssignedIdentity.json">
394398
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
395399
</None>
400+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\TestAzureDiskEncryptionExtensionSinglePass.json">
401+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
402+
</None>
396403
<None Include="Templates\azuredeploy.json">
397404
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
398405
</None>

src/ResourceManager/Compute/Commands.Compute.Test/Common/ComputeTestController.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Azure.Graph.RBAC;
1818
using Microsoft.Azure.Management.Authorization;
1919
using Microsoft.Azure.Management.Compute;
20+
using Microsoft.Azure.Management.KeyVault;
2021
using Microsoft.Azure.Management.Network;
2122
using Microsoft.Azure.Management.Resources;
2223
using Microsoft.Azure.Management.Storage;
@@ -54,9 +55,10 @@ public sealed class ComputeTestController : RMTestBase
5455

5556
public AuthorizationManagementClient AuthorizationManagementClient { get; private set; }
5657

57-
5858
public StorageManagementClient StorageClient { get; private set; }
5959

60+
public KeyVaultManagementClient KeyVaultManagementClient { get; private set; }
61+
6062
public NetworkManagementClient NetworkManagementClient { get; private set; }
6163

6264
public ComputeManagementClient ComputeManagementClient { get; private set; }
@@ -189,6 +191,7 @@ private void SetupManagementClients(RestTestFramework.MockContext context)
189191
StorageClient = GetStorageManagementClient(context);
190192
GalleryClient = GetGalleryClient();
191193
//var eventsClient = GetEventsClient();
194+
KeyVaultManagementClient = GetKeyVaultManagementClient(context);
192195
NetworkManagementClient = this.GetNetworkManagementClientClient(context);
193196
ComputeManagementClient = GetComputeManagementClient(context);
194197
AuthorizationManagementClient = GetAuthorizationManagementClient();
@@ -202,6 +205,7 @@ private void SetupManagementClients(RestTestFramework.MockContext context)
202205
StorageClient,
203206
GalleryClient,
204207
//eventsClient,
208+
KeyVaultManagementClient,
205209
NetworkManagementClient,
206210
ComputeManagementClient,
207211
AuthorizationManagementClient,
@@ -277,6 +281,13 @@ private GalleryClient GetGalleryClient()
277281
// return TestBase.GetServiceClient<EventsClient>(this.csmTestFactory);
278282
//}
279283

284+
private KeyVaultManagementClient GetKeyVaultManagementClient(RestTestFramework.MockContext context)
285+
{
286+
return testViaCsm
287+
? context.GetServiceClient<KeyVaultManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment())
288+
: TestBase.GetServiceClient<KeyVaultManagementClient>(new RDFETestEnvironmentFactory());
289+
}
290+
280291
private NetworkManagementClient GetNetworkManagementClientClient(RestTestFramework.MockContext context)
281292
{
282293
return testViaCsm

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ComputeTestCommon.ps1

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,65 @@ function Get-ComputeDefaultLocation
9494
return $test_location;
9595
}
9696

97+
# Create key vault resources
98+
function Create-KeyVault
99+
{
100+
Param
101+
(
102+
[Parameter(Mandatory=$true, Position=0)]
103+
[string] $resourceGroupName,
104+
[Parameter(Mandatory=$true, Position=1)]
105+
[string] $location,
106+
[Parameter(Mandatory=$false, Position=2)]
107+
[string] $vaultName
108+
)
109+
110+
# initialize parameters if needed
111+
if ([string]::IsNullOrEmpty($resourceGroupName)) { $resourceGroupName = Get-ComputeTestResourceName }
112+
if ([string]::IsNullOrEmpty($location)) { $location = Get-ComputeVMLocation }
113+
if ([string]::IsNullOrEmpty($vaultName)) { $vaultName = 'kv' + $resourceGroupName }
114+
115+
# create vault
116+
$vault = New-AzureRmKeyVault -VaultName $vaultName -ResourceGroupName $resourceGroupName -Location $location -Sku standard
117+
$vault = Get-AzureRmKeyVault -VaultName $vaultName -ResourceGroupName $resourceGroupName
118+
119+
# create access policy
120+
$servicePrincipalName = (Get-AzureRmContext).Account.Id
121+
Assert-NotNull $servicePrincipalName
122+
#Set-AzureRmKeyVaultAccessPolicy -VaultName $vaultName -ResourceGroupName $resourceGroupName -ServicePrincipalName $servicePrincipalName -PermissionsToKeys Create
123+
Set-AzureRmKeyVaultAccessPolicy -VaultName $vaultName -ResourceGroupName $resourceGroupName -EnabledForDiskEncryption -EnabledForDeployment -EnabledForTemplateDeployment
124+
125+
# create key encryption key
126+
#$kekName = 'kek' + $resourceGroupName
127+
#$kek = Add-AzureKeyVaultKey -VaultName $vaultName -Name $kekName -Destination "Software"
128+
129+
# return the newly created key vault properties
130+
$properties = New-Object PSObject -Property @{
131+
DiskEncryptionKeyVaultId = $vault.ResourceId
132+
DiskEncryptionKeyVaultUrl = $vault.VaultUri
133+
#KeyEncryptionKeyVaultId = $vault.ResourceId
134+
#KeyEncryptionKeyUrl = $kek.Key.kid
135+
}
136+
return $properties
137+
}
138+
97139
# Create a new virtual machine with other necessary resources configured
98-
function Create-VirtualMachine($rgname, $vmname, $loc)
99-
{
100-
# Initialize parameters
101-
$rgname = if ([string]::IsNullOrEmpty($rgname)) { Get-ComputeTestResourceName } else { $rgname }
102-
$vmname = if ([string]::IsNullOrEmpty($vmname)) { 'vm' + $rgname } else { $vmname }
103-
$loc = if ([string]::IsNullOrEmpty($loc)) { Get-ComputeVMLocation } else { $loc }
104-
Write-Host $vmname
140+
function Create-VirtualMachine
141+
{
142+
Param
143+
(
144+
[Parameter(Mandatory=$false, Position=0)]
145+
[string] $rgname,
146+
[Parameter(Mandatory=$false, Position=1)]
147+
[string] $vmname,
148+
[Parameter(Mandatory=$false, Position=2)]
149+
[string] $loc
150+
)
151+
152+
# initialize parameters if needed
153+
if ([string]::IsNullOrEmpty($rgname)) { $rgname = Get-ComputeTestResourceName }
154+
if ([string]::IsNullOrEmpty($vmname)) { $vmname = 'vm' + $rgname }
155+
if ([string]::IsNullOrEmpty($loc)) { $loc = Get-ComputeVMLocation }
105156

106157
# Common
107158
$g = New-AzureRmResourceGroup -Name $rgname -Location $loc -Force;

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineExtensionTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ public void TestAzureDiskEncryptionExtension()
8080
ComputeTestController.NewInstance.RunPsTest("Test-AzureDiskEncryptionExtension");
8181
}
8282

83+
[Fact(Skip = "TODO: only works for live mode due to key vault dependency")]
84+
[Trait(Category.RunType, Category.LiveOnly)]
85+
public void TestAzureDiskEncryptionExtensionSinglePass()
86+
{
87+
ComputeTestController.NewInstance.RunPsTest("Test-AzureDiskEncryptionExtensionSinglePass");
88+
}
89+
8390
[Fact]
8491
[Trait(Category.AcceptanceType, Category.CheckIn)]
8592
public void TestVirtualMachineBginfoExtension()

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineExtensionTests.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,45 @@ function Test-VirtualMachineAccessExtension
10271027
}
10281028
}
10291029

1030+
<#
1031+
.SYNOPSIS
1032+
Test the Set-AzureRmVMDiskEncryptionExtension single pass scenario
1033+
#>
1034+
function Test-AzureDiskEncryptionExtensionSinglePass
1035+
{
1036+
$resourceGroupName = Get-ComputeTestResourceName
1037+
try
1038+
{
1039+
# create virtual machine and key vault prerequisites
1040+
$vm = Create-VirtualMachine $resourceGroupName
1041+
$kv = Create-KeyVault $vm.ResourceGroupName $vm.Location
1042+
1043+
# enable encryption with single pass syntax (omits AD parameters)
1044+
Set-AzureRmVMDiskEncryptionExtension `
1045+
-ResourceGroupName $vm.ResourceGroupName `
1046+
-VMName $vm.Name `
1047+
-DiskEncryptionKeyVaultUrl $kv.DiskEncryptionKeyVaultUrl `
1048+
-DiskEncryptionKeyVaultId $kv.DiskEncryptionKeyVaultId `
1049+
-Force
1050+
1051+
# verify encryption state
1052+
$status = Get-AzureRmVmDiskEncryptionStatus -ResourceGroupName $vm.ResourceGroupName -VMName $vm.Name
1053+
Assert-NotNull $status
1054+
Assert-AreEqual $status.OsVolumeEncrypted Encrypted
1055+
Assert-AreEqual $status.DataVolumesEncrypted NotEncrypted
1056+
1057+
# verify encryption settings
1058+
$settings = $status.OsVolumeEncryptionSettings
1059+
Assert-NotNull $settings
1060+
Assert-NotNull $settings.DiskEncryptionKey.SecretUrl
1061+
Assert-NotNull $settings.DiskEncryptionKey.SourceVault
1062+
}
1063+
finally
1064+
{
1065+
Clean-ResourceGroup($resourceGroupName)
1066+
}
1067+
}
1068+
10301069
<#
10311070
.SYNOPSIS
10321071
Test AzureDiskEncryption extension

src/ResourceManager/Compute/Commands.Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests/TestAzureDiskEncryptionExtensionSinglePass.json

Lines changed: 7040 additions & 0 deletions
Large diffs are not rendered by default.

src/ResourceManager/Compute/Commands.Compute.Test/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<package id="Microsoft.Azure.Graph.RBAC" version="3.4.0-preview" targetFramework="net452" />
88
<package id="Microsoft.Azure.Management.Authorization" version="2.0.0" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Compute" version="18.0.0" targetFramework="net452" />
10+
<package id="Microsoft.Azure.Management.KeyVault" version="2.3.0-preview" targetFramework="net452" />
1011
<package id="Microsoft.Azure.Management.Network" version="17.0.0-preview" targetFramework="net452" />
1112
<package id="Microsoft.Azure.Management.Storage" version="4.1.0-preview" targetFramework="net45" />
1213
<package id="Microsoft.Azure.Test.Framework" version="1.0.6179.26854-prerelease" targetFramework="net45" />

src/ResourceManager/Compute/Commands.Compute/Extension/AzureDiskEncryption/AzureDiskEncryptionExtensionConstants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
namespace Microsoft.Azure.Commands.Compute.Extension.AzureDiskEncryption
1616
{
1717
/// <summary>
18-
/// This class includes contant values used in AzureDiskEncryption
18+
/// This class includes constant values used in AzureDiskEncryption
1919
/// </summary>
2020
public static class AzureDiskEncryptionExtensionConstants
2121
{
22+
public const string singlePassParameterSet = "SinglePassParameterSet";
2223
public const string aadClientCertParameterSet = "AADClientCertParameterSet";
2324
public const string aadClientSecretParameterSet = "AADClientSecretParameterSet";
2425
public const string enableEncryptionOperation = "EnableEncryption";

src/ResourceManager/Compute/Commands.Compute/Extension/AzureDiskEncryption/AzureDiskEncryptionExtensionContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ public class AzureDiskEncryptionExtensionContext : PSVirtualMachineExtension
2727
public const string LinuxExtensionDefaultName = "AzureDiskEncryptionForLinux";
2828
public const string LinuxExtensionDefaultType = "AzureDiskEncryptionForLinux";
2929
public const string LinuxExtensionDefaultVersion = "0.1";
30+
public const string LinuxExtensionSinglePassVersion = "1.1";
3031

3132
public const string ExtensionDefaultPublisher = "Microsoft.Azure.Security";
3233
public const string ExtensionDefaultName = "AzureDiskEncryption";
3334
public const string ExtensionDefaultType = "AzureDiskEncryption";
3435
public const string ExtensionDefaultVersion = "1.1";
36+
public const string ExtensionSinglePassVersion = "2.2";
3537
public const string VolumeTypeOS = "OS";
3638
public const string VolumeTypeData = "Data";
3739
public const string VolumeTypeAll = "All";

0 commit comments

Comments
 (0)