问题描述
本地环境中,执行 az ad user show -id 时候,报错 insufficient privileges to complete the operation !
问题解答
此报错说明,登录Azure (az login) 时,所使用的账号权限不足所导致的。
AZ AD USER SHOW -ID 命令是获取全部用户信息的命令,根据文档,执行这个命令需要User.Read.All的权限。
如果登录所使用的账号 ( 注册应用 Service Principl ) 中已经被赋予了足够的权限,但重新登陆后,报错依旧。则可以考虑先清空本地缓存后重试。
清空本地缓存的办法:
1) 清空该目录 ( C:\Users\<username>\.Azure ) 下的文件
2) 登录AAD,并使用 --debug 输出日志
az login --service-principal --username xxx --password "xxx" --tenant xxx --allow-no-subscriptions --debug
3)执行 user show 命令
az ad user show --id xxx --debug
此外,也可以检查az 的版本,查看登录账户的Access Token以供分析
az version
获取ms graph token,并使用 https://jwt.ms 中解析
az account get-access-token --resource-type ms-graph --debug
参考资料
permissions for az ad user show:https://github.com/Azure/azure-cli/issues/11029
Get a user:https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http