Azure RBAC の変更のアクティビティ ログを表示する

監査やトラブルシューティングなどの目的で、Azure のロールベースのアクセス制御 (Azure RBAC) の変更に関する情報が必要になる場合があります。 サブスクリプション内のロール割り当てまたはロール定義が変更されると、常に Azure アクティビティ ログに変更が記録されます。 アクティビティ ログを表示して、過去 90 日間の Azure RBAC のすべての変更を確認できます。

ログに記録される操作

アクティビティ ログに記録される Azure RBAC 関連の操作を次に示します。

  • ロール割り当ての作成
  • ロール割り当ての削除
  • カスタムのロール定義の作成または更新
  • カスタムのロール定義の削除

Azure Portal

作業を開始する最も簡単な方法は、Azure portal でアクティビティ ログを表示することです。 次のスクリーンショットは、アクティビティ ログのロール割り当て操作の例を示しています。 ログを CSV ファイルとしてダウンロードするオプションも含まれています。

Activity logs using the portal - screenshot

詳細を表示するには、エントリをクリックし、[概要] ウィンドウを開きます。 [JSON] タブをクリックし、詳細なログを取得します。

Activity logs using the portal with summary pane open - screenshot

ポータルのアクティビティ ログには複数のフィルターがあります。 Azure RBAC 関連のフィルターを次に示します。

Assert
イベント カテゴリ
  • 管理
操作
  • ロール割り当ての作成
  • ロール割り当ての削除
  • カスタムのロール定義の作成または更新
  • カスタムのロール定義の削除

アクティビティ ログの詳細については、「Azure アクティビティ ログ」を参照してください。

ログ エントリの解釈

[JSON] タブ、Azure PowerShell、または Azure CLI からのログ出力にはたくさんの情報が含まれていることがあります。 ログ エントリの解釈を試みるとき、次のような主要なプロパティをご確認ください。 Azure PowerShell または Azure CLI を利用し、ログ出力をフィルター処理する方法については、次のセクションをご覧ください。

プロパティ サンプル値 説明
authorization:action Microsoft.Authorization/roleAssignments/write ロール割り当ての作成
Microsoft.Authorization/roleAssignments/delete ロール割り当ての削除
Microsoft.Authorization/roleDefinitions/write ロールの定義の作成または更新
Microsoft.Authorization/roleDefinitions/delete ロールの定義の削除
authorization:scope /subscriptions/{subscriptionId}
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}
アクションのスコープ
caller admin@example.com
{objectId}
アクションを開始したユーザー
eventTimestamp 2021-03-01T22:07:41.126243Z アクションが発生した時刻
status:value 開始済み
成功しました
失敗
アクションの状態

Azure PowerShell

Azure PowerShell を使用してアクティビティ ログを表示するには、Get-AzLog コマンドを使用します。

このコマンドでは、過去 7 日間のサブスクリプションのロール割り当てのすべての変更が一覧表示されます。

Get-AzLog -StartTime (Get-Date).AddDays(-7) | Where-Object {$_.Authorization.Action -like 'Microsoft.Authorization/roleAssignments/*'}

このコマンドでは、過去 7 日間のリソース グループのロール定義のすべての変更が一覧表示されます。

Get-AzLog -ResourceGroupName pharma-sales -StartTime (Get-Date).AddDays(-7) | Where-Object {$_.Authorization.Action -like 'Microsoft.Authorization/roleDefinitions/*'}

ログ出力のフィルター処理

ログ出力には大量の情報が含まれることがあります。 このコマンドでは、あるサブスクリプションに含まれるロールの割り当てとロールの定義のすべての変更が過去 7 日間分、一覧表示され、出力がフィルター処理されます。

Get-AzLog -StartTime (Get-Date).AddDays(-7) | Where-Object {$_.Authorization.Action -like 'Microsoft.Authorization/role*'} | Format-List Caller,EventTimestamp,{$_.Authorization.Action},Properties

次からは、ロールの割り当ての作成時、ログ出力がフィルター処理された例を確認できます。

Caller                  : admin@example.com
EventTimestamp          : 3/1/2021 10:07:42 PM
$_.Authorization.Action : Microsoft.Authorization/roleAssignments/write
Properties              :
                          statusCode     : Created
                          serviceRequestId: {serviceRequestId}
                          eventCategory  : Administrative
                          entity         : /subscriptions/{subscriptionId}/resourceGroups/example-group/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}
                          message        : Microsoft.Authorization/roleAssignments/write
                          hierarchy      : {tenantId}/{subscriptionId}

Caller                  : admin@example.com
EventTimestamp          : 3/1/2021 10:07:41 PM
$_.Authorization.Action : Microsoft.Authorization/roleAssignments/write
Properties              :
                          requestbody    : {"Id":"{roleAssignmentId}","Properties":{"PrincipalId":"{principalId}","PrincipalType":"User","RoleDefinitionId":"/providers/Microsoft.Authorization/roleDefinitions/fa23ad8b-c56e-40d8-ac0c-ce449e1d2c64","Scope":"/subscriptions/
                          {subscriptionId}/resourceGroups/example-group"}}
                          eventCategory  : Administrative
                          entity         : /subscriptions/{subscriptionId}/resourceGroups/example-group/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}
                          message        : Microsoft.Authorization/roleAssignments/write
                          hierarchy      : {tenantId}/{subscriptionId}

サービス プリンシパルを使用してロールの割り当てを作成する場合、Caller プロパティはサービス プリンシパル オブジェクト ID になります。 サービス プリンシパルに関する情報は、Get-AzADServicePrincipal で取得できます。

Caller                  : {objectId}
EventTimestamp          : 3/1/2021 9:43:08 PM
$_.Authorization.Action : Microsoft.Authorization/roleAssignments/write
Properties              : 
                          statusCode     : Created
                          serviceRequestId: {serviceRequestId}
                          eventCategory  : Administrative

Azure CLI

Azure CLI を使用してアクティビティ ログを表示するには、az monitor activity-log list コマンドを使用します。

このコマンドでは、あるリソース グループの 3 月 1 日から 7 日間のアクティビティ ログが一覧表示されます。

az monitor activity-log list --resource-group example-group --start-time 2021-03-01 --offset 7d

このコマンドでは、Authorization リソース プロバイダーの 3 月 1 日から 7 日間のアクティビティ ログが一覧表示されます。

az monitor activity-log list --namespace "Microsoft.Authorization" --start-time 2021-03-01 --offset 7d

ログ出力のフィルター処理

ログ出力には大量の情報が含まれることがあります。 このコマンドでは、あるサブスクリプションに含まれるロールの割り当てとロールの定義のすべての変更が 7 日間分、一覧表示され、出力がフィルター処理されます。

az monitor activity-log list --namespace "Microsoft.Authorization" --start-time 2021-03-01 --offset 7d --query '[].{authorization:authorization, caller:caller, eventTimestamp:eventTimestamp, properties:properties}'

次からは、ロールの割り当ての作成時、ログ出力がフィルター処理された例を確認できます。

[
 {
    "authorization": {
      "action": "Microsoft.Authorization/roleAssignments/write",
      "role": null,
      "scope": "/subscriptions/{subscriptionId}/resourceGroups/example-group/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}"
    },
    "caller": "admin@example.com",
    "eventTimestamp": "2021-03-01T22:07:42.456241+00:00",
    "properties": {
      "entity": "/subscriptions/{subscriptionId}/resourceGroups/example-group/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}",
      "eventCategory": "Administrative",
      "hierarchy": "{tenantId}/{subscriptionId}",
      "message": "Microsoft.Authorization/roleAssignments/write",
      "serviceRequestId": "{serviceRequestId}",
      "statusCode": "Created"
    }
  },
  {
    "authorization": {
      "action": "Microsoft.Authorization/roleAssignments/write",
      "role": null,
      "scope": "/subscriptions/{subscriptionId}/resourceGroups/example-group/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}"
    },
    "caller": "admin@example.com",
    "eventTimestamp": "2021-03-01T22:07:41.126243+00:00",
    "properties": {
      "entity": "/subscriptions/{subscriptionId}/resourceGroups/example-group/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}",
      "eventCategory": "Administrative",
      "hierarchy": "{tenantId}/{subscriptionId}",
      "message": "Microsoft.Authorization/roleAssignments/write",
      "requestbody": "{\"Id\":\"{roleAssignmentId}\",\"Properties\":{\"PrincipalId\":\"{principalId}\",\"PrincipalType\":\"User\",\"RoleDefinitionId\":\"/providers/Microsoft.Authorization/roleDefinitions/fa23ad8b-c56e-40d8-ac0c-ce449e1d2c64\",\"Scope\":\"/subscriptions/{subscriptionId}/resourceGroups/example-group\"}}"
    }
  }
]

Azure Monitor ログ

Azure Monitor ログは、Azure のすべてのリソースに対する Azure RBAC の変更の収集および分析に使用できる別のツールです。 Azure Monitor ログには、次のような利点があります。

  • 複雑なクエリとロジックを記述する
  • アラート、Power BI、およびその他のツールと統合する
  • より長い保有期間でデータを保存する
  • セキュリティ、仮想マシン、およびカスタムなど他のログを相互参照する

作業を開始する基本的な手順を次に示します。

  1. Log Analytics ワークスペースを作成します

  2. ワークスペースのアクティビティを構成します。

  3. アクティビティ ログの分析情報を表示します[ログ] オプションをクリックすると、[アクティビティ ログの概要] ページにすぐに移動できます。

    Azure Monitor logs option in portal

  4. 必要に応じて、Azure Monitor Log Analytics を使用して、ログのクエリと表示を行うことができます。 詳細については、「Azure Monitor でログ クエリの使用を開始する」を参照してください。

ターゲットのリソース プロバイダー別に編成された新しいロール割り当てを返すクエリを、次に示します。

AzureActivity
| where TimeGenerated > ago(60d) and Authorization contains "Microsoft.Authorization/roleAssignments/write" and ActivityStatus == "Succeeded"
| parse ResourceId with * "/providers/" TargetResourceAuthProvider "/" *
| summarize count(), makeset(Caller) by TargetResourceAuthProvider

グラフに表示されるロール割り当ての変更を返すクエリを、次に示します。

AzureActivity
| where TimeGenerated > ago(60d) and Authorization contains "Microsoft.Authorization/roleAssignments"
| summarize count() by bin(TimeGenerated, 1d), OperationName
| render timechart

Activity logs using the Advanced Analytics portal - screenshot

次のステップ