Skip to content

Commit 62035b0

Browse files
committed
Switch to using /github/home for storing credentials
The GitHub Action currently puts generated credentials into $GITHUB_WORKSPACE (/github/workspace). Unfortunately this is also the working directory of the checkout, so it's too easy to accidentally bundle the generated credentials into Docker containers, binaries, or anything that uses `*` or `.` as a build context. In the past, we tried to move the exported credentials into RUNNER_TEMP or other directories, but it always introduced incompatibility with the various community workflows (Docker, self-hosted, etc.): - google-github-actions/setup-gcloud#148 - google-github-actions/setup-gcloud#149 - google-github-actions/setup-gcloud#405 - google-github-actions/setup-gcloud#412 While undocumented, it appears that `/github/home` is an understood path, AND that path is mounted into Docker containers. That means we can export credentials outside of the workspace and still have them available inside the Docker container without users taking manual actions. This comes at three major costs: 1. We have to write the file into two locations. This isn't ideal, but it's also not the end of the world. 2. We would be relying on an undocumented filepath which GitHub could change at any point in the future. Since this is not part of the publicly-documented API, GitHub is within their rights to change this without notice, potentially breaking everyone/everything. 3. Because of the previous point, there are no environment variables that export these paths. We have to dynamically compile them, and it's a bit messy.
1 parent 0920706 commit 62035b0

File tree

3 files changed

+162
-200
lines changed

3 files changed

+162
-200
lines changed

.github/workflows/test.yml

Lines changed: 134 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -112,140 +112,140 @@ jobs:
112112
gcloud secrets versions access "latest" --secret "${{ vars.SECRET_NAME }}"
113113
114114
115-
#
116-
# Workload Identity Federation through a Service Account
117-
#
118-
workload_identity_federation_through_service_account:
119-
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
120-
name: 'workload_identity_federation_through_service_account'
121-
runs-on: '${{ matrix.os }}'
122-
strategy:
123-
fail-fast: false
124-
matrix:
125-
os:
126-
- 'ubuntu-latest'
127-
- 'windows-latest'
128-
- 'macos-latest'
129-
130-
permissions:
131-
id-token: 'write'
132-
133-
steps:
134-
- uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
135-
136-
- uses: 'actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a' # ratchet:actions/setup-node@v4
137-
with:
138-
node-version: '20.x'
139-
140-
- name: 'npm build'
141-
run: 'npm ci && npm run build'
142-
143-
- id: 'auth-default'
144-
name: 'auth-default'
145-
uses: './'
146-
with:
147-
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
148-
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
149-
150-
- uses: 'google-github-actions/setup-gcloud@main' # ratchet:exclude
151-
with:
152-
version: '>= 363.0.0'
153-
154-
- name: 'gcloud'
155-
run: |-
156-
gcloud secrets versions access "latest" --secret "${{ vars.SECRET_NAME }}"
157-
158-
- id: 'auth-access-token'
159-
name: 'auth-access-token'
160-
uses: './'
161-
with:
162-
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
163-
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
164-
token_format: 'access_token'
165-
166-
- id: 'oauth-token'
167-
name: 'oauth-token'
168-
run: |-
169-
curl https://secretmanager.googleapis.com/v1/projects/${{ steps.auth-access-token.outputs.project_id }}/secrets/${{ vars.SECRET_NAME }}/versions/latest:access \
170-
--silent \
171-
--show-error \
172-
--fail \
173-
--header "Authorization: Bearer ${{ steps.auth-access-token.outputs.access_token }}"
174-
175-
- id: 'id-token'
176-
name: 'id-token'
177-
uses: './'
178-
with:
179-
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
180-
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
181-
token_format: 'id_token'
182-
id_token_audience: 'https://secretmanager.googleapis.com/'
183-
id_token_include_email: true
184-
185-
186-
#
187-
# Service Account Key JSON
188-
#
189-
credentials_json:
190-
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
191-
name: 'credentials_json'
192-
runs-on: '${{ matrix.os }}'
193-
strategy:
194-
fail-fast: false
195-
matrix:
196-
os:
197-
- 'ubuntu-latest'
198-
- 'windows-latest'
199-
- 'macos-latest'
200-
201-
steps:
202-
- uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
203-
204-
- uses: 'actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a' # ratchet:actions/setup-node@v4
205-
with:
206-
node-version: '20.x'
207-
208-
- name: 'npm build'
209-
run: 'npm ci && npm run build'
210-
211-
- id: 'auth-default'
212-
name: 'auth-default'
213-
uses: './'
214-
with:
215-
credentials_json: '${{ secrets.SERVICE_ACCOUNT_KEY_JSON }}'
216-
217-
- uses: 'google-github-actions/setup-gcloud@main' # ratchet:exclude
218-
with:
219-
version: '>= 363.0.0'
220-
221-
- name: 'gcloud'
222-
run: |-
223-
gcloud secrets versions access "latest" --secret "${{ vars.SECRET_NAME }}"
224-
225-
- id: 'auth-access-token'
226-
name: 'auth-access-token'
227-
uses: './'
228-
with:
229-
credentials_json: '${{ secrets.SERVICE_ACCOUNT_KEY_JSON }}'
230-
token_format: 'access_token'
231-
232-
- id: 'access-token'
233-
name: 'access-token'
234-
run: |-
235-
curl https://secretmanager.googleapis.com/v1/projects/${{ steps.auth-access-token.outputs.project_id }}/secrets/${{ vars.SECRET_NAME }}/versions/latest:access \
236-
--silent \
237-
--show-error \
238-
--fail \
239-
--header "Authorization: Bearer ${{ steps.auth-access-token.outputs.access_token }}"
240-
241-
- id: 'auth-id-token'
242-
name: 'auth-id-token'
243-
uses: './'
244-
with:
245-
credentials_json: '${{ secrets.SERVICE_ACCOUNT_KEY_JSON }}'
246-
token_format: 'id_token'
247-
id_token_audience: 'https://secretmanager.googleapis.com/'
248-
id_token_include_email: true
115+
# #
116+
# # Workload Identity Federation through a Service Account
117+
# #
118+
# workload_identity_federation_through_service_account:
119+
# if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
120+
# name: 'workload_identity_federation_through_service_account'
121+
# runs-on: '${{ matrix.os }}'
122+
# strategy:
123+
# fail-fast: false
124+
# matrix:
125+
# os:
126+
# - 'ubuntu-latest'
127+
# - 'windows-latest'
128+
# - 'macos-latest'
129+
130+
# permissions:
131+
# id-token: 'write'
132+
133+
# steps:
134+
# - uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
135+
136+
# - uses: 'actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a' # ratchet:actions/setup-node@v4
137+
# with:
138+
# node-version: '20.x'
139+
140+
# - name: 'npm build'
141+
# run: 'npm ci && npm run build'
142+
143+
# - id: 'auth-default'
144+
# name: 'auth-default'
145+
# uses: './'
146+
# with:
147+
# workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
148+
# service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
149+
150+
# - uses: 'google-github-actions/setup-gcloud@main' # ratchet:exclude
151+
# with:
152+
# version: '>= 363.0.0'
153+
154+
# - name: 'gcloud'
155+
# run: |-
156+
# gcloud secrets versions access "latest" --secret "${{ vars.SECRET_NAME }}"
157+
158+
# - id: 'auth-access-token'
159+
# name: 'auth-access-token'
160+
# uses: './'
161+
# with:
162+
# workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
163+
# service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
164+
# token_format: 'access_token'
165+
166+
# - id: 'oauth-token'
167+
# name: 'oauth-token'
168+
# run: |-
169+
# curl https://secretmanager.googleapis.com/v1/projects/${{ steps.auth-access-token.outputs.project_id }}/secrets/${{ vars.SECRET_NAME }}/versions/latest:access \
170+
# --silent \
171+
# --show-error \
172+
# --fail \
173+
# --header "Authorization: Bearer ${{ steps.auth-access-token.outputs.access_token }}"
174+
175+
# - id: 'id-token'
176+
# name: 'id-token'
177+
# uses: './'
178+
# with:
179+
# workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
180+
# service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
181+
# token_format: 'id_token'
182+
# id_token_audience: 'https://secretmanager.googleapis.com/'
183+
# id_token_include_email: true
184+
185+
186+
# #
187+
# # Service Account Key JSON
188+
# #
189+
# credentials_json:
190+
# if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}
191+
# name: 'credentials_json'
192+
# runs-on: '${{ matrix.os }}'
193+
# strategy:
194+
# fail-fast: false
195+
# matrix:
196+
# os:
197+
# - 'ubuntu-latest'
198+
# - 'windows-latest'
199+
# - 'macos-latest'
200+
201+
# steps:
202+
# - uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
203+
204+
# - uses: 'actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a' # ratchet:actions/setup-node@v4
205+
# with:
206+
# node-version: '20.x'
207+
208+
# - name: 'npm build'
209+
# run: 'npm ci && npm run build'
210+
211+
# - id: 'auth-default'
212+
# name: 'auth-default'
213+
# uses: './'
214+
# with:
215+
# credentials_json: '${{ secrets.SERVICE_ACCOUNT_KEY_JSON }}'
216+
217+
# - uses: 'google-github-actions/setup-gcloud@main' # ratchet:exclude
218+
# with:
219+
# version: '>= 363.0.0'
220+
221+
# - name: 'gcloud'
222+
# run: |-
223+
# gcloud secrets versions access "latest" --secret "${{ vars.SECRET_NAME }}"
224+
225+
# - id: 'auth-access-token'
226+
# name: 'auth-access-token'
227+
# uses: './'
228+
# with:
229+
# credentials_json: '${{ secrets.SERVICE_ACCOUNT_KEY_JSON }}'
230+
# token_format: 'access_token'
231+
232+
# - id: 'access-token'
233+
# name: 'access-token'
234+
# run: |-
235+
# curl https://secretmanager.googleapis.com/v1/projects/${{ steps.auth-access-token.outputs.project_id }}/secrets/${{ vars.SECRET_NAME }}/versions/latest:access \
236+
# --silent \
237+
# --show-error \
238+
# --fail \
239+
# --header "Authorization: Bearer ${{ steps.auth-access-token.outputs.access_token }}"
240+
241+
# - id: 'auth-id-token'
242+
# name: 'auth-id-token'
243+
# uses: './'
244+
# with:
245+
# credentials_json: '${{ secrets.SERVICE_ACCOUNT_KEY_JSON }}'
246+
# token_format: 'id_token'
247+
# id_token_audience: 'https://secretmanager.googleapis.com/'
248+
# id_token_include_email: true
249249

250250
#
251251
# This test ensures that the GOOGLE_APPLICATION_CREDENTIALS environment

README.md

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ support](https://cloud.google.com/support).**
2626

2727
## Prerequisites
2828

29-
- Run the `actions/checkout@v4` step _before_ this action. Omitting the
30-
checkout step or putting it after `auth` will cause future steps to be
31-
unable to authenticate.
32-
33-
- To create binaries, containers, pull requests, or other releases, add the
34-
following to your `.gitignore`, `.dockerignore` and similar files to prevent
35-
accidentally committing credentials to your release artifact:
36-
37-
```text
38-
# Ignore generated credentials from google-github-actions/auth
39-
gha-creds-*.json
40-
```
41-
4229
- This action runs using Node 20. Use a [runner
4330
version](https://github.com/actions/virtual-environments) that supports this
4431
version of Node or newer.
@@ -237,20 +224,9 @@ regardless of the authentication mechanism.
237224
generate a credentials file which can be used for authentication via gcloud
238225
and Google Cloud SDKs in other steps in the workflow. The default is true.
239226

240-
The credentials file is exported into `$GITHUB_WORKSPACE`, which makes it
241-
available to all future steps and filesystems (including Docker-based GitHub
242-
Actions). The file is automatically removed at the end of the job via a post
243-
action. In order to use exported credentials, you **must** add the
244-
`actions/checkout` step before calling `auth`. This is due to how GitHub
245-
Actions creates `$GITHUB_WORKSPACE`:
246-
247-
```yaml
248-
jobs:
249-
job_id:
250-
steps:
251-
- uses: 'actions/checkout@v4' # Must come first!
252-
- uses: 'google-github-actions/auth@v2'
253-
```
227+
The credentials file is exported into the GitHub home directory
228+
(`/github/home` on Unix, `C:/TODO/TODO` on Windows) and a special directory
229+
in the temp directory that is shared with Docker-based actions.
254230

255231
- `export_environment_variables`: (Optional) If true, the action will export
256232
common environment variables which are known to be consumed by popular

0 commit comments

Comments
 (0)