Repository navigation
{Compute} az vm/vmss create: Allow to use --os-type for when gallery image definition access is denied
#34307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
baa6bfb
3c8e732
5f947cc
4d71679
37a4685
0e571b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -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') | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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: | ||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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.
|
||
| namespace.os_type = image_info.get('osType') | ||
|
|
||
| gallery_image_version = res.get('child_name_2', '') | ||
| if gallery_image_version.lower() in ['latest', '']: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 omitosProfile. Skip authentication provisioning for specialized gallery images and verify all three creation modes without credentials, preserving generalized-image authentication.