php小編新一為您介紹Azure golang SDK中的一個重要功能:將AcrPull角色分配給AKS群集。這個功能可以幫助開發者在Azure云平臺上更便捷地管理和使用容器鏡像。通過使用golang SDK,開發者可以輕松地為AKS群集分配AcrPull角色,從而實現在群集中拉取和使用私有容器鏡像的功能。這不僅提高了開發和部署容器化應用的效率,還增強了安全性和可控性,為開發者提供了更好的用戶體驗。
問題內容
創建 AKS 群集和 ACR 后,我現在嘗試以編程方式向 AKS 群集授予 AcrPull
角色。
目前我正在嘗試使用 golang SDK 中的 RoleAssignmentsClient.Create() 函數來執行此操作。
這是我迄今為止嘗試過的:
AcrPullDefinitionID := "/providers/Microsoft.Authorization/roleDefinitions/7f951dda-4ed3-4680-a7ca-43fe172d538d"
// pulled that ^ off of: https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#acrpull
providerNamespace := "/providers/Microsoft.ContainerService/managedClusters/"
scope := "/subscriptions/" + subscriptionID + "/resourceGroups/" + resourceGroupName + providerNamespace + resourceName
res, err := raClient.Create(ctx, scope, roleAssigmentName, armauthorization.RoleAssignmentCreateParameters{
Properties: &armauthorization.RoleAssignmentProperties{
PrincipalID: to.Ptr(clientID),
PrincipalType: to.Ptr(armauthorization.PrincipalTypeServicePrincipal),
RoleDefinitionID: to.Ptr("/subscriptions/" + subscriptionID + AcrPullDefinitionID),
},
}, nil)
登錄后復制
當我使用上述值進行調用時,出現以下錯誤:
for resource: {AKSClusterName} of type: /providers/Microsoft.ContainerService/managedClusters/ Unable to create roleAssignment: PUT https://management.azure.com/subscriptions/{subscriptionID}/resourceGroups/{resourceGroup}/providers/Microsoft.ContainerService/managedClusters/{AKSClusterName}/providers/Microsoft.Authorization/roleAssignments/providers/Microsoft.Authorization/roleDefinitions/7f951dda-4ed3-4680-a7ca-43fe172d538d -------------------------------------------------------------------------------- RESPONSE 405: 405 Method Not Allowed ERROR CODE UNAVAILABLE -------------------------------------------------------------------------------- { "message": "The requested resource does not support http method 'PUT'." } --------------------------------------------------------------------------------
登錄后復制
我不確定這是一個概念上的誤解還是我只是錯誤地使用了 API。
任何和所有幫助將不勝感激。謝謝!
解決方法
您指向的范圍似乎不正確。應用RBAC權限時,需要將范圍設置為RBAC策略應用的資源。
因此,如果您要為 AKS 集群應用 RBAC 策略以擁有 AcrPull
權限,則范圍應設置為 Azure 容器注冊表的資源 ID。