首頁  >  文章  >  後端開發  >  Azure golang SDK - 將 AcrPull 角色指派給 AKS 叢集

Azure golang SDK - 將 AcrPull 角色指派給 AKS 叢集

PHPz
PHPz轉載
2024-02-10 21:39:08295瀏覽

Azure golang SDK - 将 AcrPull 角色分配给 AKS 群集

php小編新一為您介紹Azure golang SDK中的一個重要功能:將AcrPull角色指派給AKS群集。這個功能可以幫助開發者在Azure雲端平台上更方便地管理和使用容器鏡像。透過使用golang SDK,開發者可以輕鬆地為AKS群集分配AcrPull角色,從而實現在群集中拉取和使用私有容器鏡像的功能。這不僅提高了開發和部署容器化應用的效率,還增強了安全性和可控性,為開發者提供了更好的使用者體驗。

問題內容

建立 AKS 群集和 ACR 後,我現在嘗試以程式設計方式向 AKS 群集授予 AcrPull 角色。 目前我正在嘗試使用 golang SDK 中的 RoleAssignmentsClient.Create() 函數來執行此操作。

這是我迄今為止嘗試過的:

<code>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)
</code>

當我使用上述值進行呼叫時,出現以下錯誤:

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。

以上是Azure golang SDK - 將 AcrPull 角色指派給 AKS 叢集的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:stackoverflow.com。如有侵權,請聯絡admin@php.cn刪除