MeWrite Docs

Azure: AuthorizationFailed

Azure認可エラーの解決方法

概要

Azureリソースへのアクセス権限がない場合に発生するエラーです。

エラーメッセージ

1
2
3
4
5
6
{
  "error": {
    "code": "AuthorizationFailed",
    "message": "The client 'xxx' with object id 'xxx' does not have authorization to perform action 'Microsoft.Compute/virtualMachines/write'"
  }
}

原因

  1. ロール未割当: 必要なRBACロールがない
  2. スコープ不正: サブスクリプション/リソースグループレベル
  3. カスタムロール: 必要なアクションが含まれていない
  4. サービスプリンシパル: 権限設定不足

解決策

1. ロール確認

1
2
3
4
5
# 現在のロール確認
az role assignment list --assignee <object-id>

# 必要な権限確認
az role definition list --name "Contributor"

2. ロール割当

1
2
3
4
az role assignment create \
  --assignee <object-id> \
  --role "Contributor" \
  --scope /subscriptions/<subscription-id>/resourceGroups/<rg-name>

3. カスタムロール作成

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  "Name": "Custom VM Operator",
  "Actions": [
    "Microsoft.Compute/virtualMachines/*",
    "Microsoft.Network/networkInterfaces/*"
  ],
  "NotActions": [],
  "AssignableScopes": [
    "/subscriptions/<subscription-id>"
  ]
}

4. サービスプリンシパル設定

1
2
3
4
az ad sp create-for-rbac \
  --name "MyApp" \
  --role contributor \
  --scopes /subscriptions/<subscription-id>

よくある間違い

  • スコープの範囲が狭い
  • ロール割当後の反映待ち忘れ(最大5分)

最終更新: 2025-12-09