昨今のサイバー攻撃の激化に対応するために個人のクラウド環境や自宅NWの監視を強化しているところ。 今回は Google Cloud の管理者の監査ログを Sentinel に転送し、監視する話です。
目次
実現しようとしているログ集約と監視の全体像
今回の Google Cloud のログ転送する目的は、個人のクラウド環境と自宅NWのすべてのログをSentinel に集約し、セキュリティ観点で重大な問題やその予兆が起きたらすぐに私が気づける状態にすることが目標です。
例えば、知らぬうちに Google Cloud に不正ログインされて、勝手にマイニングされたり第三者へ攻撃に利用されるようなことをいち早く気づきたい、という感じです。
ポイントは何個かあって、1つは”私が気づけること”です。 もうちょっというと、個人の環境の特性として、管理者は私一人しかいません。 わたしは普段は仕事もしていますし、夜は寝ています。 それ以外の時間も常にスマホを見ているわけではないし、普通にメールが届いてもなかなか気づけません。 セキュリティ通報専用のアラートを準備すると良いと思っています。 あまり良い例えではないのですが、緊急地震速報のようにどんな時でも気づけるようなもの。
以下はイメージ図ですが、Sentinelの構築とメールとDiscord への通知は実現済です。 また、Microsoft 365とGoogle Workspace、Azureについてもログ集約と監視は実現済です。 今回は Google Cloud の連携を追加していきます。

Sentinelの設定
まずは Sentinel にすでにある連携用のコネクタを導入します。
Defender の管理ポータルから Microsoft Sentinel > コンテンツハブに移動し、”Google Cloud Platform Audit Logs”を探します。

まずは”Google Cloud Platform Audit Logs”を追加します。 検索して、”インストール/更新”からインストールします。

次は”Google Cloud Platform Security Command Center”を追加します。 検索して、”インストール/更新”からインストールします。 (以下はインストール終わった後の画面)

これで2つのソリューションのインストールは終了です。 次はGoogle Cloud側の設定です。
Google Cloud 側の設定(監査ログ)
Google Cloud 側では認証の設定とpub/subの準備を行っていきます。
作業は Cloud Shell から行っていきます。
PROJECT_IDは伏字にしていますが以下を実行。 実行後に”finished successfully.” と表示されればOKです。
export PROJECT_ID="XXXXXXXXXXX"
export ORG_ID=$(gcloud organizations list --format="value(ID)")
gcloud config set project $PROJECT_ID
gcloud services enable \
iam.googleapis.com \
cloudresourcemanager.googleapis.com \
pubsub.googleapis.com \
sts.googleapis.com \
iamcredentials.googleapis.com \
securitycenter.googleapis.comMicrosoft Sentinel の公式の Terraform スクリプトを使って認証基盤を作成します。
<>部分は私の固有環境なので置き換えています。
APIの有効化と初期準備
<USER_NAME>@cloudshell:~$ export PROJECT_ID="<GCP_PROJECT_ID>"
export ORG_ID=$(gcloud organizations list --format="value(ID)")
gcloud config set project $PROJECT_ID
gcloud services enable \
iam.googleapis.com \
cloudresourcemanager.googleapis.com \
pubsub.googleapis.com \
sts.googleapis.com \
iamcredentials.googleapis.com \
securitycenter.googleapis.com
Updated property [core/project].
Operation "operations/acat.p2-<GCP_PROJECT_NUMBER>-<OPERATION_UUID>" finished successfully.
Terraformスクリプトのダウンロードと実行
最初の実行時、Cloud Shell には Terraform がインストールされていないということでインストール手順が応答されました。
<USER_NAME>@cloudshell:~ (<GCP_PROJECT_ID>)$ mkdir -p ~/sentinel-gcp/auth ~/sentinel-gcp/audit
curl -sL "https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/DataConnectors/GCP/Terraform/sentinel_resources_creation/GCPInitialAuthenticationSetup/GCPInitialAuthenticationSetup.tf" \
-o ~/sentinel-gcp/auth/main.tf
cd ~/sentinel-gcp/auth
terraform init
terraform apply -var="project-id=$PROJECT_ID"
Follow the instructions at https://developer.hashicorp.com/terraform/install to install terraform, or run the commands below:
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(grep -oP '(?<=UBUNTU_CODENAME=).*' /etc/os-release || lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
bash
To persist the installation between sessions, either add the above commands to $HOME/.customize_environment, or install the terraform binary in your home directory.指示通りにTerraformをインストールします。
# 1. HashiCorp公式リポジトリを追加してTerraformをインストール
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(grep -oP '(?<=UBUNTU_CODENAME=).*' /etc/os-release || lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install -y terraform
# (略)
Setting up terraform (1.17.2-1) ...Terraform で認証基盤を作成
最初にhash -r を実行しているのはコマンドキャッシュのクリアです。 この前にTerraformが未インストールで実行に失敗し、Terraformをインストールしたのですがこのキャッシュクリアを行わずに進めたらエラーになったため。 キャッシュをクリアしたことでインストールしたTerraformが認識され正常に実行できました。
<USER_NAME>@cloudshell:~/sentinel-gcp/auth (<GCP_PROJECT_ID>)$ hash -r
export PROJECT_ID="<GCP_PROJECT_ID>"
/usr/bin/terraform init
/usr/bin/terraform apply -var="project-id=$PROJECT_ID"
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/google-beta...
- Finding hashicorp/google versions matching "3.73.0"...
- Installing hashicorp/google-beta v8.12.0...
- Installed hashicorp/google-beta v8.12.0 (signed by HashiCorp)
- Installing hashicorp/google v3.73.0...
- Installed hashicorp/google v3.73.0 (signed by HashiCorp)
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
var.tenant-id
Please enter your Sentinel tenant id
Enter a value: <AZURE_TENANT_ID>
var.workload-identity-pool-id-exists
A workload Identity Pool has already been created for Azure? (yes/no)
Enter a value: yes
╷
│ Error: Value for undeclared variable
│
│ A variable named "project-id" was assigned on the command line, but the root module does not declare a variable of that name. To use this value, add a "variable" block to the configuration.
╵var.workload-identity-pool-id-exists
A workload Identity Pool has already been created for Azure? (yes/no)
について、誤って”yes”で進めたところ、Errorとなりました。 これは初回作成だったので”no”が正しい指定となります。
再度”/usr/bin/terraform apply”を実行し、今度は”no”で進めます。
またErrorです。 これはタイミングというか反映のラグが原因なだけなので、再実行します。
省略
google_service_account.sentinel-service-account: Creating...
google_iam_workload_identity_pool.sentinel-workload-identity-pool[0]: Creating...
google_service_account.sentinel-service-account: Creation complete after 3s [id=projects/<GCP_PROJECT_ID>/serviceAccounts/sentinel-service-account@<GCP_PROJECT_ID>.iam.gserviceaccount.com]
google_project_iam_member.bind-sentinel-custom-role-to-sentinel-service-account: Creating...
# (中略)
╷
│ Error: Request `Create IAM Members projects/<GCP_PROJECT_ID>/roles/SentinelCustomRole serviceAccount:sentinel-service-account@<GCP_PROJECT_ID>.iam.gserviceaccount.com for project "<GCP_PROJECT_ID>"` returned error: Error applying IAM policy for project "<GCP_PROJECT_ID>": Error setting IAM policy for project "<GCP_PROJECT_ID>": googleapi: Error 400: Service account sentinel-service-account@<GCP_PROJECT_ID>.iam.gserviceaccount.com does not exist., badRequest
│
│ with google_project_iam_member.bind-sentinel-custom-role-to-sentinel-service-account,
│ on main.tf line 94, in resource "google_project_iam_member" "bind-sentinel-custom-role-to-sentinel-service-account":
│ 94: resource "google_project_iam_member" "bind-sentinel-custom-role-to-sentinel-service-account" {
│
╵再実行して、最終的に一連の処理は正常に終了しました。
<USER_NAME>@cloudshell:~/sentinel-gcp/auth (<GCP_PROJECT_ID>)$ /usr/bin/terraform apply
var.tenant-id
Please enter your Sentinel tenant id
Enter a value: <AZURE_TENANT_ID>
var.workload-identity-pool-id-exists
A workload Identity Pool has already been created for Azure? (yes/no)
Enter a value: no
# (既存リソースの状態確認は省略)
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
google_project_iam_member.bind-sentinel-custom-role-to-sentinel-service-account: Creating...
google_project_iam_member.bind-sentinel-custom-role-to-sentinel-service-account: Creation complete after 9s [id=<GCP_PROJECT_ID>/projects/<GCP_PROJECT_ID>/roles/SentinelCustomRole/serviceAccount:sentinel-service-account@<GCP_PROJECT_ID>.iam.gserviceaccount.com]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
An_output_message = "Please copy the following values to Sentinel"
GCP_project_id = "<GCP_PROJECT_ID>"
GCP_project_number = "<GCP_PROJECT_NUMBER>"
Identity_federation_pool_id = "<AZURE_TENANT_ID_NO_HYPHEN>"
Identity_federation_provider_id = "sentinel-identity-provider"
Service_account_email = "sentinel-service-account@<GCP_PROJECT_ID>.iam.gserviceaccount.com"
workload_identity_pool_id = "<AZURE_TENANT_ID_NO_HYPHEN>"Cloud Shell から実行していきます。
<USER_NAME>@cloudshell:~/sentinel-gcp/auth (<GCP_PROJECT_ID>)$ export PROJECT_ID="<GCP_PROJECT_ID>"
export ORG_ID=$(gcloud organizations list --format="value(ID)")
echo "Organization ID: $ORG_ID"
curl -sL "https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/DataConnectors/GCP/Terraform/sentinel_resources_creation/GCPAuditLogsSetup/GCPAuditLogsSetup.tf" \
-o ~/sentinel-gcp/audit/main.tf
cd ~/sentinel-gcp/audit
/usr/bin/terraform init
/usr/bin/terraform apply
Organization ID: <ORG_ID>
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/google versions matching "3.73.0"...
- Installing hashicorp/google v3.73.0...
- Installed hashicorp/google v3.73.0 (signed by HashiCorp)
Terraform has been successfully initialized!
# (中略)
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# google_logging_project_sink.sentinel-sink[0] will be created
+ resource "google_logging_project_sink" "sentinel-sink" {
+ destination = "pubsub.googleapis.com/projects/<GCP_PROJECT_ID>/topics/sentinel-topic"
+ id = (known after apply)
+ name = "audit-logs-sentinel-sink"
+ project = "<GCP_PROJECT_ID>"
+ unique_writer_identity = true
+ writer_identity = (known after apply)
+ bigquery_options (known after apply)
}
# google_project_iam_binding.log-writer[0] will be created
+ resource "google_project_iam_binding" "log-writer" {
+ etag = (known after apply)
+ id = (known after apply)
+ members = (known after apply)
+ project = "<GCP_PROJECT_ID>"
+ role = "roles/pubsub.publisher"
}
# google_project_service.enable-logging-api will be created
+ resource "google_project_service" "enable-logging-api" {
+ disable_on_destroy = true
+ id = (known after apply)
+ project = "<GCP_PROJECT_ID>"
+ service = "logging.googleapis.com"
}
# google_pubsub_subscription.sentinel-subscription will be created
+ resource "google_pubsub_subscription" "sentinel-subscription" {
+ ack_deadline_seconds = (known after apply)
+ id = (known after apply)
+ message_retention_duration = "604800s"
+ name = "sentinel-subscription-auditlogs"
+ path = (known after apply)
+ project = "<GCP_PROJECT_ID>"
+ topic = "sentinel-topic"
+ expiration_policy (known after apply)
}
# google_pubsub_topic.sentinel-topic[0] will be created
+ resource "google_pubsub_topic" "sentinel-topic" {
+ id = (known after apply)
+ name = "sentinel-topic"
+ project = "<GCP_PROJECT_ID>"
+ message_storage_policy (known after apply)
+ schema_settings (known after apply)
}
Plan: 5 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ An_output_message = "Please copy the following values to Sentinel"
+ GCP_project_id = "<GCP_PROJECT_ID>"
+ GCP_project_number = "<GCP_PROJECT_NUMBER>"
+ GCP_subscription_name = "sentinel-subscription-auditlogs"
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
google_project_service.enable-logging-api: Creating...
google_pubsub_topic.sentinel-topic[0]: Creating...
google_project_service.enable-logging-api: Creation complete after 4s [id=<GCP_PROJECT_ID>/logging.googleapis.com]
google_pubsub_topic.sentinel-topic[0]: Creation complete after 7s [id=projects/<GCP_PROJECT_ID>/topics/sentinel-topic]
google_pubsub_subscription.sentinel-subscription: Creating...
google_logging_project_sink.sentinel-sink[0]: Creating...
google_logging_project_sink.sentinel-sink[0]: Creation complete after 5s [id=<GCP_PROJECT_ID>/sinks/audit-logs-sentinel-sink]
google_project_iam_binding.log-writer[0]: Creating...
google_pubsub_subscription.sentinel-subscription: Still creating... [00m10s elapsed]
google_pubsub_subscription.sentinel-subscription: Creation complete after 11s [id=<GCP_PROJECT_ID>/subscriptions/sentinel-subscription-auditlogs]
google_project_iam_binding.log-writer[0]: Creation complete after 9s [id=<GCP_PROJECT_ID>/roles/pubsub.publisher]
Apply complete! Resources: 5 added, 0 changed, 0 destroyed.
Outputs:
An_output_message = "Please copy the following values to Sentinel"
GCP_project_id = "<GCP_PROJECT_ID>"
GCP_project_number = "<GCP_PROJECT_NUMBER>"
GCP_subscription_name = "sentinel-subscription-auditlogs"
<USER_NAME>@cloudshell:~/sentinel-gcp/audit (<GCP_PROJECT_ID>)$管理アクティビティに絞ります。 ”シンクを編集”から

シンクに含めるログに”logName:”cloudaudit.googleapis.com&2Factivity”を指定します。

Google Cloud側の設定(SCCのログ)
SCCのログについても同様に設定します。 今回はまとめて実行します。
<USER_NAME>@cloudshell:~/sentinel-gcp/audit (<GCP_PROJECT_ID>)$ export PROJECT_ID="<GCP_PROJECT_ID>"
export ORG_ID=$(gcloud organizations list --format="value(ID)")
export SA_EMAIL="sentinel-service-account@<GCP_PROJECT_ID>.iam.gserviceaccount.com"
# 1. SCC専用のPub/Subトピックとプル型サブスクリプションを作成
gcloud pubsub topics create sentinel-scc-topic --project=$PROJECT_ID
gcloud pubsub subscriptions create sentinel-scc-sub \
--topic=sentinel-scc-topic \
--ack-deadline=120 \
--project=$PROJECT_ID
# 2. Sentinel用サービスアカウントに購読・閲覧権限を付与
gcloud pubsub subscriptions add-iam-policy-binding sentinel-scc-sub \
--member="serviceAccount:$SA_EMAIL" \
--role="roles/pubsub.subscriber" \
--project=$PROJECT_ID
gcloud pubsub subscriptions add-iam-policy-binding sentinel-scc-sub \
--member="serviceAccount:$SA_EMAIL" \
--role="roles/pubsub.viewer" \
--project=$PROJECT_ID
# 3. 組織全体のSCC通知設定(継続的エクスポート)を作成
gcloud scc notifications create sentinel-scc-export \
--organization=$ORG_ID \
--pubsub-topic="projects/$PROJECT_ID/topics/sentinel-scc-topic" \
--filter='state="ACTIVE"'
Created topic [projects/<GCP_PROJECT_ID>/topics/sentinel-scc-topic].
Created subscription [projects/<GCP_PROJECT_ID>/subscriptions/sentinel-scc-sub].
Updated IAM policy for subscription [sentinel-scc-sub].
bindings:
- members:
- serviceAccount:sentinel-service-account@<GCP_PROJECT_ID>.iam.gserviceaccount.com
role: roles/pubsub.subscriber
etag: BwZhape4HkE=
version: 1
Updated IAM policy for subscription [sentinel-scc-sub].
bindings:
- members:
- serviceAccount:sentinel-service-account@<GCP_PROJECT_ID>.iam.gserviceaccount.com
role: roles/pubsub.subscriber
- members:
- serviceAccount:sentinel-service-account@<GCP_PROJECT_ID>.iam.gserviceaccount.com
role: roles/pubsub.viewer
etag: BwZhapf_8Hw=
version: 1
ERROR: (gcloud.scc.notifications.create) INVALID_ARGUMENT: This API is no longer available. Please use API V2 as an alternative. If the V2 API does not work for your use case, reach out to the support team.
→API V2に関するエラーが出たので、明示的に--location=global を付与して実行
<USER_NAME>@cloudshell:~/sentinel-gcp/audit (<GCP_PROJECT_ID>)$ export PROJECT_ID="<GCP_PROJECT_ID>"
export ORG_ID=$(gcloud organizations list --format="value(ID)")
gcloud scc notifications create sentinel-scc-export \
--organization=$ORG_ID \
--location=global \
--pubsub-topic="projects/$PROJECT_ID/topics/sentinel-scc-topic" \
--filter='state="ACTIVE"'
Created.
<USER_NAME>@cloudshell:~/sentinel-gcp/audit (<GCP_PROJECT_ID>)$Sentinel 側で2つのコレクターを登録する
Defender 管理ポータルから構成>データコネクタの画面に移動します。

GCP Pub/Sub Audit Logs を選択して、”Open Connector page”をクリックします。

“Add new collector”をクリックします。

Google Cloud側の情報を入力します。 ”connect”をクリックします。 これで追加の操作は完了です。

実行の手順はAudit Logsと同じです。 画面は割愛しますが進めたところエラーが発生。
“Connector resource creation failed
Deployment failed – Cannot connect the connector. Missing dependencies

Azure Portalのトラブルシューティングツールより
Connector resource creation in Microsoft Azure Security Insights can sometimes encounter issues. Here are some steps and resources to help troubleshoot and resolve the problem:
Verify Prerequisites: Ensure that all necessary prerequisites for the connector creation are met. For multicloud connectors, confirm that your environment allows the creation of required resource groups for storing AWS resources. If a policy is blocking resource group creation, consider removing the policy temporarily or manually creating the resource group before proceeding.
Impact Reporting Connectors: If the issue is with an Impact Reporting connector, ensure that the Microsoft.Impact resource provider is registered, and the feature flags AllowImpactReporting and AzureImpactReportingConnector are enabled. You should also have Contributor access to the relevant subscriptions.
Authorization Checks: If you encounter authorization-related failures, verify that the signed-in user has the necessary write permissions at the selected scope. For resource creation, the user must have a role with write permission to that resource. For support ticket creation, the user needs a role with Microsoft.Support/supportTickets/write, such as Support Request Contributor.一度、コネクタの再インストールを試します。

再インストール後も状況はかわらず・・・。
このあと Google Gemini Neon に相談しまくって解決。
かなり試行錯誤したので概要だけ紹介。 同じトラブルに遭遇したら生成AIに聞きまくってください。
問題#1 Defenderポータルからのコネクタ作成が失敗する
Defender ポータルのGUIから Google Security Command Center のコネクタを作成しようとすると何度やってもエラーで実行できない。
(AIによると)GUIのバグとのことで PowerShell からDCEとDCRのリソースを作成。
問題#2 DCRはデータを受信するのに Sentinel テーブルに書き込まれない
REST APIで DCRは構成したあと、Google Cloud の Pub/Sub から正しくデータを吸いあげているのですがSentinelへ書き込まれない状況。
カスタムストリームを定義することで解決
問題#3 JSONキーとテーブルのカラム名・型の不一致
Sentinelに書き込まれない原因を調べていくと型の違い(単数と複数)やJSONのスキーマの不一致が見つかる。
transformKqlで力業的に解決
動作確認
実際に Google Cloud から Sentinel までログが流れているかどうかを確認する。
Defenderポータルから Microsoft Sentinel > 構成 > データコネクタから各コネクタの画面で確認できる。
以下は Google Cloud の Audit Logs。 右の方にグラフでログが転送されていることを確認できる。

高度なハンティングからKQLでも確認可能です。
以下は苦労したGoogle SCC のログ。

まとめ
SCCのコネクタ設定の際に起きた3つのトラブルについて、1つ目はまだしも後の2つの問題はマッチポンプ感がある。 自分で何も調べずにAIにトラブルシューティングを任せる。 AIは自分の知識で解決策を考える。 結果まったく誤った解決策を実行する。 その誤った解決策がもたらした問題を力業で解決する。 結果論だけど、最初の問題でちゃんとトラブルシューティングすれば問題#2と#3はおきなかったと考えている。
いつも感じてはいたけどトラブル起きたとき、生成AIを利用すると自分がバカになる気がする。 昔はまずはドキュメントを読む、エラーログを見る、場合によってはソースコードを読む、そのうえでインターネット上で事例を探す、そしてまたドキュメント読んだり、ログを読んだりを繰り返す。 このアプローチは時間も手間もかかるけど、何が起きているかを紐解き、対処も自分で腹落ちしながら実行できること。 一方、AIを利用するとそこら辺全部すっ飛ばしてエラー画面やログ渡して、AIからの解決策実行して、ダメならその繰り返し。 何がどうなっているかわからなくなる。 最後にAIに整理してもらって聞いても上辺だけの理解になる。
一応自分をフォローというかAIでトラブルシューティングする際のコツを何点か。 一番大事なことはAIのいうことを常に疑うこと(これは仕事でも一緒だけど。ポジティブに他人は疑うというか間違う前提で行動すると捗る)。 特にトラブルシューティングだと、結局は他の人が過去にあげた似たような事例の情報をもとにしていることが多く、必ずしもマニュアルや仕様から組み立てて解決策を導いているわけではない。 結果、出鱈目な解決策を至極妥当な解決策として言ってきて騙されてしまう。 なので、言っていることに対してファクト(事実)を突き付けていく。
あとはAIの思考が捗るように要求されている以上の情報をどんどん与えていく。 今回のトラブルシューティングでいうと、データの発生や流れについて Google SCCからPub/Sub、DCE/DCR、Sentinelまでそれぞれで取得できる客観データをちゃんとAIに与えてあげるとAIはあー、今はここの処理まではちゃんと進んでいるなと認識し、止まっている・問題が起きているところをちゃんと深堀りする。 テーブルのスキーマを与えればそのギャップにも気づく。 言い換えるとざっくりすぎる依頼だと解決までは右往左往するし、ちゃんと情報を与えれば良いアドバイザーになってくれる。 と、当たり前な結論に帰結。
以上
