Skip to content

ci: authenticate Docker Hub with OIDC (SEC-4519) - #1417

Open
nachorpaez wants to merge 2 commits into
mainfrom
sec-4519-docker-oidc
Open

nachorpaez wants to merge 2 commits into
mainfrom
sec-4519-docker-oidc

Conversation

@nachorpaez

@nachorpaez nachorpaez commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Part of SEC-4519: Configure OIDC in GitHub Actions that log in to Docker. Replace reusable Docker credentials, which can be abused if leaked, with short-lived OIDC authentication.

Changes

  • Replace the shell login in goreleaser.yml and authenticate before the dependency-image publisher in docker.yml. Both use Docker organization sourcegraph and connection 9f14c248-6ae5-4c2a-ad0c-3af4ca55a16e without a password input.
  • Pin both docker/login-action steps to 8aa5831fb8d48d8f76594c7ddde61ae58019f550 (v4.8.0); grant contents: read and id-token: write only to the two Docker-publishing jobs. GoReleaser keeps its existing cross-repository PAT for GitHub/Homebrew publishing.
  • Remove the mandatory static-credential login from docker/batch-change-volume-workspace/push.py. It now reuses Docker's existing authentication, whether provided by the OIDC action or by docker login locally. The script no longer reads DOCKER_USERNAME or DOCKER_PASSWORD.
  • Update both sourcegraph/actions/go-setup callers (scip.yml and goreleaser.yml) to the upstream pinning fix. Its only change is pinning the nested actions/setup-go@v5 to a full SHA, fixing the organization's full-SHA-policy rejection without weakening that policy.
  • Preserve workflow triggers, manual dispatch, version/patch-release logic, Homebrew/npm publishing, image tags, platform selection, and Docker build arguments. No GitHub subject-format changes, Docker trust-policy edits, or secret deletions.

OIDC refs and required Docker rule

Compatibility rule for the existing unprefixed release tags, with Image Push to only sourcegraph/src-cli and sourcegraph/src-batch-change-volume-workspace:

repo:sourcegraph/src-cli:ref:refs/tags/*
  • Tag refs, such as 8.2.0, can authenticate; this is deliberately not v* because src-cli versions are unprefixed.
  • The existing docker.yml exclusion of the latest tag remains unchanged. The Docker wildcard itself does not enforce that exclusion or semantic-version syntax.
  • No branches, including main, receive Docker access. Manual dispatch on a branch remains available but will fail authentication under this tag-only rule; dispatch release retries on the appropriate tag.
  • Protect release-tag creation. Exact-tag or supported-major rules would be stricter, but are not introduced here because they could alter supported release/backport paths.
  • Both workflows share the default tag subject, so this rule allows each to access both images. Separate connection IDs alone cannot isolate them; workflow-specific subjects would be a separate coordinated change. This src-cli rule must not grant access to Cody's image on the shared connection.

GitHub currently reports legacy default subjects. The deployed Docker rules have not been inspected; confirm the subject and resource scopes before merging. Release tags must include these workflow changes to use OIDC; old tagged workflows still reference static credentials. Keep shared credentials until every consumer has migrated and been validated.

Test plan

  • Parsed-YAML comparison verified the initial authentication-only changes. The follow-up changes only the shared Go action SHA in its two callers. Triggers, conditions and commands are unchanged, including the push.py invocation.
  • Executed push.py through its CLI with a stub Docker executable and no static credential variables: the original fails with KeyError; the updated script succeeds using the inherited Docker configuration. Verified exact latest, 8, 8.2, 8.2.17 tags, all three architecture arguments and Dockerfile stdin; explicit branch refs still produce only latest, and failed Docker builds still fail the script. This was local validation, not a real registry exchange or image push.
  • Black formatting check and git diff --check passed.
  • actionlint v1.7.12 passed on scip.yml and goreleaser.yml, including the updated pins. For docker.yml, both base and changed versions report the same existing unknown ubuntu-26.04 runner label, with no new diagnostics. External shellcheck/pyflakes integrations were disabled. The runner label is intentionally unchanged.
  • No real token exchange, release or image publication was performed. Validate both publishing paths on an authorized release after approval; PR CI cannot prove Docker trust.

How the script receives Docker authentication

The login action exchanges GitHub OIDC for a short-lived Docker token, then invokes docker login --password-stdin. Docker stores it in the runner user's Docker configuration (normally $HOME/.docker/config.json, or the configured credential helper / $DOCKER_CONFIG location). The subsequent Python step runs on the same job and invokes docker buildx build --push without overriding its environment or configuration. Buildx reads Docker's credentials and supplies registry authentication to BuildKit; Python never needs the token itself. The login action's logout runs in post-job cleanup, after the script finishes.

Verified against the pinned login action, Docker credential-storage documentation, and Buildx auth-provider wiring. The local stub test checks script behavior, not Docker Hub's deployed trust policy.

Investigation and ruleset rationale · GitHub Docker OIDC guide

Use the configured Docker OIDC connection instead of static Docker credentials, preserving release triggers and publishing behavior.

Linear: https://linear.app/sourcegraph/issue/SEC-4519/configure-oidc-in-github-actions-that-log-in-to-docker

Amp-Thread-ID: https://ampcode.com/threads/T-01a2180e-b11b-76a6-b0cd-520034d574a0
Co-authored-by: Amp <amp@ampcode.com>
@nachorpaez
nachorpaez requested a review from a team November 26, 2026 15:47
@github-actions

Copy link
Copy Markdown

Update the shared Go setup action to its upstream full-SHA pinning fix.

Amp-Thread-ID: https://ampcode.com/threads/T-01a2180e-b11b-76a6-b0cd-520034d574a0
Co-authored-by: Amp <amp@ampcode.com>
@nachorpaez
nachorpaez marked this pull request as ready for review November 26, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant