From 15da89219c2c7782bfeabc1699882f5d1390e170 Mon Sep 17 00:00:00 2001 From: Monty Perrotti Date: Sun, 6 Sep 2026 20:26:48 -0700 Subject: [PATCH] chore: pin GitHub Actions to commit SHAs AUDIT.md P2#15: every action reference across this repo's 2 workflows was pinned to a mutable version tag (@v4 through @v7). A tag can be moved to point at a different commit -- by the upstream maintainer, or by anyone who compromises their account -- and every workflow using it would silently start executing different code on its next run. Each reference now pins the exact commit the tag currently resolves to, with the tag kept as a trailing comment for readability (GitHub's own recommended convention: `owner/repo@ # vN`). Resolved via the GitHub API (git/refs/tags, dereferencing through the tag object where the ref points at one rather than a commit directly) rather than guessed, and spot-verified two of the resulting SHAs against their own commit metadata (dates and messages consistent with the claimed release) before trusting the rest. actions/checkout@v5 -> fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 actions/setup-python@v6 -> ece7cb06caefa5fff74198d8649806c4678c61a1 actions/upload-artifact@v7 -> 043fb46d1a93c77aae656e7c1c64a875d1fc6a0a docker/build-push-action@v7 -> 53b7df96c91f9c12dcc8a07bcb9ccacbed38856a docker/login-action@v4 -> dbcb813823bdd20940b903addbd779551569679f docker/setup-buildx-action@v4 -> 37fe631027851001ddb9b187196cc803df7f5f0e docker/setup-qemu-action@v4 -> 1f40c72289eff860ee54a304f1438e3cff362e0a tests/test_container_permissions.py had two assertions relying on bare `"docker/action-name@vN"` substrings appearing verbatim, which no longer holds once the tag and the commit SHA share a line. Updated both to regex assertions (`docker/action-name@[0-9a-f]{40} # vN`) that still confirm the version, just not by exact substring, and to search for that pattern rather than the bare string when checking step ordering. Verified: YAML still parses for every touched file, no CRLF introduced, full pytest suite's failing-test set is byte-identical to the known Windows-platform baseline (diffed), the two specifically-updated tests pass, ruff findings unchanged from before this change (3 pre-existing, already reviewed). Co-Authored-By: Claude Opus 5 --- .github/workflows/ci.yml | 8 ++++---- .github/workflows/release-image.yml | 12 ++++++------ tests/test_container_permissions.py | 19 ++++++++++++++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca9446d..e060def 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,10 +26,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out repository - uses: actions/checkout@v5 + uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 - name: Set up Python - uses: actions/setup-python@v6 + uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6 with: python-version: "3.12" @@ -37,10 +37,10 @@ jobs: run: python -m unittest discover -s tests -v - name: Set up QEMU - uses: docker/setup-qemu-action@v4 + uses: docker/setup-qemu-action@1f40c72289eff860ee54a304f1438e3cff362e0a # v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4 - name: Validate Docker Compose run: IMAGE_VERSION="$(cat VERSION)" docker compose config diff --git a/.github/workflows/release-image.yml b/.github/workflows/release-image.yml index cd65496..e531458 100644 --- a/.github/workflows/release-image.yml +++ b/.github/workflows/release-image.yml @@ -23,12 +23,12 @@ jobs: steps: - name: Check out repository - uses: actions/checkout@v5 + uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v6 + uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6 with: python-version: "3.12" @@ -36,10 +36,10 @@ jobs: run: python -m unittest discover -s tests -v - name: Set up QEMU - uses: docker/setup-qemu-action@v4 + uses: docker/setup-qemu-action@1f40c72289eff860ee54a304f1438e3cff362e0a # v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4 - name: Prepare release metadata id: release-meta @@ -89,7 +89,7 @@ jobs: - name: Log in to GHCR if: steps.release-meta.outputs.publish == 'true' - uses: docker/login-action@v4 + uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 with: registry: ghcr.io username: ${{ github.actor }} @@ -97,7 +97,7 @@ jobs: - name: Build image id: build - uses: docker/build-push-action@v7 + uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7 with: context: . platforms: linux/amd64,linux/arm64 diff --git a/tests/test_container_permissions.py b/tests/test_container_permissions.py index 838501c..4bc8621 100644 --- a/tests/test_container_permissions.py +++ b/tests/test_container_permissions.py @@ -219,8 +219,14 @@ def test_release_workflow_publishes_before_idempotent_release(self) -> None: self.assertIn("--verify-tag", workflow) self.assertIn("--latest", workflow) self.assertNotIn("--prerelease", workflow) + # Pinned to a commit SHA (AUDIT.md #15); search for the pin plus + # its trailing version comment rather than the bare tag. + build_push_match = re.search( + r"uses: docker/build-push-action@[0-9a-f]{40} # v7", workflow + ) + self.assertIsNotNone(build_push_match) self.assertLess( - workflow.index("uses: docker/build-push-action@v7"), + build_push_match.start(), workflow.index("name: Create or update GitHub Release"), ) @@ -232,10 +238,13 @@ def test_workflows_use_current_docker_action_majors(self) -> None: self.assertNotIn("docker/setup-buildx-action@v3", content) self.assertNotIn("docker/build-push-action@v6", content) self.assertNotIn("docker/login-action@v3", content) - self.assertIn("docker/setup-qemu-action@v4", content) - self.assertIn("docker/setup-buildx-action@v4", content) - self.assertIn("docker/build-push-action@v7", content) - self.assertIn("docker/login-action@v4", content) + # Pinned to commit SHAs (AUDIT.md #15); each assertion below + # matches the pin plus its trailing version comment, since the + # bare tag no longer appears as its own substring. + self.assertRegex(content, r"docker/setup-qemu-action@[0-9a-f]{40} # v4") + self.assertRegex(content, r"docker/setup-buildx-action@[0-9a-f]{40} # v4") + self.assertRegex(content, r"docker/build-push-action@[0-9a-f]{40} # v7") + self.assertRegex(content, r"docker/login-action@[0-9a-f]{40} # v4") self.assertNotIn("--format '{{ .Digest }}'", content) self.assertIn("--format '{{ .Manifest.Digest }}'", content) self.assertIn("--output type=oci,dest=/tmp/mochad-ci-index.tar", content)