チュートリアル:Azure CLI を使用して Azure カスタム ロールを作成する

Azure の組み込みロールが組織の特定のニーズを満たさない場合は、独自のカスタム ロールを作成することができます。 このチュートリアルでは、Azure CLI を使用して、Reader Support Tickets というカスタム ロールを作成します。 このカスタム ロールが割り当てられたユーザーは、サブスクリプションのコントロール プレーンにすべてを表示することができ、サポート チケットを開くこともできます。

このチュートリアルでは、以下の内容を学習します。

  • カスタム ロールの作成
  • カスタム ロールの一覧表示
  • カスタム ロールの更新
  • カスタム ロールの削除

Azure サブスクリプションをお持ちでない場合は、開始する前に 無料アカウント を作成してください。

前提条件

このチュートリアルを完了するには、次の要件があります。

Azure CLI へのサインイン

Azure CLI にサインインします。

カスタム ロールの作成

カスタム ロールを作成するには、JSON テンプレートをベースに必要な変更を加えて、新しいロールを作成するのが最も簡単です。

  1. Microsoft.Support リソース プロバイダーのアクション一覧を確認します。 アクセス許可の作成に使用できるアクションを知るための参考にしてください。

    アクション 説明
    Microsoft.Support/register/action サポート リソース プロバイダーに登録します。
    Microsoft.Support/supportTickets/read サポート チケットの詳細 (ステータス、重大度、連絡先の詳細、やり取りなど) を取得するか、サブスクリプション全体のサポート チケットの一覧を取得します。
    Microsoft.Support/supportTickets/write サポート チケットを作成または更新します。 技術、課金、クォータ、またはサブスクリプション管理に関する問題のサポート チケットを作成できます。 既存のサポート チケットの重大度、連絡先の詳細、やり取りを更新できます。
  2. ReaderSupportRole.json という名前の新しいファイルを作成します。

  3. ReaderSupportRole.json をエディターで開き、次の JSON を追加します。

    各種のプロパティについては、Azure カスタム ロールに関するページを参照してください。

    {
      "Name": "",
      "IsCustom": true,
      "Description": "",
      "Actions": [],
      "NotActions": [],
      "DataActions": [],
      "NotDataActions": [],
      "AssignableScopes": [
        "/subscriptions/{subscriptionId1}"
      ]
    }
    
  4. 次のアクションを Actions プロパティに追加します。 これらのアクションによって、ユーザーはサブスクリプションに含まれるあらゆるものを閲覧したり、サポート チケットを作成したりすることができます。

    "*/read",
    "Microsoft.Support/*"
    
  5. az account list コマンドを使用して、サブスクリプションの ID を取得します。

    az account list --output table
    
  6. AssignableScopes{subscriptionId1} は、実際のサブスクリプション ID で置き換えてください。

    明示的にサブスクリプション ID を追加してください。それ以外の場合、サブスクリプションにロールをインポートできなくなります。

  7. Name プロパティと Description プロパティを、それぞれ "Reader Support Tickets" と "View everything in the subscription and also open support tickets." に変更します。

    編集後の JSON ファイルは次のようになります。

    {
      "Name": "Reader Support Tickets",
      "IsCustom": true,
      "Description": "View everything in the subscription and also open support tickets.",
      "Actions": [
        "*/read",
        "Microsoft.Support/*"
      ],
      "NotActions": [],
      "DataActions": [],
      "NotDataActions": [],
      "AssignableScopes": [
        "/subscriptions/00000000-0000-0000-0000-000000000000"
      ]
    }
    
  8. 新しいカスタム ロールを作成するには、az role definition create コマンドを使用して、JSON ロール定義ファイルを指定します。

    az role definition create --role-definition "~/CustomRoles/ReaderSupportRole.json"
    
    {
      "additionalProperties": {},
      "assignableScopes": [
        "/subscriptions/00000000-0000-0000-0000-000000000000"
      ],
      "description": "View everything in the subscription and also open support tickets.",
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/22222222-2222-2222-2222-222222222222",
      "name": "22222222-2222-2222-2222-222222222222",
      "permissions": [
        {
          "actions": [
            "*/read",
            "Microsoft.Support/*"
          ],
          "additionalProperties": {},
          "dataActions": [],
          "notActions": [],
          "notDataActions": []
        }
      ],
      "roleName": "Reader Support Tickets",
      "roleType": "CustomRole",
      "type": "Microsoft.Authorization/roleDefinitions"
    }
    

    新しいカスタム ロールが利用できる状態となり、組み込みロールと同じように、ユーザー、グループ、またはサービス プリンシパルに割り当てることができます。

カスタム ロールの一覧表示

  • すべてのカスタム ロールを一覧表示するには、az role definition list コマンドに --custom-role-only パラメーターを組み合わせて使用します。

    az role definition list --custom-role-only true
    
    [
      {
        "additionalProperties": {},
        "assignableScopes": [
          "/subscriptions/00000000-0000-0000-0000-000000000000"
        ],
        "description": "View everything in the subscription and also open support tickets.",
        "id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/22222222-2222-2222-2222-222222222222",
        "name": "22222222-2222-2222-2222-222222222222",
        "permissions": [
          {
            "actions": [
              "*/read",
              "Microsoft.Support/*",
              "Microsoft.Resources/deployments/*",
              "Microsoft.Insights/diagnosticSettings/*/read"
            ],
            "additionalProperties": {},
            "dataActions": [],
            "notActions": [],
            "notDataActions": []
          }
        ],
        "roleName": "Reader Support Tickets",
        "roleType": "CustomRole",
        "type": "Microsoft.Authorization/roleDefinitions"
      }
    ]
    

    カスタム ロールは、Azure portal で確認することもできます。

    screenshot of custom role imported in the Azure portal

カスタム ロールの更新

カスタム ロールを更新するには、JSON ファイルを更新してカスタム ロールを更新します。

  1. ReaderSupportRole.json ファイルを開きます。

  2. Actions に、リソース グループのデプロイを作成および管理するためのアクションを追加します ("Microsoft.Resources/deployments/*")。 前のアクションの後に必ずコンマを追加してください。

    更新後の JSON ファイルは次のようになります。

    {
      "Name": "Reader Support Tickets",
      "IsCustom": true,
      "Description": "View everything in the subscription and also open support tickets.",
      "Actions": [
        "*/read",
        "Microsoft.Support/*",
        "Microsoft.Resources/deployments/*"
      ],
      "NotActions": [],
      "DataActions": [],
      "NotDataActions": [],
      "AssignableScopes": [
        "/subscriptions/00000000-0000-0000-0000-000000000000"
      ]
    }
    
  3. カスタム ロールを更新するには、az role definition update コマンドを使用して、更新済みの JSON ファイルを指定します。

    az role definition update --role-definition "~/CustomRoles/ReaderSupportRole.json"
    
    {
      "additionalProperties": {},
      "assignableScopes": [
        "/subscriptions/00000000-0000-0000-0000-000000000000"
      ],
      "description": "View everything in the subscription and also open support tickets.",
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/22222222-2222-2222-2222-222222222222",
      "name": "22222222-2222-2222-2222-222222222222",
      "permissions": [
        {
          "actions": [
            "*/read",
            "Microsoft.Support/*",
            "Microsoft.Resources/deployments/*"
          ],
          "additionalProperties": {},
          "dataActions": [],
          "notActions": [],
          "notDataActions": []
        }
      ],
      "roleName": "Reader Support Tickets",
      "roleType": "CustomRole",
      "type": "Microsoft.Authorization/roleDefinitions"
    }
    

カスタム ロールの削除

  • az role definition delete コマンドを使用し、ロール名またはロール ID を指定してカスタム ロールを削除します。

    az role definition delete --name "Reader Support Tickets"
    

次のステップ