Google Cloud

GitHub Actions + GCP CI/CD 完全ガイド|Workload Identity・Cloud Run/GKE デプロイ

2026-05-24
NicheeLab編集部

GitHub Actions と GCP の連携は、Workload Identity Federation (WIF) でキーレス認証が標準化されました。 本記事では WIF セットアップから、Cloud Run / GKE / BigQuery デプロイ、Reusable Workflow、Cloud Build 連携まで実装例を網羅します。

Workload Identity Federation セットアップ

# 1. Workload Identity Pool 作成
gcloud iam workload-identity-pools create github \
  --location=global --display-name="GitHub Actions"

# 2. OIDC Provider 設定
gcloud iam workload-identity-pools providers create-oidc github-provider \
  --location=global --workload-identity-pool=github \
  --issuer-uri="https://token.actions.githubusercontent.com" \
  --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository" \
  --attribute-condition="assertion.repository_owner == 'YOUR_ORG'"

# 3. Service Account 作成
gcloud iam service-accounts create github-actions \
  --display-name="GitHub Actions SA"

# 4. SA に必要な Role 付与
gcloud projects add-iam-policy-binding PROJECT \
  --member="serviceAccount:[email protected]" \
  --role="roles/run.admin"

# 5. WIF Pool ↔ SA 紐づけ
gcloud iam service-accounts add-iam-policy-binding \
  [email protected] \
  --role=roles/iam.workloadIdentityUser \
  --member="principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/github/attribute.repository/YOUR_ORG/YOUR_REPO"

基本 Workflow (Cloud Run デプロイ)

# .github/workflows/deploy.yml
name: Deploy to Cloud Run

on:
  push:
    branches: [main]

permissions:
  contents: read
  id-token: write   # WIF に必須

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: google-github-actions/auth@v2
        with:
          workload_identity_provider: projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/github/providers/github-provider
          service_account: [email protected]

      - uses: google-github-actions/setup-gcloud@v2

      - name: Configure Docker
        run: gcloud auth configure-docker asia-northeast1-docker.pkg.dev

      - name: Build & Push
        run: |
          IMAGE=asia-northeast1-docker.pkg.dev/PROJECT/repo/app:${{ github.sha }}
          docker build -t $IMAGE .
          docker push $IMAGE

      - name: Deploy
        run: |
          gcloud run deploy my-app \
            --image=asia-northeast1-docker.pkg.dev/PROJECT/repo/app:${{ github.sha }} \
            --region=asia-northeast1 \
            --allow-unauthenticated

GKE デプロイ Workflow

- uses: google-github-actions/get-gke-credentials@v2
  with:
    cluster_name: my-cluster
    location: asia-northeast1

- name: Helm Deploy
  run: |
    helm upgrade --install my-app ./chart \
      --set image.tag=${{ github.sha }} \
      --namespace=production

Reusable Workflow パターン

# .github/workflows/reusable-deploy.yml
on:
  workflow_call:
    inputs:
      service:    { required: true, type: string }
      region:     { default: 'asia-northeast1', type: string }
      image_tag:  { required: true, type: string }

permissions: { id-token: write, contents: read }

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: google-github-actions/auth@v2
        with:
          workload_identity_provider: ...
          service_account: ...
      - run: gcloud run deploy ${{ inputs.service }} --image=... --region=${{ inputs.region }}

# 利用側
jobs:
  deploy-api:
    uses: ./.github/workflows/reusable-deploy.yml
    with:
      service:   api
      image_tag: ${{ github.sha }}

Secret Manager 統合

- id: secrets
  uses: google-github-actions/get-secretmanager-secrets@v2
  with:
    secrets: |
      DB_PASSWORD:PROJECT/db-password
      API_KEY:PROJECT/api-key

- run: ./deploy.sh
  env:
    DB_PASSWORD: ${{ steps.secrets.outputs.DB_PASSWORD }}
    API_KEY:     ${{ steps.secrets.outputs.API_KEY }}

Cloud Build トリガー連携

- name: Trigger Cloud Build
  run: |
    gcloud builds submit --config=cloudbuild.yaml \
      --substitutions=_BRANCH=${{ github.ref_name }},_SHA=${{ github.sha }}

Self-hosted Runner (VPC 内)

  • GCE VM に GitHub Runner インストール (Private IP)
  • VPC 内リソース (CloudSQL Private IP / IAP / オンプレ DB) アクセス可
  • Larger Runners + Private Networking (2024 GA) で GitHub マネージドのまま VPC 接続も可
  • セキュリティ: 1 ジョブごとに VM 破棄 (Ephemeral)

典型的なフロー

  1. PR push → Actions で lint / test / build
  2. main merge → Cloud Build 起動 (Container 署名)
  3. Artifact Registry に push (Binary Authorization 適用)
  4. Cloud Deploy に Release 作成
  5. Dev → Staging → Prod の Canary プロモート
  6. Cloud Monitoring で SLO 違反時に自動ロールバック

ベストプラクティス

  • SA キーはリポジトリに置かない (WIF 一択)
  • Environment ごとに承認ゲート (production 環境)
  • Reusable Workflow で標準化
  • Concurrency 設定で同時実行制御
  • OIDC token 利用範囲を最小化 (Attribute Condition)
  • SLSA Level 3 でビルド来歴記録

GitHub Actions と Cloud Build どちらを使う?

GitHub 完結 + マルチクラウド → Actions、GCP リソース完結 + 詳細制御 → Cloud Build。Actions が無料枠 2000 min/月で大きい、両方併用も一般的。

Workload Identity Federation 必須?

Service Account キーをリポジトリに置くのは厳禁。WIF で安全に GitHub Actions ↔ GCP 認証。設定は 1 度で永続。

対応 GCP リソースは?

google-github-actions/setup-gcloud で gcloud + kubectl + helm + terraform 等の主要ツール利用可。Cloud Run / GKE / GAE / Cloud Functions / BigQuery 全対応。

Self-hosted Runner で VPC 内アクセス?

GitHub Self-hosted Runner を GCE VM (VPC 内) に配置すれば Private DB / IAP 経由でアクセス可。Larger Runners + Private Networking 機能 (2024〜) も。

Reusable Workflow とは?

<code>workflow_call</code> で他リポジトリから再利用。組織内で標準 Pipeline を共有可能。

OIDC token expiry は?

通常 1 時間。Long-running ジョブは <code>refresh_token: true</code> で延長、または定期的に再認証。

Secrets はどう管理する?

GitHub Secrets (Actions Secrets)、Environment Secrets (環境別)、Organization Secrets (組織共有)。Google Secret Manager と組み合わせて Pipeline で取得が標準。

ArgoCD / Cloud Deploy と組み合わせる?

Actions = ビルド + テスト、ArgoCD / Cloud Deploy = デプロイ管理という分離が一般的。GitOps なら ArgoCD、Canary 管理なら Cloud Deploy。

関連記事・CI/CD

Terraform on GCP 完全ガイド|IaC・Provider・Workload Identity・GitHub Actions (2026)

Google Cloud で Terraform を使う IaC 完全ガイド。Google Cloud Provider / Beta、State 管理 (gcs バックエンド)、Workload Identity Federation、Module 設計、GitHub Actions CI、Infracost、Config Connector を 2026 年最新版で網羅。

GCP Professional Cloud Developer (PCD) 完全ガイド|Cloud Run・GKE・CI/CD・APM

Google Cloud Professional Cloud Developer の試験範囲、Cloud Run / GKE / Cloud Build / Cloud Trace、AWS DVA / Azure AZ-204 比較、学習ロードマップを徹底解説。

Cloud Build 完全ガイド|CI/CD・cloudbuild.yaml・Private Pool・GitHub 連携 (GCP)

Google Cloud Cloud Build の全機能解説。cloudbuild.yaml、トリガー設定、Private Pool、Workload Identity、Build Approvals、Cloud Deploy 連携、AWS CodeBuild / Azure DevOps 比較を網羅。

GCP Professional Cloud DevOps Engineer (PCDOE) 完全ガイド|SRE・GKE・CI/CD・SLO

Google Cloud Professional Cloud DevOps Engineer の試験範囲、SRE / SLI / SLO / Error Budget、GKE / Cloud Build / Cloud Deploy、AWS DOP・Azure AZ-400 比較を徹底解説。

※ Google Cloud は Google LLC、GitHub は GitHub, Inc. の登録商標です。最新は google-github-actions 公式 をご確認ください。

この記事で学んだ内容を問題で確認しましょう

16,000問以上の問題で実力チェック

GCP 試験対策ページを見る
この記事の著者

NicheeLab編集部

データエンジニアリング・クラウド資格の専門家。Databricks・Snowflake等の認定資格を保有し、実務経験に基づいた問題作成・解説を行っています。NicheeLab運営。


関連記事
Google Cloud

Google Cloud (GCP) 認定資格ロードマップ 2026 完全版|全 15 試験を体系化

Google Cloud 認定資格 全 15 試験 (Foundational 2 + Associate 3 + Pr...

Google Cloud

Cloud Digital Leader (CDL) 完全ガイド|出題範囲・学習リソース・合格戦略

Google Cloud Cloud Digital Leader (CDL) の完全ガイド。6 ドメイン 92 bul...

Google Cloud

Generative AI Leader (GAIL) 完全ガイド|Google Cloud 生成 AI 認定

Google Cloud Generative AI Leader (GAIL、2025-05-14 リリース) の完全...

Google Cloud

Vertex AI 入門|Google Cloud 統合 ML プラットフォームの全機能

Google Cloud Vertex AI の入門解説。Vertex AI Studio / Agent Builde...

Google Cloud

GCP Associate Cloud Engineer (ACE) 完全ガイド|試験範囲・受験料・学習ロードマップ

Google Cloud Associate Cloud Engineer (ACE) の試験範囲・受験料 125 US...

Google Cloudの記事一覧 (102件)
© 2026 NicheeLab All rights reserved.