Skip to content

Commit a4d91e1

Browse files
committed
Fix Cloud Run invocation ID token
1 parent bf557eb commit a4d91e1

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

.github/workflows/invoke-cloud-run.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ jobs:
6363
project_id: ${{ env.GCP_PROJECT_ID }}
6464
version: ">= 416.0.0"
6565

66-
- name: Invoke service
66+
- name: Resolve service URL
67+
id: service
6768
run: |
6869
set -euo pipefail
6970
@@ -85,8 +86,24 @@ jobs:
8586
exit 1
8687
fi
8788
88-
token="$(gcloud auth print-identity-token --audiences="${service_url}")"
89+
echo "url=${service_url}" >> "$GITHUB_OUTPUT"
90+
echo "path=${raw_path}" >> "$GITHUB_OUTPUT"
91+
92+
- name: Authenticate for service invocation
93+
id: invoke-auth
94+
uses: google-github-actions/auth@v3
95+
with:
96+
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
97+
service_account: ${{ env.GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT }}
98+
token_format: id_token
99+
id_token_audience: ${{ steps.service.outputs.url }}
100+
id_token_include_email: true
101+
102+
- name: Invoke service
103+
run: |
104+
set -euo pipefail
105+
89106
curl --fail-with-body --show-error --silent \
90107
--request POST \
91-
--header "Authorization: Bearer ${token}" \
92-
"${service_url}${raw_path}"
108+
--header "Authorization: Bearer ${{ steps.invoke-auth.outputs.id_token }}" \
109+
"${{ steps.service.outputs.url }}${{ steps.service.outputs.path }}"

tests/test_invoke_cloud_run_workflow.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ grep -Fq "CLOUD_RUN_REGION: \${{ vars.CLOUD_RUN_REGION }}" "$workflow_file"
1414
grep -Fq "CLOUD_RUN_SERVICE: \${{ vars.CLOUD_RUN_SERVICE }}" "$workflow_file"
1515
grep -Fq "longbridge-hk|longbridge-sg" "$workflow_file"
1616
grep -Fq "gcloud run services describe \"\${CLOUD_RUN_SERVICE}\"" "$workflow_file"
17-
grep -Fq "gcloud auth print-identity-token --audiences=\"\${service_url}\"" "$workflow_file"
17+
grep -Fq "token_format: id_token" "$workflow_file"
18+
grep -Fq "id_token_audience: \${{ steps.service.outputs.url }}" "$workflow_file"
19+
grep -Fq "id_token_include_email: true" "$workflow_file"
1820
grep -Fq "curl --fail-with-body --show-error --silent" "$workflow_file"
1921
grep -Fq -- "--request POST" "$workflow_file"
22+
grep -Fq "steps.invoke-auth.outputs.id_token" "$workflow_file"

0 commit comments

Comments
 (0)