From 46e9fa6fb8da4d8395cc935db65f510a05afed38 Mon Sep 17 00:00:00 2001 From: Ignacio Rodriguez Paez Date: Thu, 26 Nov 2026 15:47:21 +0000 Subject: [PATCH 1/3] ci: authenticate Docker Hub with OIDC (SEC-4519) 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 --- .github/workflows/docker.yml | 13 ++++++++++--- .github/workflows/goreleaser.yml | 11 ++++++++--- docker/batch-change-volume-workspace/push.py | 17 ++--------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4c8b06a691..0aa7ab6d39 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -14,6 +14,9 @@ on: jobs: publish: runs-on: ubuntu-26.04 + permissions: + contents: read + id-token: write steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -29,7 +32,11 @@ jobs: with: platforms: arm64 - - run: ./docker/batch-change-volume-workspace/push.py -d ./docker/batch-change-volume-workspace/Dockerfile -i sourcegraph/src-batch-change-volume-workspace -p linux/amd64,linux/arm64,linux/386 --readme ./docker/batch-change-volume-workspace/README.md + - name: Login to Docker Hub + uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 + with: + username: sourcegraph env: - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKERHUB_OIDC_CONNECTIONID: 9f14c248-6ae5-4c2a-ad0c-3af4ca55a16e + + - run: ./docker/batch-change-volume-workspace/push.py -d ./docker/batch-change-volume-workspace/Dockerfile -i sourcegraph/src-batch-change-volume-workspace -p linux/amd64,linux/arm64,linux/386 --readme ./docker/batch-change-volume-workspace/README.md diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 33b7758a74..a674564ee8 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -142,6 +142,9 @@ jobs: name: Run goreleaser runs-on: ubuntu-latest needs: [release_type, goreleaser_pre] + permissions: + contents: read + id-token: write # By default, this job will be skipped if either "needs" job is skipped. This tells # GitHub actions to always run it, so long as the previous jobs that ran didn't fail. if: | @@ -183,10 +186,12 @@ jobs: go-version: ${{ steps.mise.outputs.go-version }} - run: go test ./... - run: go test -race -v ./... - - run: echo "${DOCKER_PASSWORD}" | docker login -u=$DOCKER_USERNAME --password-stdin + - name: Login to Docker Hub + uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 + with: + username: sourcegraph env: - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKERHUB_OIDC_CONNECTIONID: 9f14c248-6ae5-4c2a-ad0c-3af4ca55a16e - name: Run GoReleaser uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0 with: diff --git a/docker/batch-change-volume-workspace/push.py b/docker/batch-change-volume-workspace/push.py index bca152802e..ebd828e3a3 100755 --- a/docker/batch-change-volume-workspace/push.py +++ b/docker/batch-change-volume-workspace/push.py @@ -3,6 +3,8 @@ # This is a very simple script to build and push the Docker image used by the # Docker volume workspace driver. It's normally run from the "Publish Docker # image dependencies" GitHub Action, but can be run locally if necessary. +# It reuses Docker's existing authentication, set up by the workflow's OIDC +# login or by running docker login locally. # # This script requires Python 3.8 or later, and Docker 19.03 (for buildx). You # are strongly encouraged to use Black to format this file after modifying it. @@ -87,14 +89,6 @@ def docker_cli_build( run(args, stdin=dockerfile) -def docker_cli_login(username: str, password: str): - run( - ["docker", "login", f"-u={username}", "--password-stdin"], - input=password, - text=True, - ) - - def run(args: Sequence[str], /, **kwargs) -> subprocess.CompletedProcess: print(f"+ {' '.join(args)}") return subprocess.run(args, check=True, **kwargs) @@ -127,13 +121,6 @@ def main(): tags = calculate_tags(args.ref) print(f"will push tags: {', '.join(tags)}") - print("logging into Docker Hub") - try: - docker_cli_login(os.environ["DOCKER_USERNAME"], os.environ["DOCKER_PASSWORD"]) - except KeyError as e: - print(f"error retrieving environment variables: {e}") - raise - print("building and pushing image") docker_cli_build(open(args.dockerfile, "rb"), args.platform, args.image, tags) From 33898e92df30120791db43a7c979dba9360e359c Mon Sep 17 00:00:00 2001 From: Ignacio Rodriguez Paez Date: Thu, 26 Nov 2026 15:55:02 +0000 Subject: [PATCH 2/3] ci: use SHA-pinned Go setup dependencies 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 --- .github/workflows/goreleaser.yml | 2 +- .github/workflows/scip.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index a674564ee8..5a70e36d2f 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -181,7 +181,7 @@ jobs: id: mise run: echo "go-version=$(grep 'golang' mise.toml | cut -d'"' -f2)" >> $GITHUB_OUTPUT - name: Set up Go - uses: sourcegraph/actions/go-setup@4430dc1e4dde002387a4b655b41f6431ca75b1c1 # main + uses: sourcegraph/actions/go-setup@4c889fc8e48c06d4bbcb42a4b3a4965c2a83dccb # main with: go-version: ${{ steps.mise.outputs.go-version }} - run: go test ./... diff --git a/.github/workflows/scip.yml b/.github/workflows/scip.yml index 06b83af9e6..85aaf1d375 100644 --- a/.github/workflows/scip.yml +++ b/.github/workflows/scip.yml @@ -11,7 +11,7 @@ jobs: id: mise run: echo "go-version=$(grep 'golang' mise.toml | cut -d'"' -f2)" >> $GITHUB_OUTPUT - name: Set up Go - uses: sourcegraph/actions/go-setup@4430dc1e4dde002387a4b655b41f6431ca75b1c1 # main + uses: sourcegraph/actions/go-setup@4c889fc8e48c06d4bbcb42a4b3a4965c2a83dccb # main with: go-version: ${{ steps.mise.outputs.go-version }} From e877c9ebd17c0e1ff4611a25c9cef9d6d5cd6efa Mon Sep 17 00:00:00 2001 From: Ignacio Rodriguez Paez Date: Fri, 27 Nov 2026 10:15:07 +0000 Subject: [PATCH 3/3] ci: scope Docker OIDC credentials to the published image Preserve default credentials for public Docker Hub base-image pulls. SEC-4519 Amp-Thread-ID: https://ampcode.com/threads/T-01a2180e-b11b-76a6-b0cd-520034d574a0 Co-authored-by: Amp --- .github/workflows/docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0aa7ab6d39..7cffa49dbd 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,6 +36,7 @@ jobs: uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0 with: username: sourcegraph + scope: sourcegraph/src-batch-change-volume-workspace env: DOCKERHUB_OIDC_CONNECTIONID: 9f14c248-6ae5-4c2a-ad0c-3af4ca55a16e