Azure / azure-cli-extensions

Public Repository for Extensions of Azure CLI.
https://docs.microsoft.com/en-us/cli/azure
MIT License
383 stars 1.24k forks source link

AttributeError: 'AssignmentsOperations' object has no attribute 'cli_ctx' #6211

Open ozgen opened 1 year ago

ozgen commented 1 year ago

Related command

Extension name (the extension in question)

blueprint

Description of issue (in as much detail as possible)

Command Name az blueprint assignment update Extension Name: blueprint. Version: 0.3.1.

Errors:

cli.azure.cli.core.azclierror: The command failed with an unexpected error. Here is the traceback: az_command_data_logger: The command failed with an unexpected error. Here is the traceback: cli.azure.cli.core.azclierror: 'AssignmentsOperations' object has no attribute 'cli_ctx' Traceback (most recent call last): File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute raise ex File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job result = cmd_copy(params) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__ return self.handler(*args, **kwargs) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler return op(**command_args) File "/Users/ozgen/.azure/cliextensions/blueprint/azext_blueprint/custom.py", line 671, in update_blueprint_assignment _assign_owner_role_in_target_scope(client, resource_scope, spn) File "/Users/ozgen/.azure/cliextensions/blueprint/azext_blueprint/custom.py", line 612, in _assign_owner_role_in_target_scope role_assignments = list_role_assignments(cmd, assignee=spn_object_id, role='Owner', scope=role_scope) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/command_modules/role/custom.py", line 222, in list_role_assignments graph_client = _graph_client_factory(cmd.cli_ctx) AttributeError: 'AssignmentsOperations' object has no attribute 'cli_ctx' az_command_data_logger: 'AssignmentsOperations' object has no attribute 'cli_ctx' Traceback (most recent call last): File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute raise ex File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job result = cmd_copy(params) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__ return self.handler(*args, **kwargs) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler return op(**command_args) File "/Users/ozgen/.azure/cliextensions/blueprint/azext_blueprint/custom.py", line 671, in update_blueprint_assignment _assign_owner_role_in_target_scope(client, resource_scope, spn) File "/Users/ozgen/.azure/cliextensions/blueprint/azext_blueprint/custom.py", line 612, in _assign_owner_role_in_target_scope role_assignments = list_role_assignments(cmd, assignee=spn_object_id, role='Owner', scope=role_scope) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/command_modules/role/custom.py", line 222, in list_role_assignments graph_client = _graph_client_factory(cmd.cli_ctx) AttributeError: 'AssignmentsOperations' object has no attribute 'cli_ctx'

To Reproduce: Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

Put any pre-requisite steps here...

az blueprint assignment update --name {} --location {} --identity-type {} --locks-mode {} --blueprint-version {} --parameters {} --subscription {}

Environment Summary

Installer: linux-latest

azure-cli 2.47.0 *

Extensions: blueprint 0.3.1


yonzhan commented 1 year ago

Thank you for opening this issue, we will look into it.

yonzhan commented 1 year ago

blueprint

savas-guven commented 1 year ago

This is the same issue in #4297, but it does repro with the latest versions of everything. I had this repro on:

Installer: linux-latest

azure-cli 2.46.0 *

Extensions: blueprint 0.3.1

SaurabhSharma-MSFT commented 1 year ago

@ozgen I am not to reproduce this error with the same CLI and blueprint versions. image Did you try this cmdlet in any other environment.

ozgen commented 1 year ago

I tried in Azure Devops CI pipeline with ubuntu-latest image version and I got the same error. @SaurabhSharma-MSFT

ozgen commented 1 year ago

I also got the same error on macos.

ozgen commented 1 year ago

Also, I tried on Microsoft Windows Server 2022 Datacenter Azure Edition with version 10.0.20308, I got the same error:

←[91mThe command failed with an unexpected error. Here is the traceback:←[0m
←[91m'AssignmentsOperations' object has no attribute 'cli_ctx'
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "C:\Users\deepnetwork\.azure\cliextensions\blueprint\azext_blueprint\custom.py", line 671, in update_blueprint_assignment
    _assign_owner_role_in_target_scope(client, resource_scope, spn)
  File "C:\Users\deepnetwork\.azure\cliextensions\blueprint\azext_blueprint\custom.py", line 612, in _assign_owner_role_in_target_scope
    role_assignments = list_role_assignments(cmd, assignee=spn_object_id, role='Owner', scope=role_scope)
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/role/custom.py", line 215, in list_role_assignments
AttributeError: 'AssignmentsOperations' object has no attribute 'cli_ctx'←[0m
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
savas-guven commented 1 year ago

Hi @SaurabhSharma-MSFT we suspect the difference in symptoms might be due to the location where the Blueprints are stored. We use Management Groups per Microsoft recommendations.

The only option to prevent subscription owners from removing a blueprint assignment is to assign the blueprint to a management group. In this scenario, only Owners of the management group have the permissions needed to remove the blueprint assignment

ozgen commented 1 year ago

We used System Assigned Managed Identity rather than User Assigned Identity as you tested. When I used User Assigned Identity, the command has worked properly. I converted the CLI commands to PowerShell az command as Set-AzBlueprintAssignment worked also. @SaurabhSharma-MSFT.

Does Az CLI support SystemAssignedManagedIdentity?

ref: https://learn.microsoft.com/en-us/cli/azure/blueprint/assignment?view=azure-cli-latest

SaurabhSharma-MSFT commented 1 year ago

@ozgen I am able to reproduce this issue with System Managed Identity and currently investigating for the root cause. I will update you as soon as possible. image

microsoft-github-policy-service[bot] commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @alex-frankel, @filizt.