azure-cli
azure-cli copied to clipboard
AttributeError: 'RoleAssignmentsOperations' object has no attribute 'config' when using `az ad sp create-for-rbac`
Describe the bug
Not sure how to go about fixing this - getting an error shown at the title of the issue.
Command Name
az ad sp create-for-rbac
Errors:
The command failed with an unexpected error. Here is the traceback:
'RoleAssignmentsOperations' object has no attribute 'config'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 663, in execute
raise ex
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 718, in _run_job
return cmd_copy.exception_handler(ex)
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/role/commands.py", line 51, in graph_err_handler
raise ex
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
result = cmd_copy(params)
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
return self.handler(*args, **kwargs)
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
return op(**command_args)
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/role/custom.py", line 1246, in create_service_principal_for_rbac
_create_role_assignment(cmd.cli_ctx, role, sp_oid, None, scope, resolve_assignee=False,
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/role/custom.py", line 198, in _create_role_assignment
assignments_client.config.subscription_id)
AttributeError: 'RoleAssignmentsOperations' object has no attribute 'config'
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 ad sp create-for-rbac --name {} --role {} --scopes {} --sdk-auth
Expected Behavior
Environment Summary
Linux-6.0.0-kali5-amd64-x86_64-with-glibc2.36, Kali GNU/Linux Rolling
Python 3.10.9
Installer: DEB
azure-cli 2.43.0
Extensions:
azure-devops 0.25.0
Dependencies:
msal 1.20.0
azure-mgmt-resource 21.2.1
Additional Context
@jiasli for awareness
One of the closed ticket #22231 had a comment that the issue is caused by mismatch between Azure SDK and CLI API [from @glaubitz]:
This issue is a typical example of the Azure SDK and the CLI API deviating from each other when one of the Azure SDK component packages have been updated.
I will refer to #19640 and #23933 to see if they fix the issue.
Tried out on my Windows machine but also fails:

Works fine when tried out from Azure Cloud Shell (Bash):

I haven't had a chance to go through my earlier comment yet tho.
We're encountering the same issue.
@k-byun, for your initial error:
AttributeError: 'RoleAssignmentsOperations' object has no attribute 'config'
Judging by the path /usr/lib/python3/dist-packages, you are not using the official Azure CLI. Installing the official one should solve your issue. See https://github.com/Azure/azure-cli/issues/19640
As for No connection adapter were found for 'C:/Program File/Git..., this is an issue with Git Bash. See https://github.com/Azure/azure-cli/issues/16317#issuecomment-768755622
I am unfortunately facing the same issue for the following version:
$ az --version
azure-cli 2.45.0 *
core 2.45.0 *
telemetry 1.0.8 *
Dependencies:
msal 1.21.0
azure-mgmt-resource 22.0.0
Python location '/usr/bin/python3'
Extensions directory '/home/terraform/.azure/cliextensions'
Python (Linux) 3.11.2 (main, May 2 2024, 11:59:08) [GCC 12.2.0]
Legal docs and information: aka.ms/AzureCliLegal
Installed from official Microsoft repository:
https://packages.microsoft.com/
System:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
Logs:
$ az ad sp create-for-rbac --name abc --role Contributor --scopes /subscriptions/XXXXXXXXX
Creating 'Contributor' role assignment under scope '/subscriptions/XXXXXXXXX'
Role assignment creation failed.
The command failed with an unexpected error. Here is the traceback:
'RoleAssignmentsOperations' object has no attribute 'config'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 663, in execute
raise ex
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 718, in _run_job
return cmd_copy.exception_handler(ex)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/role/commands.py", line 51, in graph_err_handler
raise ex
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
result = cmd_copy(params)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
return self.handler(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
return op(**command_args)
^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/role/custom.py", line 1246, in create_service_principal_for_rbac
_create_role_assignment(cmd.cli_ctx, role, sp_oid, None, scope, resolve_assignee=False,
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/role/custom.py", line 198, in _create_role_assignment
assignments_client.config.subscription_id)
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'RoleAssignmentsOperations' object has no attribute 'config'