Azure CLI で AWS と接続する Microsoft Sentinel データコネクタを追加する

2023.06.22

Microsoft Sentinel では AWS のログを収集できます。今回のブログでは、AWS CloudTrail のログを収集するデータコネクタを Azure CLI で追加してみたいと思います。

結論としては、次のコマンド例で AWS と接続するデータコネクタを追加できます。

$ az sentinel data-connector create \
  --data-connector-id aws-111122223333-cloudtrail \
  --resource-group test-sentinel-rg \
  --workspace-name test-sentinel-ws \
  --aws-s3 "{data-types:{logs:{state:Enabled}},destination-table:AWSCloudTrail,role-arn:'arn:aws:iam::111122223333:role/ms-sentinel-role',sqs-urls:['https://sqs.ap-northeast-1.amazonaws.com/111122223333/ms-sentinel-queue']}"


なお、Azure ポータルで AWS に接続するデータコネクタを追加する方法は下記のブログで紹介しています。

AWS と接続するデータコネクタの追加

Microsoft Sentinel のデータコネクタの追加はaz sentinel data-connectorコマンドで実行します。

az sentinel data-connector | Microsoft Learn


az sentinel data-connectorコマンドを実行するためには、Sentinel 拡張機能のインストールが必要となります。拡張機能はaz sentinel data-connectorコマンドを初めて実行するときにインストールするかどうか聞かれます。


データコネクタを追加する前にデータコネクタ一覧を次のコマンドで確認してみます。

az sentinel data-connector list \
  --resource-group test-sentinel-rg \
  --workspace-name test-sentinel-ws

実行結果です。今回の環境は事前にデータコネクタが一つも無い状況です。

$ az sentinel data-connector list \
  --resource-group test-sentinel-rg \
  --workspace-name test-sentinel-ws
This command is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
[]


データコネクタ追加

今回追加するコネクタはアマゾン ウェブ サービス S3 (プレビュー)AWSCloudTrailテーブルとします。

接続のために必要な AWS リソースの情報は、ロール ARN と SQS URL であり、AWS 側で必要なリソースは次のブログでも紹介しています。


az sentinel data-connector createコマンドでデータコネクタを追加します。

az sentinel data-connector | Microsoft Learn


アマゾン ウェブ サービス S3 (プレビュー)の追加に該当するオプションはaws-s3であり、オプションのパラメータで AWS CloudTrail を指定します。aws-cloud-trailオプションはアマゾン ウェブ サービスコネクタに該当します。似ているため注意が必要です。

aws-s3オプションの指定値は??で確認できます。

$ az sentinel data-connector create --aws-s3 ??

Argument
    --aws-s3 : Object
        Amazon web services s3.
        See https://github.com/Azure/azure-cli/tree/dev/doc/shorthand_syntax.md for more about
        shorthand syntax.

Object Properties
    data-types        : The available data types for the connector.  Try `??` to show more.
    destination-table : The logs destination table name in LogAnalytics.
    role-arn          : The Aws Role Arn that is used to access the Aws account.
    sqs-urls          : The AWS sqs urls for the connector.  Try `??` to show more.

aws-s3オプションで指定する JSON の例です。

{
  "data-types": { "logs": { "state": "Enabled" } },
  "destination-table": "AWSCloudTrail",
  "role-arn": "arn:aws:iam::111122223333:role/ms-sentinel-role",
  "sqs-urls": [
    "https://sqs.ap-northeast-1.amazonaws.com/111122223333/ms-sentinel-queue"
  ]
}

次のコマンドで AWS と接続するデータコネクタを追加します。

$ az sentinel data-connector create \
  --data-connector-id aws-111122223333-cloudtrail \
  --resource-group test-sentinel-rg \
  --workspace-name test-sentinel-ws \
  --aws-s3 "{data-types:{logs:{state:Enabled}},destination-table:AWSCloudTrail,role-arn:'arn:aws:iam::111122223333:role/ms-sentinel-role',sqs-urls:['https://sqs.ap-northeast-1.amazonaws.com/111122223333/ms-sentinel-queue']}"

実行結果例です。

$ az sentinel data-connector create \
  --data-connector-id aws-111122223333-cloudtrail \
  --resource-group test-sentinel-rg \
  --workspace-name test-sentinel-ws \
  --aws-s3 "{data-types:{logs:{state:Enabled}},destination-table:AWSCloudTrail,role-arn:'arn:aws:iam::111122223333:role/ms-sentinel-role',sqs-urls:['https://sqs.ap-northeast-1.amazonaws.com/111122223333/ms-sentinel-queue']}"
This command is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
{
  "dataTypes": {
    "logs": {
      "state": "enabled"
    }
  },
  "destinationTable": "AWSCloudTrail",
  "etag": "4955c8f0-e347-4e6b-ac1a-e1775example",
  "id": "/subscriptions/eab80a4f-1fd9-464d-b71c-d3cd6example/resourceGroups/test-sentinel-rg/providers/Microsoft.OperationalInsights/workspaces/test-sentinel-ws/providers/Microsoft.SecurityInsights/dataConnectors/aws-111122223333-cloudtrail",
  "kind": "AmazonWebServicesS3",
  "name": "aws-111122223333-cloudtrail",
  "resourceGroup": "test-sentinel-rg",
  "roleArn": "arn:aws:iam::111122223333:role/ms-sentinel-role",
  "sqsUrls": [
    "https://sqs.ap-northeast-1.amazonaws.com/111122223333/ms-sentinel-queue"
  ],
  "type": "Microsoft.SecurityInsights/dataConnectors"
}


データコネクタ追加の確認

データコネクタ一覧を確認してみたところ、先ほど追加したコネクタが追加されていました。

$ az sentinel data-connector list \
  --resource-group test-sentinel-rg \
  --workspace-name test-sentinel-ws
This command is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
[
  {
    "dataTypes": {
      "logs": {
        "state": "enabled"
      }
    },
    "destinationTable": "AWSCloudTrail",
    "etag": "4955c8f0-e347-4e6b-ac1a-e1775example",
    "id": "/subscriptions/eab80a4f-1fd9-464d-b71c-d3cd6example/resourceGroups/test-sentinel-rg/providers/Microsoft.OperationalInsights/workspaces/test-sentinel-ws/providers/Microsoft.SecurityInsights/dataConnectors/aws-111122223333-cloudtrail",
    "kind": "AmazonWebServicesS3",
    "name": "aws-111122223333-cloudtrail",
    "resourceGroup": "test-sentinel-rg",
    "roleArn": "arn:aws:iam::111122223333:role/ms-sentinel-role",
    "sqsUrls": [
      "https://sqs.ap-northeast-1.amazonaws.com/111122223333/ms-sentinel-queue"
    ],
    "type": "Microsoft.SecurityInsights/dataConnectors"
  }
]

az sentinel data-connector showコマンドで個別のコネクタを確認することもできます。

az sentinel data-connector | Microsoft Learn

$ az sentinel data-connector show \
  --data-connector-id aws-111122223333-cloudtrail \
  --resource-group test-sentinel-rg \
  --workspace-name test-sentinel-ws
This command is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
{
  "dataTypes": {
    "logs": {
      "state": "enabled"
    }
  },
  "destinationTable": "AWSCloudTrail",
  "etag": "4955c8f0-e347-4e6b-ac1a-e1775example",
  "id": "/subscriptions/eab80a4f-1fd9-464d-b71c-d3cd6example/resourceGroups/test-sentinel-rg/providers/Microsoft.OperationalInsights/workspaces/test-sentinel-ws/providers/Microsoft.SecurityInsights/dataConnectors/aws-111122223333-cloudtrail",
  "kind": "AmazonWebServicesS3",
  "name": "aws-111122223333-cloudtrail",
  "resourceGroup": "test-sentinel-rg",
  "roleArn": "arn:aws:iam::111122223333:role/ms-sentinel-role",
  "sqsUrls": [
    "https://sqs.ap-northeast-1.amazonaws.com/111122223333/ms-sentinel-queue"
  ],
  "type": "Microsoft.SecurityInsights/dataConnectors"
}

以上でデータコネクタ追加の確認は終わりです。

さいごに

Microsoft Sentinel のデータコネクタ追加作業を Azure ポータルで実行するより簡略化したく、Azure CLI で試してみました。

このブログがどなたかのご参考になれば幸いです。