From 95d25aece7edb7580dce6a613c03672bc510d963 Mon Sep 17 00:00:00 2001 From: gauron99 Date: Thu, 12 Nov 2026 00:51:30 +0100 Subject: [PATCH 1/2] ci: pin GitHub Actions and Poetry Pin every action to a commit SHA, with its version in a comment, and let Dependabot update both. pypa/gh-action-pypi-publish moves from its release/v1 branch to v1.14.3. The knative-*.yaml workflows stay at knative/actions@main, since knobots syncs them. Install Poetry 2.5.1 from .github/requirements.txt, which Dependabot now watches, instead of the newest release. publish.yaml builds with "poetry build" on Python 3.12 (same wheel and sdist as before), and ci.yaml runs the same build, so a Poetry update that breaks it fails the pull request. --- .github/dependabot.yml | 4 +++- .github/requirements.txt | 2 ++ .github/workflows/ci.yaml | 11 ++++++++--- .github/workflows/publish.yaml | 33 ++++++++++++++++----------------- 4 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 .github/requirements.txt diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 889e75eb..5f44fd12 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,7 +4,9 @@ version: 2 updates: - package-ecosystem: "pip" - directory: "/" + directories: + - "/" # pyproject.toml and poetry.lock + - "/.github" # tools the workflows install schedule: interval: "daily" assignees: diff --git a/.github/requirements.txt b/.github/requirements.txt new file mode 100644 index 00000000..ad9f2d97 --- /dev/null +++ b/.github/requirements.txt @@ -0,0 +1,2 @@ +# Tools that the workflows install. Dependabot keeps the versions current. +poetry==2.5.1 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 68da2814..f5b01879 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,14 +12,14 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up Python - uses: actions/setup-python@v7 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - pip install poetry + pip install -r .github/requirements.txt poetry install - name: Check for syntax errors run: | @@ -27,3 +27,8 @@ jobs: - name: Run tests run: | PYTHONPATH=src poetry run pytest + # publish.yaml builds the release this way, so a Poetry update that + # breaks it fails here, not in the release. + - name: Build the package + run: | + poetry build diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 77daff68..52abd1a5 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -17,21 +17,20 @@ jobs: name: Build distribution runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up Python - uses: actions/setup-python@v7 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: - python-version: "3.x" - - name: Install pypa/build - run: >- - python3 -m - pip install - build - --user + # The version ci.yaml tests "poetry build" with. + python-version: "3.12" + # Poetry requires one exact poetry-core version, so pinning Poetry also + # pins the build backend. + - name: Install Poetry + run: pip install -r .github/requirements.txt - name: Build a binary wheel and a source tarball - run: python3 -m build + run: poetry build - name: Store the distribution packages - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: python-package-distributions path: dist/ @@ -50,12 +49,12 @@ jobs: id-token: write # IMPORTANT: mandatory for trusted publishing steps: - name: Download all the dists - uses: actions/download-artifact@v8 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: python-package-distributions path: dist/ - name: Publish distribution to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 # A GitHub release will be created (and signed) for all PyPI releases. github-release: @@ -75,12 +74,12 @@ jobs: sudo apt install gh -y gh --version - name: Download all the dists - uses: actions/download-artifact@v8 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: python-package-distributions path: dist/ - name: Sign the dists with Sigstore - uses: sigstore/gh-action-sigstore-python@v3.5.0 + uses: sigstore/gh-action-sigstore-python@790bc6befb9d733738f18d8f895854b453640ec9 # v3.5.0 with: inputs: >- ./dist/*.tar.gz @@ -118,12 +117,12 @@ jobs: id-token: write # IMPORTANT: mandatory for trusted publishing steps: - name: Download all the dists - uses: actions/download-artifact@v8 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: python-package-distributions path: dist/ - name: Publish to TestPyPI - uses: pypa/gh-action-pypi-publish@release/v1 + uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 with: repository-url: https://test.pypi.org/legacy/ From 4f23d80cd2efb171dc2a710defc27d96cc79ee1c Mon Sep 17 00:00:00 2001 From: gauron99 Date: Thu, 12 Nov 2026 00:53:21 +0100 Subject: [PATCH 2/2] ci: fail pull requests that add a dependency with an OSV advisory OSV-Scanner scans the base branch and the pull request and fails when the pull request adds a dependency version with an advisory on OSV.dev, such as a known vulnerability or a malicious release. Advisories the base branch already has do not fail it, so one found in an old dependency does not block unrelated work. It runs with --no-resolve: .github/requirements.txt names only Poetry, and the scanner would otherwise guess older versions of Poetry's dependencies than pip installs and fail on their advisories. --- .github/workflows/osv-scanner.yaml | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/osv-scanner.yaml diff --git a/.github/workflows/osv-scanner.yaml b/.github/workflows/osv-scanner.yaml new file mode 100644 index 00000000..e0d5bc7d --- /dev/null +++ b/.github/workflows/osv-scanner.yaml @@ -0,0 +1,31 @@ +# Fails a pull request that adds a dependency version that OSV.dev lists an +# advisory for, such as a known vulnerability or a malicious release. +# Advisories the base branch already has do not fail it. Prow merges only +# once all checks pass, so this also stops such a Dependabot update. +name: OSV-Scanner + +on: + pull_request: + branches: [ 'main', 'release-*' ] + +permissions: {} + +jobs: + scan: + # The reusable workflow asks for these, even with upload-sarif off. + permissions: + actions: read + contents: read + security-events: write + uses: google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml@32d3cd482bdadfb38b186c0ad1b031902d55d932 # v2.7.1 + with: + # Results show as pull request annotations and in the job's artifacts. + # We do not want code scanning alerts. + upload-sarif: false + # .github/requirements.txt names only Poetry. Without --no-resolve the + # scanner guesses versions for Poetry's dependencies, older than the + # ones pip installs, and fails on their advisories. + scan-args: |- + --no-resolve + -r + ./