Skip to content

[Compute] Update command az sig create, az sig show and add command group az sig identity to manage the service identity of a Shared Image Gallery (SIG)#33137

Open
william051200 wants to merge 20 commits intoAzure:devfrom
william051200:32814-sig-identity
Open

Conversation

@william051200
Copy link
Copy Markdown
Member

Related command

az sig create
az sig show
az sig identity assign
az sig identity remove
az sig identity show

Description

Resolve #32814

aaz Azure/aaz#977

Testing Guide

Test cases:
vm\tests\latest\test_vm_commands.py: test_sig_msi
vm\tests\latest\test_vm_commands.py: test_sig_explicit_msi

History Notes

[Compute] az sig create: Add new argument group "Managed Service Identity" to configure the service identity of a Shared Image Gallery (SIG)
[Compute] az sig show: Update command to display the managed service identity of a Shared Image Gallery (SIG)
[Compute] az sig identity: Add new command group to manage the service identity of a Shared Image Gallery (SIG)


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

Copilot AI review requested due to automatic review settings April 6, 2026 01:43
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Apr 6, 2026

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
️✔️vm
️✔️latest
️✔️3.12
️✔️3.13

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Apr 6, 2026

⚠️AzureCLI-BreakingChangeTest
⚠️vm
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd sig create cmd sig create added parameter assign_identity
⚠️ 1006 - ParaAdd sig create cmd sig create added parameter identity_role
⚠️ 1006 - ParaAdd sig create cmd sig create added parameter identity_scope
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter description: removed property aaz_type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter description: removed property type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter eula: removed property aaz_type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter eula: removed property type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter gallery_name: removed property aaz_type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter gallery_name: removed property type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter location: removed property aaz_type=string
⚠️ 1010 - ParaPropUpdate sig create cmd sig create update parameter location: updated property type from string to custom_type
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter no_wait: removed property aaz_type=bool
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter no_wait: removed property choices=['0', '1', 'f', 'false', 'n', 'no', 't', 'true', 'y', 'yes']
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter no_wait: removed property nargs=?
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter no_wait: removed property type=bool
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter permissions: removed property aaz_type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter permissions: removed property type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter public_name_prefix: removed property aaz_type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter public_name_prefix: removed property type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter publisher_contact: removed property aaz_type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter publisher_contact: removed property type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter publisher_uri: removed property aaz_type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter publisher_uri: removed property type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter resource_group: removed property aaz_type=string
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter resource_group: removed property type=string
⚠️ 1010 - ParaPropUpdate sig create cmd sig create update parameter resource_group: updated property name from resource_group to resource_group_name
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter soft_delete: removed property aaz_type=bool
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter soft_delete: removed property type=bool
⚠️ 1010 - ParaPropUpdate sig create cmd sig create update parameter soft_delete: updated property choices from ['0', '1', 'f', 'false', 'n', 'no', 't', 'true', 'y', 'yes'] to ['false', 'true']
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter tags: removed property aaz_type=AAZDictArg
⚠️ 1009 - ParaPropRemove sig create cmd sig create update parameter tags: removed property type=Dict<String,String>
⚠️ 1010 - ParaPropUpdate sig create cmd sig create update parameter tags: updated property nargs from + to *
⚠️ 1011 - SubgroupAdd sig identity sub group sig identity added

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Apr 6, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the sig (Shared Image Gallery) commands in the VM module to support Managed Service Identity (system/user-assigned) on SIG resources, and introduces a new az sig identity command group for identity management (assign/remove/show), aligning with the feature request in issue #32814.

Changes:

  • Extend az sig create to optionally configure managed identity (and optionally create an RBAC role assignment via --scope/--role).
  • Add az sig identity assign|remove|show commands backed by new AAZ identity subresource plumbing and custom wrappers.
  • Add/extend scenario tests validating SIG MSI behaviors (system-assigned + user-assigned).

Reviewed changes

Copilot reviewed 17 out of 19 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py Adds scenario tests for SIG identity assign/remove/show and create/show output validation.
src/azure-cli/azure/cli/command_modules/vm/operations/sig.py Adds SIG identity remove/show operation customizations on top of generated AAZ commands.
src/azure-cli/azure/cli/command_modules/vm/custom.py Introduces custom implementations for sig create and sig identity assign/remove integration and output shaping.
src/azure-cli/azure/cli/command_modules/vm/commands.py Wires sig create to the new custom handler and registers the new sig identity command group.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/identity/_assign.py Generated AAZ command for identity assignment.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/identity/_remove.py Generated AAZ command for identity removal.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/identity/_show.py Generated AAZ command for showing identity (docstring/examples currently inaccurate).
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/identity/_wait.py Generated AAZ wait command (currently not imported/registered).
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/identity/init.py Exposes generated identity commands (but does not expose _wait).
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/identity/__cmd_group.py Generated command group registration for sig identity.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/_create.py Updates SIG create to new API version and adds identity schema handling.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/_show.py Updates SIG show to new API version and adds identity schema handling.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/_wait.py Updates SIG wait command to new API version and identity/systemData schema.
src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py Expands principal id discovery to support identity operations returning flattened identity payloads.
src/azure-cli/azure/cli/command_modules/vm/_validators.py Adds validators for SIG identity arguments and RBAC scope/role constraints.
src/azure-cli/azure/cli/command_modules/vm/_params.py Adds CLI parameters for SIG MSI and sig identity commands.
src/azure-cli/azure/cli/command_modules/vm/_help.py Adds help entries for sig create and sig identity assign/remove.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6713 to +6716
if assign_identity is None:
create_sig = SigCreate(cli_ctx=cmd.cli_ctx)(command_args=command_args)
LongRunningOperation(cmd.cli_ctx)(create_sig)
return create_sig.result()
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

create_sig eagerly waits on the AAZ LRO via LongRunningOperation and then calls .result() again. This defeats the CLI's standard --no-wait behavior (the command will still block) and does redundant polling. Prefer returning the poller (or using sdk_no_wait(no_wait, ...)) and let the command invoker handle polling/--no-wait, then post-process the final result only when no_wait is false.

Copilot uses AI. Check for mistakes.
return sig


def _assign_identity(resource, identity, external_identities=[], enable_local_identity=None, command_args={}):
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

_assign_identity uses mutable default arguments (external_identities=[], command_args={}), which can leak state across calls and cause hard-to-debug behavior. Use None defaults and initialize new lists/dicts inside the function.

Suggested change
def _assign_identity(resource, identity, external_identities=[], enable_local_identity=None, command_args={}):
def _assign_identity(resource, identity, external_identities=None, enable_local_identity=None, command_args=None):
if external_identities is None:
external_identities = []
if command_args is None:
command_args = {}

Copilot uses AI. Check for mistakes.

if existing_identity['type'] == IdentityType.NONE.value \
or existing_identity['type'] == IdentityType.SYSTEM_ASSIGNED.value:
existing_identity.pop('userAssignedIdentities')
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

In pre_instance_update, userAssignedIdentities can be popped twice: when removing the last user-assigned identity, it's popped inside the len(emsis_to_retain) < 1 block and then popped again later when type becomes None/SystemAssigned. This will raise KeyError in that path. Use pop('userAssignedIdentities', None) (or guard with if 'userAssignedIdentities' in ...) for the later cleanup.

Suggested change
existing_identity.pop('userAssignedIdentities')
existing_identity.pop('userAssignedIdentities', None)

Copilot uses AI. Check for mistakes.
Comment on lines +1368 to +1372
with self.argument_context('sig identity remove') as c:
c.argument('identities', nargs='*', help="Space-separated identities to assign. Use '{0}' to refer to the system assigned identity. Default: '{0}'".format(MSI_LOCAL_ID))

with self.argument_context('sig identity assign') as c:
c.argument('assign_identity', options_list=['--identities'], nargs='*', help="Space-separated identities to assign. Use '{0}' to refer to the system assigned identity. Default: '{0}'".format(MSI_LOCAL_ID))
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

Help text for sig identity remove --identities says "identities to assign", but this command removes identities. This is user-facing and confusing; update the help string to say "remove" (and keep it consistent with sig identity assign).

Copilot uses AI. Check for mistakes.
Comment on lines +591 to +606
helps['sig identity assign'] = """
type: command
short-summary: Assign the user or system managed identities.
"""

helps['sig identity remove'] = """
type: command
short-summary: Remove the user or system managed identities.
examples:
- name: Remove the system assigned identity.
text: |
az sig identity remove --resource-group myResourceGroup --gallery-name myGalleryName
- name: Remove a user assigned identity.
text: |
az sig identity remove --resource-group myResourceGroup --gallery-name myGalleryName --identities readerId
"""
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The sig identity command group includes a show command (registered in commands.py), but there is no corresponding help entry here. Add helps['sig identity show'] (and examples if appropriate) to keep help coverage consistent with assign/remove.

Copilot uses AI. Check for mistakes.
class Show(AAZCommand):
"""Show the details of managed identities.

:example: Get a community gallery.
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The command docstring/examples are incorrect for sig identity show (it says "Get a community gallery"). This text is user-facing when help is generated from docstrings; update it to describe showing the SIG managed identity instead.

Suggested change
:example: Get a community gallery.
:example: Show the managed identity of a gallery.

Copilot uses AI. Check for mistakes.
from .__cmd_group import *
from ._assign import *
from ._remove import *
from ._show import *
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

sig identity _wait.py is added, but sig.identity.__init__ doesn't import/export it, so the decorator never runs and az sig identity wait won't be registered. Either add _wait to __init__.py (if the command should exist) or remove the unused generated file to avoid dead code.

Suggested change
from ._show import *
from ._show import *
from ._wait import *

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad Auto-Assign Auto assign by bot Compute az vm/vmss/image/disk/snapshot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update command 'az sig create' and add new commands 'az sig identity assign', 'az sig identity show', 'az sig identity remove'

5 participants