Skip to content

{Compute} az vm/vmss create: Allow to use --os-type for when gallery image definition access is denied - #34307

Open
William (william051200) wants to merge 6 commits into
Azure:devfrom
william051200:vmss-create-image-error
Open

William (william051200) wants to merge 6 commits into
Azure:devfrom
william051200:vmss-create-image-error

Conversation

@william051200

@william051200 William (william051200) commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests Suppressions
️✔️ None ️✔️ 130/130 ️✔️ None

Related command

az vm/vmss create

Description

Resolve #16674

Allow az vm create and az vmss create to use --os-type when permission to read the gallery image definition is denied. Keep automatic OS detection when access is available, and prompt for --os-type when needed.

Testing Guide

azdev test test_vmss_create_gallery_image_without_definition_read --live

History Notes


This checklist is used to make sure that common guidelines for a pull request are followed.

@william051200 William (william051200) added the Request X Engineering Agent Ask the agent to triage this issue or review this PR label Oct 30, 2026
Copilot AI balanced review requested due to automatic review settings October 30, 2026 04:19
@x-engineering-agent

x-engineering-agent Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

X Engineering Agent Pull request review: Comments

William (@william051200) The newly reachable specialized Windows fallback still rejects creation without credentials. Upstream CI passed, but regression coverage for the real authorization scenario is not verified.

Check Status Detail
Upstream CI Passed The handoff reports 52/52 upstream checks passed.
Agent live tests Not run This is a review-only PR.
Regression coverage Unverified For vm: 2 focused test file(s) and 1 recording file(s) changed.
Findings 1 high findings 1 high
Risk Risk 37/100 Medium Medium; owner review recommended

To address

Tick each item as you address it.

  • High Specialized fallback still requires credentials

    Details and fix

    src/azure-cli/azure/cli/command_modules/vm/_validators.py:548-555 newly allows definition-denied gallery creation with --os-type windows --specialized; previously the definition GET failed before authentication. The gallery retains ManagedCustomImage (:417), so authentication's existing bypass (:1270-1272) does not apply.

    The traced paths are VM :1707 -> :1720, Flexible VMSS :1974 -> :1993, and Uniform VMSS :2025 -> :2035, all reaching :1269 -> :1302 -> :1335. With definition GET returning 403, a readable specialized Windows image version and no credentials, noninteractive creation fails demanding a password, although specialized templates omit osProfile (_template_builder.py:677-678,1424-1425, in the same module).

    Skip authentication provisioning for specialized gallery images. Verify VM and both VMSS modes create without credentials or osProfile under those permissions, while generalized-image authentication remains unchanged.

Review details

Upstream CI

The handoff reports 52/52 upstream checks passed.

Test validation

  • Agent live test: Not run; this is a review-only PR. Check author-provided test evidence and upstream CI separately.
  • Regression coverage: For vm: 2 focused test file(s) and 1 recording file(s) changed. Scenario coverage is unverified; review the issue's required conditions, test setup, and assertions before approval. No linked issue was found in the PR timeline; inspect the source issue and its required scenario manually.
  • src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:8271-8323 injects the definition-read 403, including during live runs. Its recording, src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vmss_create_gallery_image_without_definition_read.yaml:1661-1683,1953-1981, demonstrates the expected gallery image request and successful Linux VMSS output, but not an actual RBAC denial.
  • Focused rerun: test_vmss_create_gallery_image_without_definition_read and test_vmss_create_gallery_image_os_type_validation in src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_defaults.py:383-422. Verify the authorization scenario without the mock using a principal that can read the explicit image version but cannot read its definition; include specialized Windows VM and both VMSS modes without credentials.

Risk assessment

37/100 · Medium

The Medium rating is driven by public CLI behavior, failure-handling behavior.

  • Change scope: 5 changed files, 2137 changed lines (+2133 / -4), including 2 production files.
  • Affected components: vm
  • Risk drivers: public CLI behavior (+18); failure-handling behavior (+12)
  • Regression evidence: Changed regression tests are included, reducing risk.
  • Confidence: High because changed-line patches were available for every production file.
  • Required review: Owning-squad review is recommended for vm before merge.

Ask the Agent

Tick a box to queue an action. Requires write access to this repository.

  • Re-review this PR
  • Run Agent live tests on this PR

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

Copilot AI left a comment

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.

🟡 Changes recommended

The added scenario only exercises a 403 response, leaving successful definition reads untested for case-insensitive OS-type matches and mismatches that should raise InvalidArgumentValueError.

1 open issue
What changed in this PR

This PR addresses #16674 by allowing az vm create and az vmss create to use an explicit OS type when gallery image-definition access is denied, while preserving automatic detection when access is available.

Changes:

  • Accepts --os-type for gallery images and validates it against readable definitions.
  • Provides guidance when access is denied and --os-type is missing.
  • Adds a VMSS regression scenario and recording for the denied-access fallback.
File Description
src/​azure-cli/​azure/​cli/​command_modules/​vm/​tests/​latest/​test_vm_commands.py Tests missing and explicit OS types with a simulated definition-read denial.
src/​azure-cli/​azure/​cli/​command_modules/​vm/​tests/​latest/​recordings/​test_vmss_create_gallery_image_without_definition_read.yaml Records resource setup and successful VMSS creation for playback.
src/​azure-cli/​azure/​cli/​command_modules/​vm/​_validators.py Adds the access-denied fallback and OS-type consistency validation.
src/​azure-cli/​azure/​cli/​command_modules/​vm/​_params.py Documents gallery-image support in --os-type help.

Review effort: Balanced

Comment on lines +555 to +558
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')))
@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

x-engineering-agent[bot]

This comment was marked as outdated.

@x-engineering-agent x-engineering-agent Bot added the X Engineering Agent Reviewed Agent reviewed this PR label Oct 30, 2026
x-engineering-agent[bot]

This comment was marked as outdated.

@william051200

Copy link
Copy Markdown
Member Author

@Azure/x-engineering-agent I have fixed the failure, run again

@x-engineering-agent x-engineering-agent Bot left a comment

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.

Review comments are inline on the changed lines. See the X Engineering Agent Report.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad Compute az vm/vmss/image/disk/snapshot Request X Engineering Agent Ask the agent to triage this issue or review this PR X Engineering Agent Reviewed Agent reviewed this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az vmss create has incorrect authorization for gallery images

5 participants