From 76d2eb8112febf5f4e7e75ba08b63f60389de999 Mon Sep 17 00:00:00 2001 From: David Collom Date: Wed, 18 Nov 2026 13:18:24 +0000 Subject: [PATCH] Harden GitHub Actions workflows Pin every third-party action by commit SHA, with the tag in a comment so Dependabot keeps updating them. This includes sigstore/cosign-installer, which was referenced at @main in the release job that holds the signing and registry credentials, and actions/stale. Each SHA was checked against the tag it is annotated with. Fix shell injection and context handling: - release.yaml: pass needs.*.outputs.name and github.ref_name through env: instead of expanding them inside run: scripts. Fix the arguments of the prerelease contains() call, which were reversed and never matched. - helm-docs.yaml and coverage-badge.yaml: push to github.ref_name. They push on push/workflow_dispatch events, where github.head_ref is empty, and helm-docs checked out and pushed to a pull request head from a workflow with write permissions. - build-test.yaml: remove a step whose "uses:" value was invalid. - helm-test.yaml: pin the helm-unittest plugin to a release tag (it is installed without signature verification) and the Kyverno CLI to v1.20.0, because the default v1.10.3 cannot load the ValidatingPolicy policies the job applies. Limit Dependabot auto-approve and auto-merge to non-major Go module updates, so GitHub Actions and base image bumps get a human review. Signed-off-by: David Collom --- .github/workflows/build-test.yaml | 30 +++++------- .github/workflows/coverage-badge.yaml | 12 ++--- .github/workflows/dependabot-reviewer.yaml | 4 ++ .github/workflows/helm-docs.yaml | 16 +++---- .github/workflows/helm-test.yaml | 16 ++++--- .github/workflows/release.yaml | 54 +++++++++++----------- .github/workflows/stale.yaml | 2 +- 7 files changed, 67 insertions(+), 67 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index ca8075ad..2d848448 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -24,7 +24,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Golang - uses: actions/setup-go@v7 + uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7 with: go-version-file: go.mod @@ -43,10 +43,9 @@ jobs: security-events: write steps: - name: Checkout code - uses: actions/checkout@v7.0.1 - + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Run Trivy vulnerability scanner in repo mode - uses: aquasecurity/trivy-action@v0.36.0 + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 continue-on-error: true with: scan-type: "fs" @@ -57,7 +56,7 @@ jobs: severity: "CRITICAL,HIGH,MEDIUM" - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v4.39.1 + uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1 with: sarif_file: "trivy-results.sarif" @@ -72,7 +71,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - id: govulncheck - uses: golang/govulncheck-action@v1 + uses: golang/govulncheck-action@032d45514ae346b1db93c04b0c90b841c370344f # v1 with: go-version-file: go.mod go-package: ./... @@ -86,7 +85,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Golang - uses: actions/setup-go@v7 + uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7 with: go-version-file: go.mod @@ -98,16 +97,12 @@ jobs: run: make test - name: check test coverage - uses: vladopajic/go-test-coverage@v2 + uses: vladopajic/go-test-coverage@6890500b00a7e5862e54662c04ea9fa7c799ce1e # v2 with: config: ./.testcoverage.yml - - name: Trigger Coverage update - uses: ./.github/workflows/coverage-badge.yaml - continue-on-error: true - - name: Generate code coverage artifacts - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 with: name: code-coverage path: coverage.out @@ -129,17 +124,16 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - + uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 with: platforms: ${{ matrix.platform }} driver: docker-container use: true - name: Build Images - uses: docker/build-push-action@v7 + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 with: context: . platforms: ${{ matrix.platform }} @@ -156,7 +150,7 @@ jobs: type=provenance,mode=max - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@v0.36.0 + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: input: ./.oci-image format: "table" diff --git a/.github/workflows/coverage-badge.yaml b/.github/workflows/coverage-badge.yaml index 6376468a..4f3a8978 100644 --- a/.github/workflows/coverage-badge.yaml +++ b/.github/workflows/coverage-badge.yaml @@ -13,13 +13,13 @@ jobs: name: Update coverage badge steps: - name: Checkout - uses: actions/checkout@v7.0.1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. - name: Setup go - uses: actions/setup-go@v7 + uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7 with: go-version-file: 'go.mod' @@ -29,12 +29,12 @@ jobs: go tool cover -func=coverage.out -o=coverage.out - name: Go Coverage Badge # Pass the `coverage.out` output to this action - uses: tj-actions/coverage-badge-go@v3 + uses: tj-actions/coverage-badge-go@481919ec72da287775fef015fd9011dc75a5db05 # v3 with: filename: coverage.out - name: Verify Changed files - uses: tj-actions/verify-changed-files@v20 + uses: tj-actions/verify-changed-files@a1c6acee9df209257a246f2cc6ae8cb6581c1edf # v20 id: verify-changed-files with: files: README.md @@ -49,7 +49,7 @@ jobs: - name: Push changes if: steps.verify-changed-files.outputs.files_changed == 'true' - uses: ad-m/github-push-action@master + uses: ad-m/github-push-action@7fba72704ad2db819788db8f2d9e7d1dfbebe089 # master with: github_token: ${{ github.token }} - branch: ${{ github.head_ref }} + branch: ${{ github.ref_name }} diff --git a/.github/workflows/dependabot-reviewer.yaml b/.github/workflows/dependabot-reviewer.yaml index 0c32c856..d038f457 100644 --- a/.github/workflows/dependabot-reviewer.yaml +++ b/.github/workflows/dependabot-reviewer.yaml @@ -19,11 +19,15 @@ jobs: with: github-token: "${{ secrets.GITHUB_TOKEN }}" - name: Approve PR + # Actions and base-image bumps change what runs with repo secrets: a human reviews those. + if: steps.metadata.outputs.update-type != 'version-update:semver-major' && steps.metadata.outputs.package-ecosystem == 'go_modules' run: gh pr review --approve "$PR_URL" env: PR_URL: ${{github.event.pull_request.html_url}} GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - name: Enable auto-merge for Dependabot PRs + # Actions and base-image bumps change what runs with repo secrets: a human reviews those. + if: steps.metadata.outputs.update-type != 'version-update:semver-major' && steps.metadata.outputs.package-ecosystem == 'go_modules' run: gh pr merge --auto --squash "$PR_URL" env: PR_URL: ${{github.event.pull_request.html_url}} diff --git a/.github/workflows/helm-docs.yaml b/.github/workflows/helm-docs.yaml index b2d10ab0..51572f62 100644 --- a/.github/workflows/helm-docs.yaml +++ b/.github/workflows/helm-docs.yaml @@ -21,12 +21,9 @@ jobs: contents: write pull-requests: write steps: - - uses: actions/checkout@v7.0.1 - with: - ref: ${{ github.event.pull_request.head.ref }} - repository: ${{ github.event.pull_request.head.repo.full_name }} + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Check for values.yaml changes - uses: dorny/paths-filter@v4 + uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4 id: filter with: filters: | @@ -35,7 +32,7 @@ jobs: - 'deploy/charts/version-checker/Chart.yaml' - name: Install Helm Docs if: steps.filter.outputs.values == 'true' - uses: envoy/install-helm-docs@v1.0.0 + uses: envoy/install-helm-docs@05313083ef2cfaea27c4c3d7cb725242d22ea88b # v1.0.0 with: version: 1.14.2 - name: Update Helm Docs @@ -45,7 +42,7 @@ jobs: cd deploy/charts/version-checker helm-docs - name: Check for README.md changes - uses: dorny/paths-filter@v4 + uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4 id: filter-readme with: base: HEAD @@ -62,8 +59,7 @@ jobs: git commit -m "[HELM] Update helm docs" - name: Push Changes if: steps.filter-readme.outputs.readme == 'true' - uses: ad-m/github-push-action@v1.3.0 + uses: ad-m/github-push-action@881a6320fdb16eb5318c5054f31c218aec2b324c # v1.3.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.head_ref }} - repository: ${{ github.event.pull_request.head.repo.full_name }} + branch: ${{ github.ref_name }} diff --git a/.github/workflows/helm-test.yaml b/.github/workflows/helm-test.yaml index 332ac778..f9adf879 100644 --- a/.github/workflows/helm-test.yaml +++ b/.github/workflows/helm-test.yaml @@ -25,11 +25,11 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Golang - uses: actions/setup-go@v7 + uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7 with: go-version-file: go.mod - - uses: azure/setup-helm@v5 + - uses: azure/setup-helm@2f5e7bc67f1f9972ab16657bb795f36d8f04de0e # v5 with: version: v4.2.2 @@ -43,18 +43,19 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup Golang - uses: actions/setup-go@v7 + uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7 with: go-version-file: go.mod - - uses: azure/setup-helm@v5 + - uses: azure/setup-helm@2f5e7bc67f1f9972ab16657bb795f36d8f04de0e # v5 with: version: v4.2.2 - name: Install helm Plugins run: | if [ ! -e "${HELM_PLUGINS}/helm-unittest" ]; then - helm plugin install --verify=false https://github.com/helm-unittest/helm-unittest.git + # --verify=false: git installs carry no provenance, so pin a release tag instead. + helm plugin install --verify=false https://github.com/helm-unittest/helm-unittest.git --version v1.2.1 fi - name: Run Tests @@ -73,7 +74,10 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Install Kyverno CLI - uses: kyverno/action-install-cli@v0.2.0 + uses: kyverno/action-install-cli@fcee92fca5c883169ef9927acf543e0b5fc58289 # v0.2.0 + with: + # The default (v1.10.3) cannot load policies.kyverno.io/v1 ValidatingPolicy. + release: v1.20.0 - run: |- kyverno apply -p https://github.com/kyverno/policies/pod-security-vpol/restricted --git-branch main --resource <(helm template deploy/charts/version-checker/) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0cede412..150d9326 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -21,7 +21,7 @@ jobs: outputs: name: "${{ steps.release_number.outputs.substring != '' && steps.release_number.outputs.substring || github.ref_name }}" steps: - - uses: bhowell2/github-substring-action@1.0.2 + - uses: bhowell2/github-substring-action@840a63713530fface80dec51acc55ced1d64f24a # 1.0.2 id: release_number continue-on-error: true with: @@ -45,12 +45,12 @@ jobs: fetch-depth: 0 - name: Setup Golang - uses: actions/setup-go@v7 + uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7 with: go-version-file: go.mod - name: Find and Replace Helm Chart Version - uses: jacobtomlinson/gha-find-replace@v3 + uses: jacobtomlinson/gha-find-replace@2ff30f644d2e0078fc028beb9193f5ff0dcad39e # v3 with: find: 'v(\d+)\.(\d+)\.(\d+)(-rc(\d)+)?' replace: "${{needs.release-name.outputs.name}}" @@ -58,7 +58,7 @@ jobs: regex: true - name: Find and Replace Kubernetes Manifests - uses: jacobtomlinson/gha-find-replace@v3 + uses: jacobtomlinson/gha-find-replace@2ff30f644d2e0078fc028beb9193f5ff0dcad39e # v3 with: find: 'v(\d+)\.(\d+)\.(\d+)(-rc(\d)+)?' replace: "${{needs.release-name.outputs.name}}" @@ -66,7 +66,7 @@ jobs: regex: true - name: Find and Replace Makefile versions - uses: jacobtomlinson/gha-find-replace@v3 + uses: jacobtomlinson/gha-find-replace@2ff30f644d2e0078fc028beb9193f5ff0dcad39e # v3 with: find: 'v(\d+)\.(\d+)\.(\d+)(-rc(\d)+)?' replace: "${{needs.release-name.outputs.name}}" @@ -74,7 +74,7 @@ jobs: regex: true - name: Install Helm Docs - uses: envoy/install-helm-docs@v1.0.0 + uses: envoy/install-helm-docs@05313083ef2cfaea27c4c3d7cb725242d22ea88b # v1.0.0 with: version: 1.14.2 - name: Update Helm Docs @@ -84,7 +84,7 @@ jobs: helm-docs - name: Detect any Local Changes - uses: dorny/paths-filter@v4 + uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4 id: filter with: base: HEAD @@ -97,29 +97,31 @@ jobs: - name: Commit files if: steps.filter.outputs.versions == 'true' + env: + RELEASE_NAME: ${{ needs.release-name.outputs.name }} run: | set -x git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git status - git commit -a -m "Bump versions to ${{needs.release-name.outputs.name}}" + git commit -a -m "Bump versions to ${RELEASE_NAME}" - name: Push changes if: steps.filter.outputs.versions == 'true' - uses: ad-m/github-push-action@v1.3.0 + uses: ad-m/github-push-action@881a6320fdb16eb5318c5054f31c218aec2b324c # v1.3.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: ${{ github.ref_name }} - name: Build Changelog id: github_release - uses: mikepenz/release-changelog-builder-action@v6 + uses: mikepenz/release-changelog-builder-action@b0db9d18b53447ef9f940a46c8f31653c4d9f621 # v6 with: ignorePreReleases: true toTag: "main" - name: Create Release PR - uses: devops-infra/action-pull-request@v1.4.0 + uses: devops-infra/action-pull-request@1d8aa3c4a6060a1410641f700f91353af65cc94b # v1.4.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} target_branch: main @@ -146,8 +148,7 @@ jobs: path: version-checker - name: Setup Cosign - uses: sigstore/cosign-installer@main - + uses: sigstore/cosign-installer@756fe2d284c7292c4e9b62c8a28f1e5629c59532 # main # Temporarily disabled while org auth is being sorted. # - name: checkout jetstack-charts # uses: actions/checkout@v6 @@ -158,7 +159,7 @@ jobs: # path: jetstack-charts - name: Setup Helm - uses: azure/setup-helm@v5 + uses: azure/setup-helm@2f5e7bc67f1f9972ab16657bb795f36d8f04de0e # v5 with: version: v4.2.2 @@ -173,10 +174,12 @@ jobs: helm package version-checker/deploy/charts/version-checker -d jetstack-charts/charts/ - name: Sign Helm Chart + env: + RELEASE_NAME: ${{ needs.release-name.outputs.name }} run: | cosign sign-blob -y \ - jetstack-charts/charts/version-checker-${{ needs.release-name.outputs.name }}.tgz \ - --bundle jetstack-charts/charts/version-checker-${{ needs.release-name.outputs.name }}.tgz.cosign.bundle + "jetstack-charts/charts/version-checker-${RELEASE_NAME}.tgz" \ + --bundle "jetstack-charts/charts/version-checker-${RELEASE_NAME}.tgz.cosign.bundle" # FIXME: We need a Repo Created in Quay ahead of time for this to work # - name: Push to Quay @@ -204,7 +207,7 @@ jobs: # base: main - name: Upload chart artifacts for manual publishing - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 with: name: helm-chart-${{ needs.release-name.outputs.name }} path: jetstack-charts/charts/* @@ -228,15 +231,14 @@ jobs: cosign-release: "v2.2.4" - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - + uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 with: platforms: linux/amd64,linux/arm64 - name: Login to Docker Hub - uses: docker/login-action@v4 + uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4 with: registry: quay.io username: ${{ secrets.QUAY_USERNAME }} @@ -244,7 +246,7 @@ jobs: - name: Build and push (if applicable) id: build-and-push - uses: docker/build-push-action@v7 + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 with: context: . platforms: linux/amd64,linux/arm64 @@ -261,10 +263,10 @@ jobs: if: ${{ startsWith(github.ref, 'refs/tags/') }} env: # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable - TAGS: quay.io/jetstack/version-checker:${{github.ref_name}} + REF_NAME: ${{ github.ref_name }} DIGEST: ${{ steps.build-and-push.outputs.digest }} run: |- - cosign sign --yes "quay.io/jetstack/version-checker:${{github.ref_name}}@${DIGEST}" + cosign sign --yes "quay.io/jetstack/version-checker:${REF_NAME}@${DIGEST}" github-release: name: Create/Update GitHub Release @@ -275,10 +277,10 @@ jobs: - release-name steps: - name: Create Release / Change Logs - uses: softprops/action-gh-release@v3 + uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3 with: tag_name: ${{ needs.release-name.outputs.name }} target_commitish: ${{ github.ref_name }} draft: ${{ !startsWith(github.ref, 'refs/tags/') }} - prerelease: ${{ contains('-rc', github.ref_name) || !startsWith(github.ref, 'refs/tags/') }} + prerelease: ${{ contains(github.ref_name, '-rc') || !startsWith(github.ref, 'refs/tags/') }} generate_release_notes: true diff --git a/.github/workflows/stale.yaml b/.github/workflows/stale.yaml index bd1a7aac..2957f848 100644 --- a/.github/workflows/stale.yaml +++ b/.github/workflows/stale.yaml @@ -14,7 +14,7 @@ jobs: pull-requests: write # for actions/stale to close stale PRs runs-on: 'ubuntu-latest' steps: - - uses: 'actions/stale@v11' + - uses: actions/stale@4391f3da665fdf50b6810c1a66712fb9ba21aa93 # v11 with: stale-issue-message: |- This issue has been automatically marked as stale because it has not had