🍣

sp-initiated

2025/03/02に公開

IAPでSAML認証を使用する場合、SP-initiated(サービスプロバイダー主導)のSSOフローの設定は、Google Cloud Consoleで行います。Terraformを使って自動化することも可能です。

SP-initiated設定の主なポイントは以下の通りです:

  1. SAML設定のセットアップ場所:

    • Google Cloud Consoleの「Security」→「Identity-Aware Proxy」→「Identity providers」セクション
    • または、Terraformを使用して設定を自動化
  2. SP-initiated認証フローの主要コンポーネント:

    • アサーションコンシューマーサービス(ACS)URL
    • エンティティID
    • SSO開始URL(オプション)

Terraformでの実装例:

# IAP用のブランドを作成
resource "google_iap_brand" "project_brand" {
  support_email     = "admin@example.com"
  application_title = "My Application"
  project           = var.project_id
}

# SAML IdPをIAPに登録
resource "google_iap_client" "project_client" {
  display_name = "My SAML Client"
  brand        = google_iap_brand.project_brand.name
}

# IAP SAML IdPの設定
resource "google_iap_identity_provider" "saml_provider" {
  brand     = google_iap_brand.project_brand.name
  idp_id    = "my-saml-provider"
  name      = "My SAML Provider"
  
  # SAML設定
  saml {
    idp_metadata  = file("idp-metadata.xml")  # IdPのメタデータXMLファイル
    # または、メタデータURLを使用
    # idp_metadata_url = "https://idp.example.com/metadata"
  }
}

# ロードバランサーとIAPの統合
resource "google_compute_backend_service" "default" {
  name        = "backend-service"
  port_name   = "http"
  protocol    = "HTTP"
  timeout_sec = 10

  backend {
    group = google_compute_instance_group_manager.default.instance_group
  }

  # IAPの有効化
  iap {
    oauth2_client_id     = google_iap_client.project_client.client_id
    oauth2_client_secret = google_iap_client.project_client.secret
  }
}

SP-initiated認証フローのプロセス:

  1. ユーザーがロードバランサーのURLにアクセス(例: https://app.example.com
  2. IAPが認証されていないリクエストを検出
  3. IAPがSAML認証リクエストを生成し、IdPにリダイレクト
  4. ユーザーがIdPで認証
  5. IdPがSAMLレスポンスを生成し、ACS URLに送信
  6. IAPが認証を検証し、元のアプリケーションへのアクセスを許可

設定後の情報確認と共有:

IdPの管理者に提供する必要がある情報は以下の通りです:

  1. SP Entity ID: https://iap.googleapis.com/v1/projects/PROJECT_NUMBER/brands/BRAND_ID/identityProviders/IDP_ID
  2. ACS URL: https://iap.googleapis.com/v1/projects/PROJECT_NUMBER/brands/BRAND_ID/identityProviders/IDP_ID/redirectUri
  3. 開始URL: https://YOUR_APPLICATION_URL

これらの値は、Terraformの適用後に以下のコマンドで取得できます:

# Entity IDとACS URLを表示
terraform output saml_entity_id
terraform output saml_acs_url

IAPでSAML認証を使用する場合、SP-initiatedフローの設定はIAP側(Google Cloud)で行い、IdP側(Okta、Azure AD、GSuiteなど)にはこれらの情報を登録します。

Discussion