Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ def load_arguments(self, _):
'or specify individual disks. {} {}'.format(usage, allowed_values)

c.argument('os_disk_name', help='The name of the new VM OS disk.')
c.argument('os_type', help='Type of OS installed on a custom VHD. Do not use when specifying an URN or URN alias.', arg_type=get_enum_type(OperatingSystemTypesLower))
c.argument('os_type', help='Type of OS installed on a custom VHD or gallery image. Required for gallery images when the image definition cannot be read. Do not use when specifying an URN or URN alias.', arg_type=get_enum_type(OperatingSystemTypesLower))
c.argument('storage_account', help="Only applicable when used with `--use-unmanaged-disk`. The name to use when creating a new storage account or referencing an existing one. If omitted, an appropriate storage account in the same resource group and location will be used, or a new one will be created.")
c.argument('storage_sku', nargs='+', help=storage_sku_help)
c.argument('storage_container_name', help="Only applicable when used with `--use-unmanaged-disk`. Name of the storage container for the VM OS disk. Default: vhds")
Expand Down
24 changes: 21 additions & 3 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ def _validate_location(cmd, namespace, zone_info, size_info):

# pylint: disable=too-many-branches, too-many-statements, too-many-locals
def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False):
from azure.core.exceptions import HttpResponseError
from azure.cli.core.azclierror import InvalidArgumentValueError
from azure.mgmt.core.tools import parse_resource_id

_validate_vm_vmss_create_ephemeral_placement(namespace)
Expand Down Expand Up @@ -453,9 +455,12 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False):
forbidden.append('os_disk_name')

elif namespace.storage_profile == StorageProfile.ManagedCustomImage:
res = parse_resource_id(namespace.image)
required = ['image']
forbidden = ['os_type', 'attach_os_disk', 'storage_account',
'storage_container_name', 'use_unmanaged_disk']
if res['type'].lower() == 'galleries':
forbidden.remove('os_type')
if for_scale_set:
forbidden.append('os_disk_name')

Expand Down Expand Up @@ -516,7 +521,6 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False):
image_data_disks = []
if namespace.storage_profile == StorageProfile.ManagedCustomImage:
# extract additional information from a managed custom image
res = parse_resource_id(namespace.image)
namespace.aux_subscriptions = [res['subscription']]
if res['type'].lower() == 'images':
from .aaz.latest.image import Show as ImageShow
Expand All @@ -539,8 +543,22 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False):
'resource_group': res['resource_group'],
'subscription': res['subscription']
}
image_info = SigImageDefinitionShow(cli_ctx=cmd.cli_ctx)(command_args=command_args)
namespace.os_type = image_info.get('osType')
try:
image_info = SigImageDefinitionShow(cli_ctx=cmd.cli_ctx)(command_args=command_args)
except HttpResponseError as ex:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High Specialized fallback still requires credentials

The newly admitted 403 fallback reaches authentication for specialized Windows gallery images. Without credentials, VM and both VMSS modes fail at _validators.py:1335, although specialized templates omit osProfile. Skip authentication provisioning for specialized gallery images and verify all three creation modes without credentials, preserving generalized-image authentication.

X Engineering Agent · Reviewer · React with +1 or -1 to train the reviewer

if ex.status_code != 403:
raise
if not namespace.os_type:
raise RequiredArgumentMissingError(
"Unable to determine the image OS type because the gallery image definition cannot be read. "
"Specify --os-type linux or windows."
) from ex
else:
if namespace.os_type and namespace.os_type.lower() != image_info.get('osType', '').lower():
raise InvalidArgumentValueError(
"The specified --os-type '{}' does not match the gallery image OS type '{}'."
.format(namespace.os_type, image_info.get('osType')))
Comment on lines +557 to +560

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium Cover the readable-definition OS validation

The added scenario always injects a definition-read 403, so it cannot detect removal or reversal of this comparison. The existing shared-gallery mismatch test at test_vm_commands.py:9337-9341 reaches a different branch and exception type. Add focused VM/VMSS create-validator cases with a readable ordinary gallery definition: mixed-case matching OS succeeds with the expected OS configuration, and mismatching OS raises InvalidArgumentValueError before deployment. Rerun these cases alongside VMGalleryImage.test_vmss_create_gallery_image_without_definition_read. This is the same test-strength root cause as Copilot comment 4420422113.

X Engineering Agent · Reviewer · React with +1 or -1 to train the reviewer

namespace.os_type = image_info.get('osType')

gallery_image_version = res.get('child_name_2', '')
if gallery_image_version.lower() in ['latest', '']:
Expand Down
Loading
Loading