Skip to content

Commit 1384808

Browse files
authored
[Compute] az vm/vmss create/update: Set --security-type to Standard only if explicitly set by end user (#31282)
1 parent 617ad1e commit 1384808

6 files changed

Lines changed: 19054 additions & 5551 deletions

File tree

src/azure-cli/azure/cli/command_modules/vm/_params.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ def load_arguments(self, _):
130130

131131
enable_vtpm_type = CLIArgumentType(arg_type=get_three_state_flag(), min_api='2020-12-01', help='Enable vTPM.')
132132
enable_secure_boot_type = CLIArgumentType(arg_type=get_three_state_flag(), min_api='2020-12-01', help='Enable secure boot.')
133-
# The `Standard` is used for backward compatibility to allow customers to keep their current behavior after changing the default values to Trusted Launch VMs in the future.
134-
t_security = [x.value for x in self.get_models('SecurityTypes') or []] + [COMPATIBLE_SECURITY_TYPE_VALUE]
135-
security_type = CLIArgumentType(arg_type=get_enum_type(t_security), min_api='2020-12-01', help='Specify the security type of the virtual machine.')
136133
enable_auto_os_upgrade_type = CLIArgumentType(arg_type=get_three_state_flag(), min_api='2018-10-01',
137134
help='Indicate whether OS upgrades should automatically be applied to scale set instances in a rolling fashion when a newer version of the OS image becomes available.')
138135
gallery_image_name_type = CLIArgumentType(options_list=['--gallery-image-definition', '-i'], help='The name of the community gallery image definition from which the image versions are to be listed.', id_part='child_name_2')
@@ -434,7 +431,6 @@ def load_arguments(self, _):
434431
c.argument('ephemeral_os_disk_placement', arg_type=ephemeral_placement_type,
435432
help='Only applicable when used with `--size`. Allows you to choose the Ephemeral OS disk provisioning location.')
436433
c.argument('enable_hibernation', arg_type=get_three_state_flag(), min_api='2021-03-01', help='The flag that enable or disable hibernation capability on the VM.')
437-
c.argument('security_type', arg_type=get_enum_type(["TrustedLaunch", "Standard"], default=None), min_api='2022-11-01', help='Specify the security type of the virtual machine.')
438434

439435
with self.argument_context('vm create') as c:
440436
c.argument('name', name_arg_type, validator=_resource_not_exists(self.cli_ctx, 'Microsoft.Compute/virtualMachines'))
@@ -466,7 +462,6 @@ def load_arguments(self, _):
466462
help='Specify the scale set logical fault domain into which the virtual machine will be created. By default, the virtual machine will be automatically assigned to a fault domain that best maintains balance across available fault domains. This is applicable only if the virtualMachineScaleSet property of this virtual machine is set. The virtual machine scale set that is referenced, must have platform fault domain count. This property cannot be updated once the virtual machine is created. Fault domain assignment can be viewed in the virtual machine instance view')
467463
c.argument('count', type=int, is_preview=True,
468464
help='Number of virtual machines to create. Value range is [2, 250], inclusive. Don\'t specify this parameter if you want to create a normal single VM. The VMs are created in parallel. The output of this command is an array of VMs instead of one single VM. Each VM has its own public IP, NIC. VNET and NSG are shared. It is recommended that no existing public IP, NIC, VNET and NSG are in resource group. When --count is specified, --attach-data-disks, --attach-os-disk, --boot-diagnostics-storage, --computer-name, --host, --host-group, --nics, --os-disk-name, --private-ip-address, --public-ip-address, --public-ip-address-dns-name, --storage-account, --storage-container-name, --subnet, --use-unmanaged-disk, --vnet-name are not allowed.')
469-
c.argument('security_type', security_type)
470465
c.argument('enable_secure_boot', enable_secure_boot_type)
471466
c.argument('enable_vtpm', enable_vtpm_type)
472467
c.argument('user_data', help='UserData for the VM. It can be passed in as file or string.', completer=FilesCompleter(), type=file_type, min_api='2021-03-01')
@@ -482,6 +477,7 @@ def load_arguments(self, _):
482477
c.argument('enable_user_redeploy_scheduled_events', options_list=['--enable-user-redeploy-scheduled-events', '--enable-redeploy'], arg_type=get_three_state_flag(), min_api='2024-07-01', help='The configuration parameter used while creating user initiated redeploy scheduled event setting creation.')
483478
c.argument('align_regional_disks_to_vm_zone', options_list=['--align-regional-disks-to-vm-zone', '--align-regional-disks'], arg_type=get_three_state_flag(), min_api='2024-11-01', help='Specify whether the regional disks should be aligned/moved to the VM zone. This is applicable only for VMs with placement property set. Please note that this change is irreversible.')
484479
c.argument('key_incarnation_id', type=int, min_api='2024-11-01', help='Increase the value of this property allows user to reset the key used for securing communication channel between guest and host.')
480+
c.argument('security_type', arg_type=get_enum_type(["TrustedLaunch", "Standard", "ConfidentialVM"], default=None), help='Specify the security type of the virtual machine. The value Standard can be used if subscription has feature flag UseStandardSecurityType registered under Microsoft.Compute namespace. Refer to https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/preview-features for steps to enable required feature.')
485481

486482
with self.argument_context('vm create', arg_group='Storage') as c:
487483
c.argument('attach_os_disk', help='Attach an existing OS disk to the VM. Can use the name or ID of a managed disk or the URI to an unmanaged disk VHD.')
@@ -770,7 +766,6 @@ def load_arguments(self, _):
770766
c.argument('patch_mode', arg_type=get_enum_type(['AutomaticByOS', 'AutomaticByPlatform', 'Manual', 'ImageDefault']), min_api='2020-12-01',
771767
help='Mode of in-guest patching to IaaS virtual machine. Allowed values for Windows VM: AutomaticByOS, AutomaticByPlatform, Manual. Allowed values for Linux VM: AutomaticByPlatform, ImageDefault. Manual - You control the application of patches to a virtual machine. You do this by applying patches manually inside the VM. In this mode, automatic updates are disabled; the paramater --enable-auto-update must be false. AutomaticByOS - The virtual machine will automatically be updated by the OS. The parameter --enable-auto-update must be true. AutomaticByPlatform - the virtual machine will automatically updated by the OS. ImageDefault - The virtual machine\'s default patching configuration is used. The parameter --enable-agent and --enable-auto-update must be true')
772768
c.argument('enable_hibernation', arg_type=get_three_state_flag(), min_api='2021-03-01', help='The flag that enable or disable hibernation capability on the VMSS.')
773-
c.argument('security_type', security_type)
774769
c.argument('enable_secure_boot', enable_secure_boot_type)
775770
c.argument('enable_vtpm', enable_vtpm_type)
776771
c.argument('os_disk_delete_option', arg_type=get_enum_type(self.get_models('DiskDeleteOptionTypes')), min_api='2022-03-01', arg_group='Storage', help='Specify whether OS disk should be deleted or detached upon VMSS Flex deletion (This feature is only for VMSS with flexible orchestration mode).')
@@ -821,7 +816,6 @@ def load_arguments(self, _):
821816
c.argument('enable_secure_boot', enable_secure_boot_type)
822817
c.argument('enable_vtpm', enable_vtpm_type)
823818
c.argument('custom_data', help='Custom init script file or text (cloud-init, cloud-config, etc..)', completer=FilesCompleter(), type=file_type)
824-
c.argument('security_type', arg_type=get_enum_type(["TrustedLaunch", "Standard"]), min_api='2020-06-01', help='Specify the security type of the virtual machine scale set.')
825819
c.argument('ephemeral_os_disk', arg_type=get_three_state_flag(), min_api='2024-03-01', help='Allow you to specify the ephemeral disk settings for the operating system disk. Specify it to false to set ephemeral disk setting as empty and migrate it to non ephemeral')
826820
c.argument('ephemeral_os_disk_option', options_list=['--ephemeral-os-disk-option', '--ephemeral-option'], arg_type=get_enum_type(self.get_models('DiffDiskOptions')), min_api='2024-03-01', help='Specify the ephemeral disk settings for operating system disk.')
827821
c.argument('zones', zones_type, min_api='2023-03-01')
@@ -874,6 +868,8 @@ def load_arguments(self, _):
874868
'Please refer to https://docs.microsoft.com/rest/api/compute/virtualmachinescalesets/get#virtualmachineextension for the data format.')
875869
c.argument('security_posture_reference_is_overridable', arg_type=get_three_state_flag(), min_api='2024-03-01', options_list=['--security-posture-reference-is-overridable', '--is-overridable'], help='Whether the security posture can be overridden by the user.')
876870
c.argument('zone_balance', arg_type=get_three_state_flag(), min_api='2017-12-01', help='Whether to force strictly even Virtual Machine distribution cross x-zones in case there is zone outage.')
871+
c.argument('security_type', arg_type=get_enum_type(["TrustedLaunch", "Standard", "ConfidentialVM"], default=None),
872+
help='Specify the security type of the virtual machine scale set. The value Standard can be used if subscription has feature flag UseStandardSecurityType registered under Microsoft.Compute namespace. Refer to https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/preview-features for steps to enable required feature.')
877873

878874
with self.argument_context('vmss update') as c:
879875
c.argument('instance_id', id_part='child_name_1', help="Update the VM instance with this ID. If missing, update the VMSS.")

src/azure-cli/azure/cli/command_modules/vm/_validators.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,6 @@ def trusted_launch_set_default(namespace, generation_version, features):
14131413
if namespace.enable_secure_boot is None:
14141414
namespace.enable_secure_boot = True
14151415
else:
1416-
if namespace.security_type is None:
1417-
namespace.security_type = COMPATIBLE_SECURITY_TYPE_VALUE
14181416
logger.warning(UPGRADE_SECURITY_HINT)
14191417

14201418

@@ -1424,11 +1422,6 @@ def _validate_generation_version_and_trusted_launch(cmd, namespace):
14241422
return
14251423
from ._vm_utils import validate_image_trusted_launch, validate_vm_disk_trusted_launch
14261424
if namespace.image is not None:
1427-
from ._vm_utils import is_valid_image_version_id
1428-
if is_valid_image_version_id(namespace.image):
1429-
if namespace.security_type is None:
1430-
namespace.security_type = 'Standard'
1431-
14321425
image_type = _parse_image_argument(cmd, namespace)
14331426

14341427
if image_type == 'image_id':

src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -653,23 +653,20 @@ def validate_vm_disk_trusted_launch(namespace, disk_security_profile):
653653
return
654654

655655
security_type = disk_security_profile.security_type if hasattr(disk_security_profile, 'security_type') else None
656-
if security_type.lower() == 'trustedlaunch':
656+
if security_type and security_type.lower() == 'trustedlaunch':
657657
if namespace.enable_secure_boot is None:
658658
namespace.enable_secure_boot = True
659659
if namespace.enable_vtpm is None:
660660
namespace.enable_vtpm = True
661661
namespace.security_type = 'TrustedLaunch'
662-
elif security_type.lower() == 'standard':
662+
elif security_type and security_type.lower() == 'standard':
663663
logger.warning(UPGRADE_SECURITY_HINT)
664664

665665

666666
def validate_image_trusted_launch(namespace):
667667
from ._constants import UPGRADE_SECURITY_HINT
668668

669-
# set securityType to Standard by default if no inputs by end user
670-
if namespace.security_type is None:
671-
namespace.security_type = 'Standard'
672-
if namespace.security_type.lower() != 'trustedlaunch':
669+
if namespace.security_type and namespace.security_type.lower() != 'trustedlaunch':
673670
logger.warning(UPGRADE_SECURITY_HINT)
674671

675672

0 commit comments

Comments
 (0)