Skip to content

feat(auth): support Workload Identity Federation for Artifact Registry - #163

Closed
lucaghersi wants to merge 1 commit into
mainfrom
gar-workload-identity-auth
Closed

lucaghersi wants to merge 1 commit into
mainfrom
gar-workload-identity-auth

Conversation

@lucaghersi

@lucaghersi lucaghersi commented Sep 14, 2026

Copy link
Copy Markdown

Type of Change

  • Enhancement / new feature

Description

Goal: let this action push to Google Artifact Registry without a long-lived key, as the first step of moving off Harbor.

Adds gcp-workload-identity-provider + gcp-service-account. When both are set, the action exchanges the job's OIDC token for a short-lived Google access token and logs in with that. GAR accepts it as a basic-auth password under the fixed username oauth2accesstoken, so retag-image.sh needs no changes — it keeps working against the registry v2 API.

Federation only. A service account key input was considered and dropped: Staffbase is migrating straight to Workload Identity Federation, and a public action should not advertise a long-lived-credential path that its own consumers have rejected.

Also fixes a silent failure. Half-configured credentials (username with no password, provider with no service account) used to skip the build and leave the job green while the deployment went stale. They now fail with the missing half named — including the id-token: write case, which is the first thing a caller will hit. Passing no credentials stays a warning: that is the documented deploy-only mode, where skipping is the point.

How to review:

  • scripts/resolve-registry-auth.sh — the whole decision. The password never passes through a step output.
  • action.yml — the new auth step, and the Buildx / Login / Build gates now sharing one authenticated flag.
  • tests/resolve-registry-auth.bats — 10 cases, all passing. mise run lint clean.

Nothing changes for existing callers: no GCP inputs means the old path.

Not defaulted on purpose. This repo is public. A default would make every caller attempt Google auth and fail any job without id-token: write. Staffbase-wide defaults live in gha-workflows.

Consumers: Staffbase/gha-workflows#510 pins this action and is blocked on it being tagged. The GCP side is applied (Staffbase/infrastructure#17340).

Checklist

  • Write tests
  • Make sure all tests pass
  • Update documentation
  • Reference relevant issue(s)

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@lucaghersi

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Adds gcp-workload-identity-provider and gcp-service-account as an
alternative to docker-username / docker-password. When both are set the
action exchanges the job's OIDC token for a short-lived Google access
token and logs in with it, so pushing to Artifact Registry needs no
long-lived key. The calling job must grant permissions: id-token: write,
which a composite action cannot request for itself.

Artifact Registry accepts that token as a basic-auth password under the
fixed username oauth2accesstoken, so the retag step keeps working against
the registry v2 API without changes.

The split is deliberate: the script decides whether authentication is
possible, and the steps select the credential inline. Neither half of a
credential passes through a step output or the environment file.

The three steps previously gated on docker-username and docker-password
now share that resolved flag, so they run under either credential source.

Half-configured credentials now stop the run instead of skipping the
build. A username with no password, or a provider with no service
account, are what a mistyped secret name looks like, and skipping the
build there left the job green while the deployment went stale. Each case
names the missing half. Supplying no credentials at all stays a warning:
that is the documented deploy-only usage.

Both inputs are left without a default on purpose: this action is public,
and a default would make every caller attempt Google authentication and
fail any job that has not granted id-token: write.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@lucaghersi

Copy link
Copy Markdown
Author

Not needed. Artifact Registry accepts a Google access token as a basic-auth password under the fixed username oauth2accesstoken, so this action works against GAR as it already is — the caller mints the token and passes it as docker-password.

Federation now lives in one place, Staffbase/gha-workflows#511, and this action stays unaware of Google. That also removes the release dependency: no version bump is needed for the migration.

The one independently useful change here was failing on half-configured credentials instead of silently skipping the build. Worth reopening as its own PR if someone wants it.

@lucaghersi lucaghersi closed this Sep 14, 2026
@lucaghersi
lucaghersi deleted the gar-workload-identity-auth branch September 14, 2026 16:24
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant