使用China Azure,通过Azure CLI 创建AAD组报错,提示权限不足 Insufficient privileges to complete the operation
# 使用这个登录: az login --service-principal --username xxx--password xxx--tenant xxx #执行 az ad group create az ad group create --display-name GroupTestAdministrator --mail-nickname azuretest
为了查看更完整的错误信息,在 az ad group create 命令中添加 --debug 参数,用于输出完整的日志信息:
$ az ad group create --debug --display-name GroupTestAdministrator --mail-nickname azuretest cli.knack.cli: Command arguments: ['ad', 'group', 'create', '--debug', '--display-name', 'GroupTestAdministrator', '--mail-nickname', 'azuretest'] cli.knack.cli: __init__ debug log: ... ... urllib3.connectionpool: Starting new HTTPS connection (1): graph.chinacloudapi.cn:443 urllib3.connectionpool: https://graph.chinacloudapi.cn:443 "POST /xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/groups?api-version=1.6 HTTP/1.1" 403 219 msrest.http_logger: Response status: 403 msrest.http_logger: Response headers: ... ... msrest.exceptions: Insufficient privileges to complete the operation.
查看以上错误日志,最主要的信息是在请求接口 https://graph.chinacloudapi.cn 时,报错403。而 graph.chinacloudapi.cn 是使用的旧的Azure AD Graph终结点。现在新的为 Microsoft Graph(https://microsoftgraph.chinacloudapi.cn/)。
Azure Active Directory (Azure AD) Graph 已弃用,将于近期停用。 作为此弃用路径的一部分,现在已禁用通过Azure 门户向应用注册添加 Azure AD Graph 权限。
为应用注册配置所需的 Azure AD Graph 权限:https://learn.microsoft.com/zh-cn/graph/migrate-azure-ad-graph-configure-permissions
所以,根据此文的介绍,如要继续使用 az ad group create 创建AD Group,可以修改注册应用的清单权限,来实现赋权。详细步骤见:https://learn.microsoft.com/zh-cn/graph/migrate-azure-ad-graph-configure-permissions#option-2-update-the-application-manifest-on-the-azure-portal
Windows Azure Active Directory
或 00000002-0000-0000-c000-000000000000 下的所有Role ID。
通过Azure CLI指令: az ad sp show --id 00000002-0000-0000-c000-000000000000 , 过滤出结果zhozho能够的 Role ID。
"requiredResourceAccess": [ { "resourceAppId": "00000002-0000-0000-c000-000000000000", "resourceAccess": [ { "id": "a42657d6-7f20-40e3-b6f0-cee03008a62a", "type": "Scope" }, { "id": "5778995a-e1bf-45b8-affa-663a9f3f4d04", "type": "Scope" }, { "id": "78c8a3c8-a07e-4b9e-af1b-b5ccab50a175", "type": "Scope" }, { "id": "6234d376-f627-4f0f-90e0-dff25c5211a3", "type": "Scope" }, { "id": "970d6fa6-214a-4a9b-8513-08fad511e2fd", "type": "Scope" }, { "id": "311a71cc-e848-46a1-bdf8-97ff7156d8e6", "type": "Scope" }, { "id": "c582532d-9d9e-43bd-a97c-2667a28ce295", "type": "Scope" }, { "id": "cba73afc-7f69-4d86-8450-4978e04ecd1a", "type": "Scope" }, { "id": "5778995a-e1bf-45b8-affa-663a9f3f4d04", "type": "Role" }, { "id": "78c8a3c8-a07e-4b9e-af1b-b5ccab50a175", "type": "Role" } ] }, { "resourceAppId": "00000003-0000-0000-c000-000000000000", "resourceAccess": [ { "id": "8b010b06-ce5b-41ce-bc8b-fa9acdb14371", "type": "Scope" } ] } ],
更新Azure 门户上的应用程序清单 : https://learn.microsoft.com/zh-cn/graph/migrate-azure-ad-graph-configure-permissions#option-2-update-the-application-manifest-on-the-azure-portal