Google Cloud
Shisho Cloud と Google Cloud を連携することで、Google Cloud プロジェクトや組織のセキュリティスキャンが実施できます。 この連携は以下の 3 ステップで行えます:
- Shisho Cloud が利用(impersonate)できるサービスアカウントと、それに関連するリソースを作成する。
- 作成したサービスアカウントに、セキュリティ検査を行いたい Google Cloud プロジェクトへの権限を付与する。
- 作成したサービスアカウントや関連リソースの情報を Shisho Cloud に登録する。
サービスアカウントと関連リソースの作成
まずは任意の Google Cloud プロジェクトに、以下のどれかの手順に従って、Shisho Cloud から利用するサービスアカウント・アイデンティティプール・アイデンティティプロバイダを作成 してください。
複数の Google Cloud プロジェクトを検査したい場合でも、この手順は 1 回だけで問題ありません。 つまり、Shisho Cloud のためのサービスアカウント・アイデンティティプール・アイデンティティプロバイダは、それぞれ 1 つずつあれば十分です。
- gcloud CLI
- Terraform
- Web コンソール(Cloud Shell)
冒頭の # 入力値 セクションの値を適宜変更した後、以下のスクリプトを実行することで、必要なリソース(ID プロバイダ・IAM ロール)が作成されます:
#!/bin/bash
set -eu
# 入力値
############
# Google Cloud プロジェクトの ID
PROJECT_ID="your-google-cloud-project-id"
# Shisho Cloud 組織の ID
SHISHO_ORG_ID="you-shisho-organization-id"
# 作成するアイデンティティプールの ID; 特に理由がなければ変更の必要はありません
POOL_ID="shisho-cloud"
# 作成するアイデンティティプロバイダの ID; 特に理由がなければ変更の必要はありません
PROVIDER_ID="shisho-cloud"
# 作成するサービスアカウント名; 特に理由がなければ変更の必要はありません
SERVICE_ACCOUNT_NAME="shisho-cloud"
# Creation
############
TOKEN_ENDPOINT_URL="https://tokens.cloud.shisho.dev"
PROJECT_NUMBER="$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")"
# Ensure to enable APIs that needs to be enabled on the project that includes the service account to integrate with Shisho Cloud.
gcloud services enable \
bigquery.googleapis.com \
cloudasset.googleapis.com \
cloudkms.googleapis.com \
cloudresourcemanager.googleapis.com \
compute.googleapis.com \
container.googleapis.com \
dns.googleapis.com \
essentialcontacts.googleapis.com \
logging.googleapis.com \
iamcredentials.googleapis.com \
iam.googleapis.com \
pubsub.googleapis.com \
serviceusage.googleapis.com \
storage-component.googleapis.com \
sqladmin.googleapis.com \
--project "$PROJECT_ID"
# Create a new workload identity pool
gcloud iam workload-identity-pools create "$POOL_ID" \
--project="$PROJECT_ID" \
--description="An identity pool for Shisho Cloud audit jobs. Visit https://shisho.dev/docs/ja/g/getting-started/integrate-apps/googlecloud for further details." \
--location=global \
--display-name="$POOL_ID"
# Add a workload identity pool provider
gcloud iam workload-identity-pools providers create-oidc "$PROVIDER_ID" \
--project="$PROJECT_ID" \
--location="global" \
--workload-identity-pool="$POOL_ID" \
--description="An identity provider for Shisho Cloud audit jobs. Visit https://shisho.dev/docs/ja/g/getting-started/integrate-apps/googlecloud for further details." \
--display-name="$PROVIDER_ID" \
--attribute-mapping="google.subject=assertion.sub,attribute.organization_id=assertion.organization_id,attribute.workflow_id=assertion.workflow_id,attribute.job_id=assertion.job_id" \
--attribute-condition="assertion.organization_id == '$SHISHO_ORG_ID'" \
--issuer-uri="$TOKEN_ENDPOINT_URL"
# Create a service account that can be impersonated IDs in the pool
gcloud iam service-accounts create "$SERVICE_ACCOUNT_NAME" \
--description="A service account that Shisho Cloud impersonates and use for listing up projects, resources, and their settings. Visit https://shisho.dev/docs/ja/g/getting-started/integrate-apps/googlecloud for further details." \
--project "$PROJECT_ID"
# Allow a service account to be impersonated. Note that the service account doesn't have ability to access config of Google resources yet.
gcloud iam service-accounts add-iam-policy-binding "$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \
--project="$PROJECT_ID" \
--role="roles/iam.workloadIdentityUser" \
--member="principalSet://iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$POOL_ID/*"
# Post-processing
echo "Visit https://cloud.shisho.dev/${SHISHO_ORG_ID}/settings/integrations/googlecloud and add a federation with:"
echo "- (1) Service Account Email: ${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"
echo "- (2) Pool Project Number: ${PROJECT_NUMBER}"
echo "- (3) Pool ID: ${POOL_ID}"
echo "- (4) Provider ID: ${PROVIDER_ID}"
実行が完了すると、作成された以下のリソースに関する情報が Visit https://cloud.shisho.dev ... 以降に出力されます。
ここで表示される内容は後のステップ「Shisho Cloud への情報の登録」で利用するため、控えておいてください。
shisho-cloudという名前のサービスアカウントshisho-cloudという名前のアイデンティティプロバイダshisho-cloudという名前のアイデンティティプール
変数 shisho_cloud_org_id の値をご自身の Shisho Cloud 組織の ID に変更した後、以下の Terraform 実装をご自身の Terraform プロジェクトに含め、 terraform apply を実行してください。
サンプルコードは、以下のように定義された project 変数に、サービスアカウント等を作成する Google Cloud プロジェクト ID を指定されていることを仮定しています:
variable "project" {
type = string
}
このような変数が別名で定義されている場合、サンプルコード中の var.project の参照を適宜置換してください。
そのよな変数が定義されていない場合、GOOGLE_PROJECT 環境変数を設定した上で、サンプルコードから var.project を削除して利用するか、var.project を直接プロジェクト ID に置換してください。
locals {
# 以下を Shisho Cloud 組織の ID に変更してください:
shisho_cloud_org_id = "your-shisho-organization-id"
}
# Ensure to enable APIs that needs to be enabled on the project that includes the service account to integrate with Shisho Cloud.
resource "google_project_service" "bigquery" {
project = var.project
service = "bigquery.googleapis.com"
}
resource "google_project_service" "cloudasset" {
project = var.project
service = "cloudasset.googleapis.com"
}
resource "google_project_service" "cloudkms" {
project = var.project
service = "cloudkms.googleapis.com"
}
resource "google_project_service" "resourcemanager" {
project = var.project
service = "cloudresourcemanager.googleapis.com"
}
resource "google_project_service" "compute" {
project = var.project
service = "compute.googleapis.com"
}
resource "google_project_service" "container" {
project = var.project
service = "container.googleapis.com"
}
resource "google_project_service" "dns" {
project = var.project
service = "dns.googleapis.com"
}
resource "google_project_service" "essentialcontacts" {
project = var.project
service = "essentialcontacts.googleapis.com"
}
resource "google_project_service" "logging" {
project = var.project
service = "logging.googleapis.com"
}
resource "google_project_service" "iamcredentials" {
project = var.project
service = "iamcredentials.googleapis.com"
}
resource "google_project_service" "iam" {
project = var.project
service = "iam.googleapis.com"
}
resource "google_project_service" "pubsub" {
project = var.project
service = "pubsub.googleapis.com"
}
resource "google_project_service" "serviceusage" {
project = var.project
service = "serviceusage.googleapis.com"
}
resource "google_project_service" "storage-component" {
project = var.project
service = "storage-component.googleapis.com"
}
resource "google_project_service" "sqladmin" {
project = var.project
service = "sqladmin.googleapis.com"
}
# Create a service account
resource "google_service_account" "shisho_cloud" {
project = var.project
account_id = "shisho-cloud"
description = "A service account that Shisho Cloud impersonates and use for listing up projects, resources, and their settings. Visit https://shisho.dev/docs/ja/g/getting-started/integrate-apps/googlecloud for further details."
}
# Create an identity pool
resource "google_iam_workload_identity_pool" "shisho_cloud" {
project = var.project
workload_identity_pool_id = "shisho-cloud"
description = "An identity pool for Shisho Cloud audit jobs. Visit https://shisho.dev/docs/ja/g/getting-started/integrate-apps/googlecloud for further details."
}
# Create an identity provider
resource "google_iam_workload_identity_pool_provider" "shisho_cloud" {
project = var.project
workload_identity_pool_provider_id = "shisho-cloud"
workload_identity_pool_id = google_iam_workload_identity_pool.shisho_cloud.workload_identity_pool_id
description = "An identity provider for Shisho Cloud audit jobs. Visit https://shisho.dev/docs/ja/g/getting-started/integrate-apps/googlecloud for further details."
oidc {
issuer_uri = "https://tokens.cloud.shisho.dev"
}
attribute_mapping = {
"google.subject" = "assertion.sub"
"attribute.organization_id" = "assertion.organization_id"
"attribute.workflow_id" = "assertion.workflow_id"
"attribute.job_id" = "assertion.job_id"
}
# Limit the scope of the service account to only be able to access the
attribute_condition = "attribute.organization_id == '${local.shisho_cloud_org_id}'"
}
# Grant the identity from the identity provider to impersonate the service account
resource "google_service_account_iam_member" "shisho_cloud_iam_workload_identity_user" {
service_account_id = google_service_account.shisho_cloud.id
role = "roles/iam.workloadIdentityUser"
member = "principalSet://iam.googleapis.com/${google_iam_workload_identity_pool.shisho_cloud.name}/*"
}
実行が完了すると、以下が作成されているはずです:
shisho-cloudという名前のサービスアカウントshisho-cloudという名前のアイデンティティプロバイダshisho-cloudという名前のアイデンティティプール
画面右上のターミナルボタンから Cloud Shell を起動してください。以下の画像のうち、右上でハイライトされているボタンです:

クリックしてしばらく経つと、以下のように Cloud Shell が起動し、gcloud コマンドが利用できるようになります:

冒頭の # 作成した Shisho Cloud 組織の ID セクションの値を適宜変更した後、当該 Cloud Shell 上に以下のスクリプトをコピー・アンド・ペーストして実行することで、必要なリソース(ID プロバイダ・IAM ロール)が作成されます:
# 作成した Shisho Cloud 組織の ID
SHISHO_ORG_ID="you-shisho-organization-id"
# 作成するアイデンティティプールの ID; 特に理由がなければ変更の必要はありません
POOL_ID="shisho-cloud"
# 作成するアイデンティティプロバイダの ID; 特に理由がなければ変更の必要はありません
PROVIDER_ID="shisho-cloud"
# 作成するサービスアカウント名; 特に理由がなければ変更の必要はありません
SERVICE_ACCOUNT_NAME="shisho-cloud"
TOKEN_ENDPOINT_URL="https://tokens.cloud.shisho.dev"
PROJECT_ID="$(gcloud config get-value project)"
PROJECT_NUMBER="$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")"
# Ensure to enable APIs that needs to be enabled on the project that includes the service account to integrate with Shisho Cloud.
gcloud services enable \
bigquery.googleapis.com \
cloudasset.googleapis.com \
cloudkms.googleapis.com \
cloudresourcemanager.googleapis.com \
compute.googleapis.com \
container.googleapis.com \
dns.googleapis.com \
essentialcontacts.googleapis.com \
logging.googleapis.com \
iamcredentials.googleapis.com \
iam.googleapis.com \
pubsub.googleapis.com \
serviceusage.googleapis.com \
storage-component.googleapis.com \
sqladmin.googleapis.com \
--project "$PROJECT_ID"
# Create a Workload Identity Pool & Provider
gcloud iam workload-identity-pools create "$POOL_ID" \
--project="$PROJECT_ID" \
--description="An identity pool for Shisho Cloud audit jobs. Visit https://shisho.dev/docs/ja/g/getting-started/integrate-apps/googlecloud for further details." \
--location=global \
--display-name="$POOL_ID"
gcloud iam workload-identity-pools providers create-oidc "$PROVIDER_ID" \
--project="$PROJECT_ID" \
--location="global" \
--workload-identity-pool="$POOL_ID" \
--description="An identity provider for Shisho Cloud audit jobs. Visit https://shisho.dev/docs/ja/g/getting-started/integrate-apps/googlecloud for further details." \
--display-name="$PROVIDER_ID" \
--attribute-mapping="google.subject=assertion.sub,attribute.organization_id=assertion.organization_id,attribute.workflow_id=assertion.workflow_id,attribute.job_id=assertion.job_id" \
--attribute-condition="assertion.organization_id == '$SHISHO_ORG_ID'" \
--issuer-uri="$TOKEN_ENDPOINT_URL"
# Create a service account that can be impersonated IDs in the pool
gcloud iam service-accounts create "$SERVICE_ACCOUNT_NAME" \
--description="A service account that Shisho Cloud impersonates and use for listing up projects, resources, and their settings. Visit https://shisho.dev/docs/ja/g/getting-started/integrate-apps/googlecloud for further details." \
--project "$PROJECT_ID"
gcloud iam service-accounts add-iam-policy-binding "$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \
--project="$PROJECT_ID" \
--role="roles/iam.workloadIdentityUser" \
--member="principalSet://iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/$POOL_ID/*"
# Post-processing
echo "Visit https://cloud.shisho.dev/${SHISHO_ORG_ID}/settings/integrations/googlecloud and add a federation with:"
echo "- (1) Service Account Email: ${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"
echo "- (2) Pool Project Number: ${PROJECT_NUMBER}"
echo "- (3) Pool ID: ${POOL_ID}"
echo "- (4) Provider ID: ${PROVIDER_ID}"
実行が完了すると、作成された以下のリソースに冠する情報が Visit https://cloud.shisho.dev ... 以降に出力されます。
ここで表示される内容は後のステップ「Shisho Cloud への情報の登録」で利用するため、控えておいてください。
shisho-cloudという名前のサービスアカウントshisho-cloudという名前のアイデンティティプロバイダshisho-cloudという名前のアイデンティティプール
サービスアカウントが作成できたら、作成されたサービスアカウントの E メールアドレスを控えてください。
当該 E メールアドレスは、上記のスクリプト類をそのまま利用した場合、およそ shisho-cloud@<プロジェクト名>.iam.gserviceaccount.com のようになるはずです。
また、サービスアカウントの E メールアドレスと併せて、サービスアカウントや関連リソースを作成した Google Cloud プロジェクトのプロジェクト番号も控えてください。 これは通常 12 桁の数で、Google Cloud コンソールの ウェルカムページ で確認できます。