
這個錯誤訊息代表你目前的帳號雖然可以建立資源,但沒有權限指派角色(Role Assignment)。
Error message:
(AuthorizationFailed) The client '[email protected]' with object id '7a85725f' does not have authorization to perform action 'Microsoft.Authorization/roleAssignments/write' over scope '/subscriptions/XXX/resourceGroups/rg-pr-stg-jpe-001/providers/Microsoft.ContainerRegistry/registries/arcprstgjpe001/providers/Microsoft.Authorization/roleAssignments/be44c8b3' or the scope is invalid. If access was recently granted, please refresh your credentials.
Code: AuthorizationFailed
在 Azure 的權限體系中,建立資源只需要 Contributor (參與者) 權限,但指派權限(RBAC)則需要 Owner (擁有者) 或 User Access Administrator (使用者存取管理員) 權限。
核心問題:權限不足
你的帳號在該 Subscription 或 Resource Group 層級缺少 Microsoft.Authorization/roleAssignments/write 這個權限。
解決方法
聯繫管理員提升權限
你需要請該訂用帳戶的管理者,將你的帳號權限提升。
- 目標角色:Owner 或 User Access Administrator。
- 範圍:建議在資源群組
rg-pr-stg-jpe-001層級設定即可。
檢查目前的權限
你可以執行以下指令,看看自己在該資源群組下到底有什麼角色:
PowerShell
az role assignment list --assignee [email protected] --resource-group rg-pr-stg-jpe-001 --output table
暫時繞過方法:使用 Admin User (不推薦用於正式環境)
如果你急著測試 App Service 能否抓到影像,可以先避開 RBAC,直接開啟 ACR 的管理員帳號密碼:
PowerShell
# 1. 開啟 ACR 管理員功能
az acr update --name arcprstgjpe001 --admin-enabled true
# 2. 取得帳號密碼
az acr credential show --name arcprstgjpe001
開啟後,你可以直接在 App Service 的部署設定中使用這組帳密,而不需要執行 az role assignment。
長期來看,要在 CI/CD 流程中自動化設定權限,你必須具備 Owner 角色。如果是公司內部的 PoC 環境,通常會直接給予開發負責人 Owner 權限以利測試。
這兩個角色都擁有指派權限的能力,但它們在 對資源的操作權限 上有本質的區別。
Owner (擁有者)
這是權限最高的角色。
- 完全控制權:擁有者可以對該範圍(訂閱或資源群組)內的所有資源進行任何操作,包括建立、讀取、修改、刪除資源。
- 權限管理:可以指派或移除其他人的 RBAC 角色。
- 適用場景:通常給予專案負責人或系統管理員,因為他們需要處理資源的生命週期(如建立資料庫、刪除伺服器)以及團隊成員的權限。
User Access Administrator (使用者存取管理員)
這是一個專注於 安全與合規 的角色。
- 無資源操作權:這個角色不能建立、啟動或刪除資源(如虛擬機、資料庫、ACR)。如果一個帳號只有這個角色,他連建立一個 Resource Group 都辦不到。
- 權限管理:他唯一能做的就是管理角色指派。
- 適用場景:通常給予公司的資安人員或稽核人員。他們負責審核與發放權限,但不會去動到工程師的資源配置,符合最小權限原則(Principle of Least Privilege)。
比較表
| 功能 | Owner (擁有者) | User Access Administrator |
| 管理角色指派 (RBAC) | 可以 | 可以 |
| 建立/刪除 Azure 資源 | 可以 | 不可以 |
| 查看/讀取 資源內容 | 可以 | 不可以 |
| 角色性質 | 全能管理 | 純權限管理 |
針對你目前的問題
你目前遇到 AuthorizationFailed,是因為你目前的身分(可能是 Contributor)雖然可以建立 ACR,但無權指派 acrpull 權限。
- 如果你希望以後能 一條龍處理到底(建資源 + 設權限),你應該請管理員給你 Owner。
- 如果公司規範較嚴,不希望你擁有刪除所有東西的權限,但又要你能設權限,管理員則會給你 Contributor + User Access Administrator 的組合。
