无法创建 Azure AKS 集群:CreateRoleAssignmentError

Cannot create Azure AKS cluster: CreateRoleAssignmentError

我尝试在全新订阅中创建 AKS 群集。通过 Web 界面创建集群时,最终会产生 CreateRoleAssignmentError 错误,并显示以下消息:

RoleAssignmentReconciler retry timed out: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client 'foo' with object id 'foo' does not have authorization to perform action 'Microsoft.Authorization/roleAssignments/write' over scope '/subscriptions/bar/resourceGroups/MC_MyResourceGroup_mycluster_region/providers/Microsoft.Authorization/roleAssignments/az

请注意,根据 documentation,集群是使用手动创建的服务主体创建的。此服务主体对订阅中的所有资源组具有 "Owner" 角色。

另请注意,我必须手动创建服务主体的原因是首先无法创建集群。尝试在未明确指定服务主体(即请求自动创建新服务主体)的情况下创建集群时,产生了另一个错误:

The credentials in ServicePrincipalProfile were invalid. Please see https://aka.ms/aks-sp-help for more details. (Details: adal: Refresh request failed. Status Code = '400'. Response body: {"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier 'foo' was not found in the directory 'bar'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.\r\nTrace ID: 9ec6ed81-892d-4592-b7b5-61842f5c1200\r\nCorrelation ID: bffbb112-7348-4403-a36f-3010bf34e594\r\nTimestamp: 2019-07-13 15:48:02Z","error_codes":[700016],"timestamp":"2019-07-13 15:48:02Z","trace_id":"9ec6ed81-892d-4592-b7b5-61842f5c1200","correlation_id":"bffbb112-7348-4403-a36f-3010bf34e594","error_uri":"https://login.microsoftonline.com/error?code=700016"})

我正在使用 "initial" 管理员用户对新帐户和订阅进行这些操作,因此我认为所有权限都应该到位。什么可以解释上面的错误?

正如 OP 所问,这就是答案。为了在 Azure 中创建资源(无论是哪些资源),您需要以下类型的权限:provider/resource/write。编辑也是如此。这个基本原则适用于那里的所有资源。现在让我们比较所有者和贡献者:

我有一个 AKS 模板需要贡献者角色才能工作 + 这个自定义角色:

$role = Get-AzureRmRoleDefinition "Virtual Machine Contributor"
$role.Id = $null
$role.Name = "Assign AKS permissions to the vnet"
$role.Description = "Assign AKS permissions to the vnet for the inflation process"
$role.Actions.Clear()
$role.Actions.Add("Microsoft.Authorization/roleAssignments/write")

使用此角色 + 贡献者的代码创建的 AKS 集群功能齐全。

User Access Administrator 是一个 built-in 角色,当您是租户时,您将被授予此角色,并且您授予自己访问租户下的所有内容的权限:https://docs.microsoft.com/en-us/azure/role-based-access-control/elevate-access-global-admin。因此,如果您授予自己此角色,它显然会起作用,但您可以通过更少的权限逃脱。

在我的例子中,我通过再次执行 "az login" 并移动到正确的订阅来解决它,然后我再次尝试 运行 命令。成功了。

另外一个原因可能是您没有在该资源组上创建集群的权限。我以前遇到过这种问题,为此你应该联系管理你订阅的人给你权限。