Skip to content

Commit 2bb6a36

Browse files
committed
ci: switch cloud run env sync to oidc
1 parent 7ceed15 commit 2bb6a36

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

.github/workflows/sync-cloud-run-env.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ on:
44
push:
55
branches: [ main ]
66

7+
env:
8+
GCP_PROJECT_ID: longbridgequant
9+
GCP_WORKLOAD_IDENTITY_PROVIDER: projects/252919773759/locations/global/workloadIdentityPools/github-actions/providers/github-main
10+
GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT: longbridge-platform-build@longbridgequant.iam.gserviceaccount.com
11+
712
jobs:
813
sync-hk:
914
name: Sync HK Cloud Run Env
1015
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
id-token: write
1119
environment: longbridge-hk
1220
env:
1321
ENABLE_GITHUB_ENV_SYNC: ${{ vars.ENABLE_GITHUB_ENV_SYNC }}
@@ -24,7 +32,6 @@ jobs:
2432
LONGPORT_SECRET_NAME: ${{ vars.LONGPORT_SECRET_NAME }}
2533
NOTIFY_LANG: ${{ vars.NOTIFY_LANG }}
2634
GLOBAL_TELEGRAM_CHAT_ID: ${{ vars.GLOBAL_TELEGRAM_CHAT_ID }}
27-
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
2835
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
2936
LONGPORT_APP_KEY: ${{ secrets.LONGPORT_APP_KEY }}
3037
LONGPORT_APP_SECRET: ${{ secrets.LONGPORT_APP_SECRET }}
@@ -48,7 +55,6 @@ jobs:
4855
LONGPORT_SECRET_NAME
4956
NOTIFY_LANG
5057
GLOBAL_TELEGRAM_CHAT_ID
51-
GCP_SA_KEY
5258
)
5359
5460
missing_vars=()
@@ -85,13 +91,14 @@ jobs:
8591
if: steps.config.outputs.enabled == 'true'
8692
uses: google-github-actions/auth@v3
8793
with:
88-
credentials_json: ${{ env.GCP_SA_KEY }}
94+
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
95+
service_account: ${{ env.GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT }}
8996

9097
- name: Set up gcloud
9198
if: steps.config.outputs.enabled == 'true'
9299
uses: google-github-actions/setup-gcloud@v3
93100
with:
94-
project_id: ${{ steps.auth.outputs.project_id }}
101+
project_id: ${{ env.GCP_PROJECT_ID }}
95102
version: ">= 416.0.0"
96103

97104
- name: Sync Cloud Run environment
@@ -158,6 +165,9 @@ jobs:
158165
sync-sg:
159166
name: Sync SG Cloud Run Env
160167
runs-on: ubuntu-latest
168+
permissions:
169+
contents: read
170+
id-token: write
161171
environment: longbridge-sg
162172
env:
163173
ENABLE_GITHUB_ENV_SYNC: ${{ vars.ENABLE_GITHUB_ENV_SYNC }}
@@ -174,7 +184,6 @@ jobs:
174184
LONGPORT_SECRET_NAME: ${{ vars.LONGPORT_SECRET_NAME }}
175185
NOTIFY_LANG: ${{ vars.NOTIFY_LANG }}
176186
GLOBAL_TELEGRAM_CHAT_ID: ${{ vars.GLOBAL_TELEGRAM_CHAT_ID }}
177-
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
178187
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
179188
LONGPORT_APP_KEY: ${{ secrets.LONGPORT_APP_KEY }}
180189
LONGPORT_APP_SECRET: ${{ secrets.LONGPORT_APP_SECRET }}
@@ -198,7 +207,6 @@ jobs:
198207
LONGPORT_SECRET_NAME
199208
NOTIFY_LANG
200209
GLOBAL_TELEGRAM_CHAT_ID
201-
GCP_SA_KEY
202210
)
203211
204212
missing_vars=()
@@ -235,13 +243,14 @@ jobs:
235243
if: steps.config.outputs.enabled == 'true'
236244
uses: google-github-actions/auth@v3
237245
with:
238-
credentials_json: ${{ env.GCP_SA_KEY }}
246+
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
247+
service_account: ${{ env.GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT }}
239248

240249
- name: Set up gcloud
241250
if: steps.config.outputs.enabled == 'true'
242251
uses: google-github-actions/setup-gcloud@v3
243252
with:
244-
project_id: ${{ steps.auth.outputs.project_id }}
253+
project_id: ${{ env.GCP_PROJECT_ID }}
245254
version: ">= 416.0.0"
246255

247256
- name: Sync Cloud Run environment

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ Recommended setup:
128128
- `NOTIFY_LANG`
129129
- `GLOBAL_TELEGRAM_CHAT_ID`
130130
- **Repository Secrets (shared):**
131-
- `GCP_SA_KEY`
132131
- Optional fallback only: `TELEGRAM_TOKEN`
133132
- **GitHub Environment: `longbridge-hk`**
134133
- Variables: `CLOUD_RUN_REGION`, `CLOUD_RUN_SERVICE`, `ACCOUNT_PREFIX`, `SERVICE_NAME`, `ACCOUNT_REGION`, `LONGPORT_SECRET_NAME`
@@ -141,10 +140,10 @@ On every push to `main`, the workflow updates both Cloud Run services with the s
141140

142141
Important:
143142

144-
- Put `GCP_SA_KEY` in **repository secrets**, not only under a single Environment. Both `longbridge-hk` and `longbridge-sg` jobs need it.
145143
- `CLOUD_RUN_REGION` should be set on each GitHub Environment, not as one shared repository variable. This lets `HK` and `SG` live in different Cloud Run regions.
146144
- The workflow only becomes strict when `ENABLE_GITHUB_ENV_SYNC=true`. If this variable is unset, the sync job is skipped and the old Google Cloud Trigger-only setup keeps working. Once you set it to `true`, missing env-sync values become a hard failure so you do not get a false green deployment.
147-
- Here "shared" only means **shared inside this repository** between the `HK` and `SG` Cloud Run services. `GCP_SA_KEY` remains repository-specific. The Telegram token and LongPort app credentials should live in Secret Manager and be referenced by the shared secret-name variables above; they are not meant to be a global secret set reused by unrelated quant repos.
145+
- GitHub now authenticates to Google Cloud with OIDC + Workload Identity Federation, so `GCP_SA_KEY` is no longer required for this workflow.
146+
- Here "shared" only means **shared inside this repository** between the `HK` and `SG` Cloud Run services. The Telegram token and LongPort app credentials should live in Secret Manager and be referenced by the shared secret-name variables above; they are not meant to be a global secret set reused by unrelated quant repos.
148147
- If you want one cross-project shared layer across multiple quant repos, keep it small: `GLOBAL_TELEGRAM_CHAT_ID` and `NOTIFY_LANG` are reasonable; account credentials and deployment keys are not.
149148

150149
### Deployment unit and naming
@@ -299,7 +298,6 @@ Secret Manager 中需存在 `LONGPORT_SECRET_NAME` 指定的密钥(默认: `lo
299298
- `NOTIFY_LANG`
300299
- `GLOBAL_TELEGRAM_CHAT_ID`
301300
- **仓库级 Secrets(共享):**
302-
- `GCP_SA_KEY`
303301
- 仅保留为 fallback:`TELEGRAM_TOKEN`
304302
- **GitHub Environment: `longbridge-hk`**
305303
- Variables: `CLOUD_RUN_REGION``CLOUD_RUN_SERVICE``ACCOUNT_PREFIX``SERVICE_NAME``ACCOUNT_REGION``LONGPORT_SECRET_NAME`
@@ -312,10 +310,10 @@ Secret Manager 中需存在 `LONGPORT_SECRET_NAME` 指定的密钥(默认: `lo
312310

313311
注意:
314312

315-
- `GCP_SA_KEY` 请放在**仓库级 Secret**,不要只放在某一个 Environment 里,因为 `longbridge-hk``longbridge-sg` 两个 job 都要用它。
316313
- `CLOUD_RUN_REGION` 应该分别放在 `longbridge-hk``longbridge-sg` 这两个 Environment 里,不要再当成一个仓库级共享变量。这样 HK 和 SG 才能各自更新到自己的 region。
317314
- 现在 workflow 只有在 `ENABLE_GITHUB_ENV_SYNC=true` 时才会严格检查配置。没打开这个开关时,它会直接跳过,不影响原来只靠 Google Cloud Trigger 的老流程;一旦打开,缺任何配置都会直接失败,避免你以为已经同步成功。
318-
- 这里的“共享”只是指 **同一个仓库里的 HK / SG 两个服务共享**`GCP_SA_KEY` 仍然是这个仓库自己的 secret。Telegram token 和 LongPort app 凭据建议放到 Secret Manager,并通过上面的 shared secret-name 变量引用,不建议把它们当成所有 quant 共用的全局 secrets。
315+
- GitHub 现在通过 OIDC + Workload Identity Federation 登录 Google Cloud,这个 workflow 不再需要 `GCP_SA_KEY`
316+
- 这里的“共享”只是指 **同一个仓库里的 HK / SG 两个服务共享**。Telegram token 和 LongPort app 凭据建议放到 Secret Manager,并通过上面的 shared secret-name 变量引用,不建议把它们当成所有 quant 共用的全局 secrets。
319317
- 如果你真的要在多个 quant 仓库之间保留一层全局共享,建议只保留 `GLOBAL_TELEGRAM_CHAT_ID``NOTIFY_LANG` 这种低耦合配置。
320318

321319
### 部署单元和命名建议

0 commit comments

Comments
 (0)