Skip to content

Commit 8852fa9

Browse files
update docs for workload identity federation with GAR
this is a last mile doc improvement for #640. it clarifies how to use direct identity federation in GAR without a service account using `google-github-actions/auth@v2`. Signed-off-by: David Montoya <davidmontoyago@gmail.com>
1 parent 3d10084 commit 8852fa9

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ You can authenticate with workload identity federation or a service account.
227227

228228
#### Workload identity federation
229229

230-
Your service account must have permission to push to GAR. Use the
231-
`google-github-actions/auth` action to authenticate using workload identity as
230+
Configure [Direct Workload Identity Federation](https://github.com/google-github-actions/auth/blob/v2.1.10/README.md#preferred-direct-workload-identity-federation) for GitHub Actions in Google Cloud and avoid long-lived GCP credentials.
231+
Make sure to grant the [principal identity](https://cloud.google.com/iam/docs/workload-identity-federation#principal-types) enough permissions to the GAR repository (E.g.: `roles/artifactregistry.writer`).
232+
Use the `google-github-actions/auth@v2` action to authenticate using workload identity as
232233
shown in the following example:
233234

234235
```yaml
@@ -238,35 +239,35 @@ on:
238239
push:
239240
branches: main
240241
242+
env:
243+
GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
244+
WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
245+
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
246+
241247
jobs:
242248
login:
243249
runs-on: ubuntu-latest
244250
steps:
245251
-
246252
name: Authenticate to Google Cloud
247253
id: auth
248-
uses: google-github-actions/auth@v1
254+
uses: google-github-actions/auth@v2
249255
with:
250-
token_format: access_token
251-
workload_identity_provider: <workload_identity_provider>
252-
service_account: <service_account>
256+
project_id: ${{ env.GCP_PROJECT }}
257+
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
258+
253259
-
254-
name: Login to GAR
260+
name: Login to Google Artifact Registry
255261
uses: docker/login-action@v3
256262
with:
257-
registry: <location>-docker.pkg.dev
263+
registry: ${{ env.REGISTRY_URL}}
258264
username: oauth2accesstoken
259-
password: ${{ steps.auth.outputs.access_token }}
265+
password: ${{ steps.auth.outputs.auth_token }}
260266
```
261267

262-
> Replace `<workload_identity_provider>` with configured workload identity
263-
> provider
268+
> Set `WORKLOAD_IDENTITY_PROVIDER` to the configured workload identity provider. For steps to configure, [see here](https://github.com/google-github-actions/auth/blob/v2.1.10/README.md#inputs).
264269

265-
> Replace `<service_account>` with configured service account in workload
266-
> identity provider which has access to push to GCR
267-
268-
> Replace `<location>` with the regional or multi-regional [location](https://cloud.google.com/artifact-registry/docs/repo-organize#locations)
269-
> of the repository where the image is stored.
270+
> Set `REGISTRY_URL` to the regional or multi-regional [repository URL](https://cloud.google.com/artifact-registry/docs/repo-organize#locations).
270271

271272
#### Service account based authentication
272273

0 commit comments

Comments
 (0)