az role assignment create --resource-group with AD-group -- The api-version '2018-01-01-preview' is invalid
az feedbackauto-generates most of the information requested below, as of CLI version az --version
azure-cli 2.0.77
Describe the bug When trying to add a Azure Active Directory-group to a role on Resourcegroup-level the response is that the API-version is not matching.
ERROR: The api-version '2018-01-01-preview' is invalid. The supported versions are '2019-11-01,2019-10-01,2019-09-01,2019-08-01,2019-07-01,2019-06-01,2019-05-10,2019-05-01,2019-03-01,2018-11-01,2018-09-01,2018-08-01,2018-07-01,2018-06-01,2018-05-01,201 8-02-01,2018-01-01,2017-12-01,2017-08-01,2017-06-01,2017-05-10,2017-05-01,2017-03-01,2016-09-01,2016-07-01,2016-06-01,2016-02-01,2015-11-01,2015-01-01,2014-04-01-preview,2014-04-01,2014-01-01,2013-03-01,2014-02-26,2014-04'.
az role assignment create --assignee $Aadgroup.Objectid --role "C ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : NotSpecified: (ERROR: The api-...02-26,2014-04'.:String) [], RemoteException
FullyQualifiedErrorId : NativeCommandError
To Reproduce
When running the command 'az role assignment create --assignee-object-id $Aadgroup.Objectid --role "Contributor" --resource-group $ResourceGroup.id' az role assignment create --assignee $Aadgroup.Objectid --role "Contributor" --resource-group $ResourceGroup.id
$Aadgroup = the object returned from "az ad group list | ConvertFrom-Json" $Aadgroup.Objectid = GUID.
$ResourceGroup = the object returned from 'az group list | ConvertFrom-Json'
$ResourceGroup.id = '/subscriptions/<
Expected behavior That the Active Directory Group is added to the role with the Resourcegroup-scope.
Environment summary Az CLI - PowerShell
command-modules-nspkg 2.0.3 core 2.0.77 nspkg 3.0.4 telemetry 1.0.4 Extensions: azure-devops 0.16.0
Python location '\Azure\CLI2\python.exe' Extensions directory '.azure\cliextensions'
Additional context Closed it, as the previous version had the wrong id in the Assignee ( ugh ) but even with the correct ID, it gives the same issue.
@jiasli Please take a look.
add to S165.
@qianwens This issue may be related to Python SDK, try to repro.
@Kinjara , I cannot repro this issue with the latest Azure CLI. Could you please try again after upgrade your Azure CLI to the latest version. Besides, did you use pip install to install Azure CLI? If so, there may be some SDK version mismatch by some other installation, could you please use pip install azure-cli to upgrade the SDK and try again? Please let us know if it still not work.
Hi Qianwens,
Thank you for your reply; i will update the Az-CLI and try agian. However i installed it with the Powershell-line( Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows [...] ). I'll try again today and see if it works, because that would be utterly awesome! :D
This seems to be related to #10641. Could you capture the --debug output and send to my email <my_github_id>@microsoft.com? Thanks.
I see where the problem is. In this script
$ResourceGroup = the object returned from 'az group list | ConvertFrom-Json'
$ResourceGroup.id = '/subscriptions/<>/resourceGroups/<<resourcegroup_name>>'
az role assignment create --assignee-object-id $Aadgroup.Objectid --role "Contributor" --resource-group $ResourceGroup.id
In az role assignment create, when --resource-group is used, the argument should be resource group name, instead of id. If id is used, the REST API call will become:
GET https://management.azure.com/subscriptions/{}/resourceGroups/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Authorization/roleDefinitions?$filter=roleName%20eq%20%27Contributor%27&api-version=2018-01-01-preview
Note that /subscriptions/{}/resourceGroups is duplicated. Thus the URL is corrupted and falls back to the default Resource Groups REST API, but api-version doesn't meet this API's requirement, which is why your are seeing this error.
Instead, resource group id should be used with --scope.
So this doesn't work:
az role assignment create --assignee-object-id {} --role "Contributor" --resource-group /subscriptions/{}/resourceGroups/{name}
These work:
az role assignment create --assignee-object-id {} --role "Contributor" --resource-group {name}
az role assignment create --assignee-object-id {} --role "Contributor" --scope /subscriptions/{}/resourceGroups/{name}
Please let me know if this solves the issue.
@Kinjara Please confirm whether above solution can solve your problem.
Sorry for the slow response; i have not tested it but you can close the ticket... Scope makes sense to use :)