Skip to content

Add Workload Identity Federation article to hugoplate blog - #6

Draft
yayachang with Copilot wants to merge 2 commits into
mainfrom
copilot/write-wif-article
Draft

Add Workload Identity Federation article to hugoplate blog#6
yayachang with Copilot wants to merge 2 commits into
mainfrom
copilot/write-wif-article

Conversation

Copilot AI commented Feb 13, 2026

Copy link
Copy Markdown

Adds comprehensive Chinese-language guide on migrating from GCP Service Account JSON keys to Workload Identity Federation for cross-cloud authentication.

Changes

  • New article: hugoplate/content/english/blog/workload-identity-federation.md
    • Covers WIF setup between AWS and GCP
    • Includes architecture diagrams and step-by-step gcloud CLI commands
    • Documents credential config usage with Google Auth libraries
    • Addresses local development workflows and common migration questions

Article Structure

  • Problem space: static key management pain points
  • Core concepts with cross-cloud identity exchange analogy
  • Implementation: Pool/Provider/Service Account configuration
  • Security comparison table
  • FAQ covering ECS/Lambda, credential leakage, token caching

Metadata configured for "Cloud" category with GCP, AWS, security tags.

Original prompt

This section details on the original issue you should resolve

<issue_title>write WIF article</issue_title>
<issue_description>將以下內容寫在hugoplate分支,新增一篇文章:

告別 Service Account 金鑰:Workload Identity Federation 完整入門指南

你是否曾經把 GCP Service Account 的 JSON 金鑰存在專案裡,然後心虛地加進 .gitignore?這篇文章會告訴你一個更安全、更優雅的做法。

問題:Service Account 金鑰的痛點

在串接 Google Cloud API(例如 Google Play Developer API、Google Sheets API)時,最常見的做法是:

  1. 在 GCP Console 建立 Service Account
  2. 下載 JSON 金鑰檔案
  3. 把金鑰存在環境變數、Secrets Manager 或設定檔裡
  4. 程式讀取金鑰後呼叫 API

這個流程能動,但有幾個根本性的問題:

  • 金鑰是永久有效的:一旦洩漏,攻擊者可以無限期使用
  • 需要手動輪替:你得定期重新產生金鑰並更新部署
  • 金鑰會四處流竄:開發環境、CI/CD、Secrets Manager⋯⋯每多一個地方就多一個風險
  • 組織政策可能直接禁止:許多企業啟用了 iam.disableServiceAccountKeyCreation,根本不讓你建金鑰

那有沒有辦法不用金鑰,就能讓你的 AWS 上的服務去呼叫 GCP API?

答案就是 Workload Identity Federation(WIF)


核心概念:用「身份交換」取代「密碼」

一個生活化的比喻

想像你是台灣人,要去日本的銀行辦事。銀行不認識你,但他們信任台灣的外交部。

流程是這樣的:

  1. 你拿出台灣護照(你在 AWS 的身份)
  2. 日本銀行打電話給台灣外交部確認(Google 向 AWS 驗證你的身份)
  3. 確認OK,銀行發給你一張臨時通行證(Google 發給你一個短期 Token)
  4. 你用臨時通行證辦事(用 Token 呼叫 GCP API)

整個過程沒有交換密碼,只有身份的驗證和信任的傳遞。

技術對照

比喻 技術概念
台灣護照 AWS IAM Role 的臨時憑證(STS Token)
台灣外交部 AWS Security Token Service (STS)
日本銀行 Google Cloud IAM
銀行信任外交部 Workload Identity Pool 的 AWS Provider
臨時通行證 Google 的 OAuth 2.0 Access Token

架構圖

你的 AWS 服務(EC2 / ECS / Lambda)
        │
        │ ① 我是 AWS 帳號 123456 的 Role "my-server-role"
        ▼
┌─────────────────────────────────┐
│  Google Security Token Service  │
│  (sts.googleapis.com)           │
│                                 │
│  ② 讓我驗證一下...               │
│     → 呼叫 AWS STS 確認身份      │
│     → 檢查 Workload Identity    │
│       Pool 的信任設定            │
│  ③ OK,你的 AWS 身份是合法的      │
└────────────┬────────────────────┘
             │
             │ ④ 用驗證過的身份模擬 Service Account
             ▼
┌─────────────────────────────────┐
│  GCP Service Account            │
│  sa@project.iam.gserviceaccount │
│                                 │
│  ⑤ 產生短期 Access Token         │
│     (有效期 1 小時)             │
└────────────┬────────────────────┘
             │
             │ ⑥ 用 Access Token 呼叫 API
             ▼
┌─────────────────────────────────┐
│  Google Play Developer API      │
│  (或任何 GCP API)              │
└─────────────────────────────────┘

三個你一定要懂的元件

1. Workload Identity Pool(身份池)

把它想成一個「外國人登記處」。

它是 GCP 專案裡的一個容器,用來管理外部身份(AWS、Azure、GitHub Actions 等)的信任關係。

一個 GCP 專案可以有多個 Pool
    └── Pool: "production-pool"
    └── Pool: "staging-pool"

2. Provider(身份提供者)

把它想成登記處裡的「國家窗口」。

每個 Pool 裡面可以有多個 Provider,每個 Provider 對應一個外部身份來源。

Pool: "production-pool"
    └── Provider: "aws-provider"     ← 信任 AWS 帳號 123456789
    └── Provider: "github-provider"  ← 信任 GitHub repo xxx/yyy

Provider 的設定決定了:

  • 信任誰:哪個 AWS 帳號?哪個 GitHub repo?
  • 映射什麼身份:把 AWS 的 Role ARN 對應到什麼 GCP 屬性?

3. Service Account + IAM 綁定

把它想成「這個外國人可以用哪個本地人的名義辦事」。

外部身份本身在 GCP 裡沒有任何權限。你需要授權它「扮演」(impersonate) 某個 Service Account,而這個 Service Account 才有實際的 API 權限。

AWS Role "my-server-role"
    → 被允許扮演 → GCP Service Account "play-api@project.iam.gserviceaccount.com"
        → 擁有 → Google Play Developer API 的權限

實作步驟

Step 0:前置準備

確認你有:

  • 一個 GCP 專案(記下 Project ID 和 Project Number)
  • 一個 AWS 帳號(記下 Account ID)
  • 你的服務跑在 AWS 上,且有 IAM Role
  • 本機安裝了 gcloud CLI

Step 1:建立 Workload Identity Pool

gcloud iam workload-identity-pools create my-aws-pool \
  --project="YOUR_PROJECT_ID" \
  --location="global" \
  --display-name="AWS Workload Pool"

Step 2:建立 AWS Provider

gcloud iam workload-identity-pools providers create-aws my-aws-provider \
  --project="YOUR_PROJECT_ID" \
  --location="global" \
  --workload-identity-pool="my-aws-pool" \
  --account-id="YOUR_AWS_ACCOUNT_ID" \
  --display-name="AWS Provider"

其中 --account-id 是你的 12 位數 AWS 帳號 ID。

Step 3:建立 Service Account(如果還沒有)

gcloud iam service-accounts create play-api-sa \
  --project="YOUR_PROJECT_ID" \
  --display-name="Google Play API Service Account"

不需要給這個 Service Account 任何 GCP 專案層級的角色。它的 Google Play 權限是在 Google Play Console 裡授予的。

Step 4:授權 Pool 扮演 Service Account

gcloud iam service-accounts add-iam-policy-binding \
  "play-api-sa@YOUR_PROJECT_ID.iam.gserviceaccount.com" \
  --project="YOUR_PROJECT_ID" \
  --role="roles/iam.workloadIdentityUser" \
  --member="principalSet://iam.googleapis.com/projects/YOUR_PROJECT_NUMBER/locations/global/workloadIdentityPools/my-aws-pool/attribute.aws_role/arn:aws:sts::YOUR_AWS_ACCOUNT_ID:assumed-role/YOUR_AWS_ROLE_NAME"

注意--member 裡的 YOUR_AWS_ROLE_NAME 是你的 EC2/ECS 服務使用的 IAM Role 名稱。這樣只有特定 Role 能扮演這個 Service Account。

Step 5:產生 credential-config.json

gcloud iam workload-identity-pools create-cred-config \
  "projects/YOUR_PROJECT_NUMBER/locations/global/workloadIdentityPools/my-aws-pool/providers/my-aws-provider" \
  --service-account="play-api-sa@...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes yayachang/yayachang.github.io#5

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/yayachang/yayachang.github.io/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: yayachang <3753981+yayachang@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Workload Identity Federation article Add Workload Identity Federation article to hugoplate blog Feb 13, 2026
Copilot AI requested a review from yayachang February 13, 2026 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants