ここを参考にセットアップする。
- https://docs.github.com/ja/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-google-cloud-platform
- https://github.com/google-github-actions/auth
いくつかエラーが出たので解決メモ。
Error code invalid_request: Invalid value for “audience”. 🔗
google-github-actions/auth の workload_identity_provider 設定の方ところで、provider を設定すべきところに pool を設定していた。
jobs:
sample-job:
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
uses: google-github-actions/auth@v0
with:
# NG
# workload_identity_provider: projects/193431358102/locations/global/workloadIdentityPools/cicd-pipeline
# OK
workload_identity_provider: projects/193431358102/locations/global/workloadIdentityPools/cicd-pipeline/providers/github-actions
service_account: ${{ env.PROD_WI_SA }}
Error code invalid_grant: The audience in ID Token “…” does not match the expected audience …' 🔗
GCP側の「許可するオーディエンス」に https://github.com/<org>/<repo> を指定していたが、
google-github-actions/auth@v0 を使った時のデフォルトオーディエンスは https://iam.googleapi.com/... というものになる。
The value for the audience (aud) parameter in the generated GitHub Actions OIDC token. This value defaults to the value of workload_identity_provider, which is also the default value Google Cloud expects for the audience parameter on the token. We do not recommend changing this value.
https://github.com/google-github-actions/auth#authenticating-via-workload-identity-federation
ここの値を変えるのは非推奨とのことなので、GCP側の設定で来たするオーディエンスをデフォルトのものにする。