Skip to content

Commit 716f948

Browse files
SandidoVeryEarly
andauthored
Adding help doc and changelog for New-AzVmss DisableIntegrityMonitoring new parameter (#18829)
* Update VirtualMachineTests.ps1 * Update ChangeLog.md * Update New-AzVM.md * Update New-AzVmss.md * Update New-AzVM.md * Update New-AzVmss.md Co-authored-by: Yabo Hu <[email protected]>
1 parent db939f0 commit 716f948

File tree

4 files changed

+157
-23
lines changed

4 files changed

+157
-23
lines changed

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5798,7 +5798,13 @@ function Test-VirtualMachinePlatformFaultDomain
57985798

57995799
<#
58005800
.SYNOPSIS
5801-
Test GuestAttestation
5801+
Test GuestAttestation defaulting behavior.
5802+
1) SecurityType is TrustedLaunch.
5803+
2) EnableVtpm is true.
5804+
3) EnabledSecureBoot is true.
5805+
4) DisableIntegrityMonitoring is not true.
5806+
Then this test removes the VM and recreates it with -DisableIntegrityMonitoring set to true so the
5807+
Guest Attestation extension is not installed.
58025808
#>
58035809
function Test-VirtualMachineGuestAttestation
58045810
{
@@ -5872,4 +5878,4 @@ function Test-VirtualMachineGuestAttestation
58725878
# Cleanup
58735879
Clean-ResourceGroup $rgname;
58745880
}
5875-
}
5881+
}

src/Compute/Compute/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
## Upcoming Release
2323
* Added image alias 'Win2022AzureEditionCore'
2424
* Added the `-DisableIntegrityMonitoring` switch parameter to the `New-AzVM` cmdlet.
25-
Changed the default behavior for `New-AzVM` when these conditions are met:
25+
Changed the default behavior for `New-AzVM` and `New-AzVmss` when these conditions are met:
2626
1) `-DisableIntegrityMonitoring` is not true.
2727
2) `SecurityType` on the SecurityProfile is `TrustedLaunch`.
2828
3) `VTpmEnabled` on the SecurityProfile is true.
2929
4) `SecureBootEnabled` on the SecurityProfile is true.
3030
Now `New-AzVM` will install the `Guest Attestation` extension to the new VM when these conditions are met.
31+
Now `New-AzVmss` will install the `Guest Attestation` extension to the new Vmss when these conditions are met and installed to all VM instances in the Vmss.
3132
* Added `-UserAssignedIdentity` and `-FederatedClientId` to the following cmdlets:
3233
- `New-AzDiskEncryptionSetConfig`
3334
- `Update-AzDiskEncryptionSet`

src/Compute/Compute/help/New-AzVM.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,70 @@ $vmss = New-AzVmss -ResourceGroupName $resourceGroupName -Name $vmssName -Virtua
241241
$vm = New-AzVM -ResourceGroupName $resourceGroupName -Name $vmname -Credential $cred -DomainNameLabel $domainNameLabel -PlatformFaultDomain $platformFaultDomainVMDefaultSet -VmssId $vmss.Id
242242
```
243243

244+
### Example 7: Creating a new VM with the GuestAttestation extension installed by default, then recreating the VM with DisableIntegrityMonitoring to prevent this.
245+
```
246+
$rgname = <RESOURCE GROUP NAME>;
247+
$loc = <AZURE REGION>;
248+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
249+
250+
# VM Profile & Hardware
251+
$vmname = 'vm' + $rgname;
252+
$domainNameLabel = "d1" + $rgname;
253+
$vnetname = "myVnet";
254+
$vnetAddress = "10.0.0.0/16";
255+
$subnetname = "slb" + $rgname;
256+
$subnetAddress = "10.0.2.0/24";
257+
$OSDiskName = $vmname + "-osdisk";
258+
$NICName = $vmname+ "-nic";
259+
$NSGName = $vmname + "-NSG";
260+
$OSDiskSizeinGB = 128;
261+
$VMSize = "Standard_DS2_v2";
262+
$PublisherName = "MicrosoftWindowsServer";
263+
$Offer = "WindowsServer";
264+
$SKU = "2019-DATACENTER-GENSECOND";
265+
$securityType = "TrustedLaunch";
266+
$secureboot = $true;
267+
$vtpm = $true;
268+
269+
# Default extension and identity values.
270+
$extDefaultName = "GuestAttestation";
271+
$vmGADefaultIDentity = "SystemAssigned";
272+
273+
# Credential
274+
$password = <PASSWORD>;
275+
$securePassword = $password | ConvertTo-SecureString -AsPlainText -Force;
276+
$user = <USER NAME>;
277+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
278+
279+
# Network resources
280+
$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name $subnetname -AddressPrefix $subnetAddress;
281+
$vnet = New-AzVirtualNetwork -Name $vnetname -ResourceGroupName $rgname -Location $loc -AddressPrefix $vnetAddress -Subnet $frontendSubnet;
282+
$nsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name RDP -Protocol Tcp -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow;
283+
$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $RGName -Location $loc -Name $NSGName -SecurityRules $nsgRuleRDP;
284+
$nic = New-AzNetworkInterface -Name $NICName -ResourceGroupName $RGName -Location $loc -SubnetId $vnet.Subnets[0].Id -NetworkSecurityGroupId $nsg.Id -EnableAcceleratedNetworking;
285+
286+
# VM creation
287+
$vmConfig = New-AzVMConfig -VMName $vmName -VMSize $VMSize;
288+
Set-AzVMOperatingSystem -VM $vmConfig -Windows -ComputerName $vmName -Credential $cred;
289+
Set-AzVMSourceImage -VM $vmConfig -PublisherName $PublisherName -Offer $Offer -Skus $SKU -Version latest;
290+
Add-AzVMNetworkInterface -VM $vmConfig -Id $nic.Id;
291+
$vmConfig = Set-AzVMSecurityProfile -VM $vmConfig -SecurityType $securityType;
292+
$vmConfig = Set-AzVmUefi -VM $vmConfig -EnableVtpm $vtpm -EnableSecureBoot $secureboot;
293+
New-AzVM -ResourceGroupName $RGName -Location $loc -VM $vmConfig;
294+
295+
# Verify values
296+
$vm = Get-AzVm -ResourceGroupName $rgname -Name $vmName;
297+
$vmExt = Get-AzVMExtension -ResourceGroupName $rgname -VMName $vmName -Name $extDefaultName;
298+
# Check the default extension has been installed, and the Identity.Type defaulted to SystemAssigned.
299+
# $vmExt.Name
300+
# $vm.Identity.Type
301+
302+
# Use the DisableIntegrityMonitoring parameter
303+
Remove-AzVm -ResourceGroupName $rgname -Name $vmname -Force;
304+
New-AzVM -ResourceGroupName $rgname -Location $loc -VM $vmConfig -DisableIntegrityMonitoring;
305+
# This VM does not have the Guest Attestation extension installed on it, and the Identity is not set to SystemAssigned by default.
306+
```
307+
244308
## PARAMETERS
245309

246310
### -AddressPrefix

src/Compute/Compute/help/New-AzVmss.md

Lines changed: 83 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Creates a VMSS.
1616
### DefaultParameter (Default)
1717
```
1818
New-AzVmss [-ResourceGroupName] <String> [-VMScaleSetName] <String>
19-
[-VirtualMachineScaleSet] <PSVirtualMachineScaleSet> [-AsJob] [-EdgeZone <String>]
19+
[-VirtualMachineScaleSet] <PSVirtualMachineScaleSet> [-DisableIntegrityMonitoring] [-AsJob] [-EdgeZone <String>]
2020
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2121
```
2222

@@ -147,25 +147,6 @@ $VMSS = New-AzVmssConfig -Location $LOC -SkuCapacity 2 -SkuName "Standard_E4-2ds
147147
New-AzVmss -ResourceGroupName $RGName -Name $VMSSName -VirtualMachineScaleSet $VMSS;
148148
```
149149

150-
### Example 3: Create a VMSS with a UserData value
151-
```powershell
152-
$ResourceGroupName = 'RESOURCE GROUP NAME';
153-
$vmssName = 'VMSSNAME';
154-
$domainNameLabel = "dnl" + $ResourceGroupName;
155-
# Create credentials, I am using one way to create credentials, there are others as well.
156-
# Pick one that makes the most sense according to your use case.
157-
$vmPassword = ConvertTo-SecureString 'PASSWORD' -AsPlainText -Force;
158-
$vmCred = New-Object System.Management.Automation.PSCredential('USERNAME', $vmPassword);
159-
160-
$text = "UserData value to encode";
161-
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text);
162-
$userData = [Convert]::ToBase64String($bytes);
163-
164-
#Create a VMSS
165-
New-AzVmss -ResourceGroupName $ResourceGroupName -Name $vmssName -Credential $vmCred -DomainNameLabel $domainNameLabel -Userdata $userData;
166-
$vmss = Get-AzVmss -ResourceGroupName $ResourceGroupName -VMScaleSetName $vmssName -InstanceView:$false -Userdata;
167-
```
168-
169150
The complex example above creates a VMSS, following is an explanation of what is happening:
170151
* The first command creates a resource group with the specified name and location.
171152
* The second command uses the **New-AzStorageAccount** cmdlet to create a storage account.
@@ -186,6 +167,74 @@ The complex example above creates a VMSS, following is an explanation of what is
186167
* The eighteenth command uses the **New-AzVmssConfig** cmdlet to create a VMSS configuration object and stores the result in the variable named $VMSS.
187168
* The nineteenth command uses the **New-AzVmss** cmdlet to create the VMSS.
188169

170+
### Example 3: Create a VMSS with a UserData value
171+
```powershell
172+
$ResourceGroupName = 'RESOURCE GROUP NAME';
173+
$vmssName = 'VMSSNAME';
174+
$domainNameLabel = "dnl" + $ResourceGroupName;
175+
# Create credentials, I am using one way to create credentials, there are others as well.
176+
# Pick one that makes the most sense according to your use case.
177+
$vmPassword = ConvertTo-SecureString 'PASSWORD' -AsPlainText -Force;
178+
$vmCred = New-Object System.Management.Automation.PSCredential('USERNAME', $vmPassword);
179+
180+
$text = "UserData value to encode";
181+
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text);
182+
$userData = [Convert]::ToBase64String($bytes);
183+
184+
#Create a VMSS
185+
New-AzVmss -ResourceGroupName $ResourceGroupName -Name $vmssName -Credential $vmCred -DomainNameLabel $domainNameLabel -Userdata $userData;
186+
$vmss = Get-AzVmss -ResourceGroupName $ResourceGroupName -VMScaleSetName $vmssName -InstanceView:$false -Userdata;
187+
```
188+
189+
### Example 4: Create a VMSS with the Guest Attestation extension installed with the TrustedLaunch security type.
190+
```powershell
191+
# Common setup
192+
$rgname = <RESOURCE GROUP NAME>;
193+
$loc = <AZURE REGION>;
194+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
195+
$vmssSize = 'Standard_DS3_v2';
196+
$PublisherName = "MicrosoftWindowsServer";
197+
$Offer = "WindowsServer";
198+
$SKU = "2019-DATACENTER-GENSECOND";
199+
$securityType = "TrustedLaunch";
200+
$secureboot = $true;
201+
$vtpm = $true;
202+
203+
# NRP
204+
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
205+
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
206+
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
207+
$subnetId = $vnet.Subnets[0].Id;
208+
209+
# New VMSS Parameters
210+
$vmssName = 'vmss' + $rgname;
211+
$vmssType = 'Microsoft.Compute/virtualMachineScaleSets';
212+
$adminUsername = <USER NAME>;
213+
$adminPassword = <PASSWORD> | ConvertTo-SecureString -AsPlainText -Force;
214+
$imgRef = New-Object -TypeName 'Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImage';
215+
$imgRef.PublisherName = $PublisherName;
216+
$imgRef.Offer = $Offer;
217+
$imgRef.Skus = $SKU;
218+
$imgRef.Version = "latest";
219+
$ipCfg = New-AzVmssIPConfig -Name 'test' -SubnetId $subnetId;
220+
221+
$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName $vmssSize -UpgradePolicyMode 'Manual' `
222+
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
223+
| Set-AzVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $adminUsername -AdminPassword $adminPassword `
224+
| Set-AzVmssStorageProfile -OsDiskCreateOption 'FromImage' -OsDiskCaching 'ReadOnly' `
225+
-ImageReferenceOffer $imgRef.Offer -ImageReferenceSku $imgRef.Skus -ImageReferenceVersion $imgRef.Version `
226+
-ImageReferencePublisher $imgRef.PublisherName ;
227+
228+
# Requirements for the Guest Attestation defaulting behavior.
229+
# SecurityType is TrustedLaunch, EnableVtpm is true, EnableSecureBoot is true, DisableIntegrityMonitoring is not true.
230+
$vmss = Set-AzVmssSecurityProfile -VirtualMachineScaleSet $vmss -SecurityType $securityType;
231+
$vmss = Set-AzVmssUefi -VirtualMachineScaleSet $VMSS -EnableVtpm $vtpm -EnableSecureBoot $secureboot;
232+
233+
# Create Vmss
234+
$result = New-AzVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmss;
235+
# This Vmss and its Vm instances has the GuestAttestation extension installed, and the Identity of SystemAssigned.
236+
```
237+
189238
## PARAMETERS
190239

191240
### -AllocationMethod
@@ -877,6 +926,20 @@ Default value: None
877926
Accept pipeline input: True (ByPropertyName)
878927
Accept wildcard characters: False
879928
```
929+
930+
### -DisableIntegrityMonitoring
931+
This flag disables the default behavior to install the Guest Attestation extension to the virtual machine scale set and its vm instances if: 1) SecurityType is TrustedLaunch, 2) SecureBootEnabled on the SecurityProfile is true, 3) VTpmEnabled on the SecurityProfile is true.
932+
933+
```yaml
934+
Type: System.Management.Automation.SwitchParameter
935+
Parameter Sets: DefaultParameter
936+
Aliases:
937+
Required: False
938+
Position: Named
939+
Default value: None
940+
Accept pipeline input: False
941+
Accept wildcard characters: False
942+
```
880943
881944
### -Confirm
882945
Prompts you for confirmation before running the cmdlet.

0 commit comments

Comments
 (0)