Skip to content

Commit 1dff131

Browse files
sf-76wyunchi-ms
andauthored
[Compute] Adding Set-AzVmUefi, Set-AzVmssUefi, Set-AzVmSecurityType, Set-AzVmssSecurityType to support Trusted Launch (Azure#14479)
* Trusted Launch changes * Adding help markdown and change log update * Adding online version urls to Trusted Launch related cmdlets * Adding TrustedLaunch cmdlets to SignatureIssues.csv * Added the missing double quotes in SignatureIssues.csv Co-authored-by: Yunchi Wang <[email protected]>
1 parent 7e754cb commit 1dff131

File tree

14 files changed

+774
-2
lines changed

14 files changed

+774
-2
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
- 'Remove-AzContainerService'
2525
- 'Remove-AzContainerServiceAgentPoolProfile'
2626
- 'Update-AzContainerService'
27+
* Added new cmdlet `Set-AzVmUefi`
28+
* Added new cmdlet `Set-AzVmSecurityType`
29+
* Added new cmdlet `Set-AzVmssUefi`
30+
* Added new cmdlet `Set-AzVmssSecurityType`
31+
2732

2833
#### Az.ContainerRegistry
2934
* Fixed authentication for `Connect-AzContainerRegistry`

src/Accounts/Accounts/AzureRmAlias/Mappings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@
520520
"Remove-AzVmssDataDisk": "Remove-AzureRmVmssDataDisk",
521521
"Remove-AzVmssNetworkInterfaceConfiguration": "Remove-AzureRmVmssNetworkInterfaceConfiguration",
522522
"Set-AzVmssOsProfile": "Set-AzureRmVmssOsProfile",
523+
"Set-AzVmssSecurityType": "Set-AzureRmVmssSecurityType",
524+
"Set-AzVmssUefi": "Set-AzureRmVmssUefi",
523525
"Set-AzVmssStorageProfile": "Set-AzureRmVmssStorageProfile",
524526
"New-AzVmss": "New-AzureRmVmss",
525527
"Update-AzVmss": "Update-AzureRmVmss",

src/Compute/Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,26 @@ function Test-VirtualMachineProfileWithoutAUC
349349
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1;
350350
Assert-AreEqual $p.StorageProfile.DataDisks[1].Vhd.Uri $dataDiskVhdUri2;
351351

352+
# Verify Security Profile
353+
Assert-Null $p.SecurityProfile.UefiSettings.VtpmEnabled;
354+
Assert-Null $p.SecurityProfile.UefiSettings.SecureBootEnabled;
355+
356+
$p = Set-AzVmUefi -VM $p -EnableVtpm $true -EnableSecureBoot $true
357+
Assert-AreEqual $p.SecurityProfile.UefiSettings.VtpmEnabled $true;
358+
Assert-AreEqual $p.SecurityProfile.UefiSettings.SecureBootEnabled $true;
359+
360+
$p = Set-AzVmUefi -VM $p -EnableVtpm $true -EnableSecureBoot $false
361+
Assert-AreEqual $p.SecurityProfile.UefiSettings.VtpmEnabled $true;
362+
Assert-AreEqual $p.SecurityProfile.UefiSettings.SecureBootEnabled $false;
363+
364+
$p = Set-AzVmUefi -VM $p -EnableVtpm $false -EnableSecureBoot $true
365+
Assert-AreEqual $p.SecurityProfile.UefiSettings.VtpmEnabled $false;
366+
Assert-AreEqual $p.SecurityProfile.UefiSettings.SecureBootEnabled $true;
367+
368+
$p = Set-AzVmUefi -VM $p -EnableVtpm $false -EnableSecureBoot $false
369+
Assert-AreEqual $p.SecurityProfile.UefiSettings.VtpmEnabled $false;
370+
Assert-AreEqual $p.SecurityProfile.UefiSettings.SecureBootEnabled $false;
371+
352372
# Windows OS
353373
$user = "Foo12";
354374
$password = $PLACEHOLDER;

src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetProfileTests.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ function Test-VirtualMachineScaleSetProfile
112112
Assert-AreEqual 100 $vmss.VirtualMachineProfile.StorageProfile.DataDisks[0].DiskIOPSReadWrite;
113113
Assert-AreEqual 1000 $vmss.VirtualMachineProfile.StorageProfile.DataDisks[0].DiskMBpsReadWrite;
114114

115+
# Security Profile
116+
Assert-Null $vmss.VirtualMachineProfile.SecurityProfile.UefiSettings.VtpmEnabled;
117+
Assert-Null $vmss.VirtualMachineProfile.SecurityProfile.UefiSettings.SecureBootEnabled;
118+
119+
$vmss = Set-AzVmssUefi -VirtualMachineScaleSet $vmss -EnableVtpm $true -EnableSecureBoot $true
120+
Assert-AreEqual $vmss.VirtualMachineProfile.SecurityProfile.UefiSettings.VtpmEnabled $true;
121+
Assert-AreEqual $vmss.VirtualMachineProfile.SecurityProfile.UefiSettings.SecureBootEnabled $true;
122+
123+
$vmss = Set-AzVmssUefi -VirtualMachineScaleSet $vmss -EnableVtpm $true -EnableSecureBoot $false
124+
Assert-AreEqual $vmss.VirtualMachineProfile.SecurityProfile.UefiSettings.VtpmEnabled $true;
125+
Assert-AreEqual $vmss.VirtualMachineProfile.SecurityProfile.UefiSettings.SecureBootEnabled $false;
126+
127+
$vmss = Set-AzVmssUefi -VirtualMachineScaleSet $vmss -EnableVtpm $false -EnableSecureBoot $true
128+
Assert-AreEqual $vmss.VirtualMachineProfile.SecurityProfile.UefiSettings.VtpmEnabled $false;
129+
Assert-AreEqual $vmss.VirtualMachineProfile.SecurityProfile.UefiSettings.SecureBootEnabled $true;
130+
131+
$vmss = Set-AzVmssUefi -VirtualMachineScaleSet $vmss -EnableVtpm $false -EnableSecureBoot $false
132+
Assert-AreEqual $vmss.VirtualMachineProfile.SecurityProfile.UefiSettings.VtpmEnabled $false;
133+
Assert-AreEqual $vmss.VirtualMachineProfile.SecurityProfile.UefiSettings.SecureBootEnabled $false;
134+
135+
115136
# Extension profile
116137
Assert-AreEqual $extname $vmss.VirtualMachineProfile.ExtensionProfile.Extensions[0].Name;
117138
Assert-AreEqual $publisher $vmss.VirtualMachineProfile.ExtensionProfile.Extensions[0].Publisher;

src/Compute/Compute/Az.Compute.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ CmdletsToExport = 'Remove-AzAvailabilitySet', 'Get-AzAvailabilitySet',
100100
'Add-AzVMSshPublicKey', 'Add-AzVMSecret', 'Remove-AzVMSecret',
101101
'Remove-AzVMNetworkInterface', 'Remove-AzVMDataDisk',
102102
'Set-AzVMBootDiagnostic', 'Set-AzVMDataDisk', 'Set-AzVMPlan',
103-
'Set-AzVMSourceImage', 'Set-AzVMOSDisk',
103+
'Set-AzVMSourceImage', 'Set-AzVMOSDisk', 'Set-AzVmSecurityType', 'Set-AzVmUefi',
104104
'Get-AzVMBootDiagnosticsData', 'Get-AzVM', 'Update-AzVM',
105105
'Restart-AzVM', 'New-AzVM', 'Start-AzVM', 'Stop-AzVM', 'Remove-AzVM',
106106
'New-AzVMConfig', 'Set-AzVMOperatingSystem', 'Add-AzVMDataDisk',
@@ -112,7 +112,7 @@ CmdletsToExport = 'Remove-AzAvailabilitySet', 'Get-AzAvailabilitySet',
112112
'New-AzVmssConfig', 'New-AzVmssIpConfig',
113113
'New-AzVmssVaultCertificateConfig', 'Remove-AzVmssExtension',
114114
'Remove-AzVmssDataDisk',
115-
'Remove-AzVmssNetworkInterfaceConfiguration', 'Set-AzVmssOsProfile',
115+
'Remove-AzVmssNetworkInterfaceConfiguration', 'Set-AzVmssOsProfile', 'Set-AzVmssSecurityType', 'Set-AzVmssUefi',
116116
'Set-AzVmssStorageProfile', 'New-AzVmss', 'Update-AzVmss',
117117
'Stop-AzVmss', 'Remove-AzVmss', 'Get-AzVmss', 'Get-AzVmssSku',
118118
'Set-AzVmss', 'Restart-AzVmss', 'Start-AzVmss', 'Update-AzVmssInstance',
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// Copyright (c) Microsoft and contributors. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
// Warning: This code was generated by a tool.
18+
//
19+
// Changes to this file may cause incorrect behavior and will be lost if the
20+
// code is regenerated.
21+
22+
using System;
23+
using System.Collections;
24+
using System.Collections.Generic;
25+
using System.Linq;
26+
using System.Management.Automation;
27+
using Microsoft.Azure.Commands.Compute.Automation.Models;
28+
using Microsoft.Azure.Management.Compute.Models;
29+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
30+
31+
namespace Microsoft.Azure.Commands.Compute.Automation
32+
{
33+
[Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssSecurityType")]
34+
[OutputType(typeof(PSVirtualMachineScaleSet))]
35+
public partial class SetAzureRmVmssSecurityTypeCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
36+
{
37+
[Parameter(
38+
Mandatory = true,
39+
Position = 0,
40+
ValueFromPipeline = true,
41+
ValueFromPipelineByPropertyName = true)]
42+
public PSVirtualMachineScaleSet VirtualMachineScaleSet { get; set; }
43+
44+
[Parameter(
45+
HelpMessage = "Parameter to toggle vTPM on the VMs of the scale set",
46+
Mandatory = false,
47+
Position = 1,
48+
ValueFromPipelineByPropertyName = true)]
49+
public SecurityTypes SecurityType { get; set; }
50+
51+
protected override void ProcessRecord()
52+
{
53+
Run();
54+
}
55+
56+
private void Run()
57+
{
58+
if (this.IsParameterBound(c => c.SecurityType))
59+
{
60+
// Security Profile
61+
if (this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile == null)
62+
{
63+
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile = new SecurityProfile();
64+
}
65+
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile.SecurityType = SecurityType;
66+
}
67+
68+
WriteObject(this.VirtualMachineScaleSet);
69+
}
70+
71+
}
72+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//
2+
// Copyright (c) Microsoft and contributors. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
// Warning: This code was generated by a tool.
18+
//
19+
// Changes to this file may cause incorrect behavior and will be lost if the
20+
// code is regenerated.
21+
22+
using System;
23+
using System.Collections;
24+
using System.Collections.Generic;
25+
using System.Linq;
26+
using System.Management.Automation;
27+
using Microsoft.Azure.Commands.Compute.Automation.Models;
28+
using Microsoft.Azure.Management.Compute.Models;
29+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
30+
31+
namespace Microsoft.Azure.Commands.Compute.Automation
32+
{
33+
[Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssUefi")]
34+
[OutputType(typeof(PSVirtualMachineScaleSet))]
35+
public partial class SetAzureRmVmssUefiCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
36+
{
37+
[Parameter(
38+
Mandatory = true,
39+
Position = 0,
40+
ValueFromPipeline = true,
41+
ValueFromPipelineByPropertyName = true)]
42+
public PSVirtualMachineScaleSet VirtualMachineScaleSet { get; set; }
43+
44+
[Parameter(
45+
HelpMessage = "Parameter to toggle vTPM on the VMs of the scale set",
46+
Mandatory = false,
47+
Position = 1,
48+
ValueFromPipelineByPropertyName = true)]
49+
public bool EnableVtpm { get; set; }
50+
51+
[Parameter(
52+
HelpMessage = "Parameter to toggle secure boot on the VMs of the scale set",
53+
Mandatory = false,
54+
Position = 2,
55+
ValueFromPipelineByPropertyName = true)]
56+
public bool EnableSecureBoot { get; set; }
57+
58+
protected override void ProcessRecord()
59+
{
60+
Run();
61+
}
62+
63+
private void Run()
64+
{
65+
if (this.IsParameterBound(c => c.EnableVtpm))
66+
{
67+
// Security Profile
68+
if (this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile == null)
69+
{
70+
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile = new SecurityProfile();
71+
}
72+
73+
// Uefi Settings
74+
if (this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile.UefiSettings == null)
75+
{
76+
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile.UefiSettings = new UefiSettings();
77+
}
78+
79+
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile.UefiSettings.VTpmEnabled = this.EnableVtpm;
80+
}
81+
82+
if (this.IsParameterBound(c => c.EnableSecureBoot))
83+
{
84+
// Security Profile
85+
if (this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile == null)
86+
{
87+
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile = new SecurityProfile();
88+
}
89+
90+
// Uefi Settings
91+
if (this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile.UefiSettings == null)
92+
{
93+
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile.UefiSettings = new UefiSettings();
94+
}
95+
96+
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile.UefiSettings.SecureBootEnabled = this.EnableSecureBoot;
97+
}
98+
99+
WriteObject(this.VirtualMachineScaleSet);
100+
}
101+
}
102+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Text;
19+
using System.Management.Automation;
20+
using Microsoft.Azure.Commands.Compute.Common;
21+
using Microsoft.Azure.Commands.Compute.Models;
22+
using Microsoft.Azure.Management.Compute.Models;
23+
24+
namespace Microsoft.Azure.Commands.Compute
25+
{
26+
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VMSecurityType"), OutputType(typeof(PSVirtualMachine))]
27+
public class SetAzureVMSecurityType : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
28+
{
29+
[Alias("VMProfile")]
30+
[Parameter(
31+
Mandatory = true,
32+
Position = 0,
33+
ValueFromPipeline = true,
34+
ValueFromPipelineByPropertyName = true,
35+
HelpMessage = HelpMessages.VMProfile)]
36+
[ValidateNotNullOrEmpty]
37+
public PSVirtualMachine VM { get; set; }
38+
39+
[Parameter(
40+
Mandatory = false,
41+
ValueFromPipelineByPropertyName = true)]
42+
public SecurityTypes SecurityType { get; set; }
43+
44+
public override void ExecuteCmdlet()
45+
{
46+
if(this.VM.SecurityProfile == null)
47+
{
48+
this.VM.SecurityProfile = new SecurityProfile();
49+
}
50+
51+
this.VM.SecurityProfile.SecurityType = SecurityType;
52+
53+
WriteObject(this.VM);
54+
}
55+
}
56+
57+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Text;
19+
using System.Management.Automation;
20+
using Microsoft.Azure.Commands.Compute.Common;
21+
using Microsoft.Azure.Commands.Compute.Models;
22+
using Microsoft.Azure.Management.Compute.Models;
23+
24+
namespace Microsoft.Azure.Commands.Compute
25+
{
26+
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VMUefi"), OutputType(typeof(PSVirtualMachine))]
27+
public class SetAzureVMUefi : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
28+
{
29+
[Alias("VMProfile")]
30+
[Parameter(
31+
Mandatory = true,
32+
Position = 0,
33+
ValueFromPipeline = true,
34+
ValueFromPipelineByPropertyName = true,
35+
HelpMessage = HelpMessages.VMProfile)]
36+
[ValidateNotNullOrEmpty]
37+
public PSVirtualMachine VM { get; set; }
38+
39+
[Parameter(
40+
Mandatory = false,
41+
ValueFromPipelineByPropertyName = true)]
42+
public bool EnableVtpm { get; set; }
43+
44+
[Parameter(
45+
Mandatory = false,
46+
ValueFromPipelineByPropertyName = true)]
47+
public bool EnableSecureBoot { get; set; }
48+
49+
public override void ExecuteCmdlet()
50+
{
51+
if(this.VM.SecurityProfile == null)
52+
{
53+
this.VM.SecurityProfile = new SecurityProfile();
54+
}
55+
this.VM.SecurityProfile.UefiSettings = new UefiSettings
56+
{
57+
VTpmEnabled = this.EnableVtpm,
58+
SecureBootEnabled = this.EnableSecureBoot
59+
};
60+
61+
WriteObject(this.VM);
62+
}
63+
}
64+
65+
}

0 commit comments

Comments
 (0)