|
| 1 | +name: Audit dependencies |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +# Global environment variables applied to all steps |
| 7 | +env: |
| 8 | + UV_VERSION: "0.11.21" |
| 9 | + UV_PREVIEW: "1" # Enables the preview uv audit and malware engines |
| 10 | + UV_MALWARE_CHECK: "1" # Automatically blocks malicious installs on sync/run |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: |
| 15 | + - main |
| 16 | + pull_request: |
| 17 | + merge_group: |
| 18 | + workflow_dispatch: |
| 19 | + |
| 20 | +jobs: |
| 21 | + security-check: |
| 22 | + name: Validate Dependencies |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Check out repository |
| 27 | + uses: actions/checkout@v7 |
| 28 | + with: |
| 29 | + # Full history so we can diff against a base ref to see whether the |
| 30 | + # resolved dependency set changed (see "Detect dependency changes"). |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + # Pin uv to a known-good, recent release. |
| 34 | + - name: Install uv and setup uv caching |
| 35 | + uses: astral-sh/setup-uv@v9.0.0 |
| 36 | + with: |
| 37 | + version: ${{ env.UV_VERSION }} |
| 38 | + enable-cache: true |
| 39 | + |
| 40 | + - name: Set up Python |
| 41 | + uses: actions/setup-python@v7.0.0 |
| 42 | + id: setup-python |
| 43 | + with: |
| 44 | + python-version: 3.13 |
| 45 | + |
| 46 | + # The CVE audit reflects the state of the *upstream advisory database*, |
| 47 | + # not the change under test: a newly-published advisory against an |
| 48 | + # already-pinned package would otherwise turn every open PR — and the next |
| 49 | + # innocent merge to main — red, regardless of whether it touched deps. |
| 50 | + # |
| 51 | + # So gate the audit on whether the change actually altered dependencies, |
| 52 | + # relative to each event's natural base: |
| 53 | + # * pull_request -> the PR base |
| 54 | + # * push (main) -> the commit before the push (github.event.before) |
| 55 | + # * merge_group -> the queue base |
| 56 | + # * otherwise (workflow_dispatch, first/force push) -> audit |
| 57 | + # |
| 58 | + # A pyproject.toml change is always a real dependency change. uv.lock is |
| 59 | + # regenerated non-deterministically, so a textual change there is only |
| 60 | + # treated as real if the resolved (name, version) set actually differs. |
| 61 | + - name: Detect dependency changes |
| 62 | + id: deps |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + set -euo pipefail |
| 66 | + case "${{ github.event_name }}" in |
| 67 | + pull_request) base="${{ github.event.pull_request.base.sha }}" ;; |
| 68 | + merge_group) base="${{ github.event.merge_group.base_sha }}" ;; |
| 69 | + push) base="${{ github.event.before }}" ;; |
| 70 | + *) base="" ;; |
| 71 | + esac |
| 72 | +
|
| 73 | + zero="0000000000000000000000000000000000000000" |
| 74 | + if [ -z "$base" ] || [ "$base" = "$zero" ] || ! git cat-file -e "$base^{commit}" 2>/dev/null; then |
| 75 | + echo "No comparable base ref for '${{ github.event_name }}'; auditing." |
| 76 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 77 | + exit 0 |
| 78 | + fi |
| 79 | +
|
| 80 | + changed_files="$(git diff --name-only "$base...HEAD")" |
| 81 | +
|
| 82 | + if grep -qE '(^|/)pyproject\.toml$' <<<"$changed_files"; then |
| 83 | + echo "pyproject.toml changed; auditing." |
| 84 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 85 | + elif grep -qE '(^|/)uv\.lock$' <<<"$changed_files"; then |
| 86 | + changed="$(python3 .github/scripts/uv_lock_deps_changed.py "$base")" |
| 87 | + if [ "$changed" = "true" ]; then |
| 88 | + echo "uv.lock resolved dependency set changed; auditing." |
| 89 | + else |
| 90 | + echo "uv.lock changed but the resolved dependency set is identical; skipping audit." |
| 91 | + fi |
| 92 | + echo "changed=$changed" >> "$GITHUB_OUTPUT" |
| 93 | + else |
| 94 | + echo "No dependency files changed; skipping audit." |
| 95 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 96 | + fi |
| 97 | +
|
| 98 | + # Step 1: Run uv audit to check for vulnerabilities (CVEs) |
| 99 | + # |
| 100 | + # GHSA-6w46-j5rx-g56g (pytest predictable tmpdir path) is fixed only in |
| 101 | + # pytest 9.0.3, but pytest 9 removed the private _pytest.assertion.util |
| 102 | + # ._diff_text API that tests/conftest.py depends on. We pin pytest <9 |
| 103 | + # (see packages/linkml/pyproject.toml) and ignore this single test-only, |
| 104 | + # low-risk advisory until conftest is migrated to stdlib difflib. |
| 105 | + - name: Audit lockfile for CVEs |
| 106 | + if: steps.deps.outputs.changed == 'true' |
| 107 | + run: uv audit --ignore GHSA-6w46-j5rx-g56g |
| 108 | + |
| 109 | + # Step 2: Run a sync. If a package contains known malware, |
| 110 | + # the OSV-lookup triggers an immediate, non-zero failure exit. |
| 111 | + # |
| 112 | + # NOTE: The malware gate only blocks malware that has *already* been |
| 113 | + # published as an OSV advisory. There is a window between a malicious |
| 114 | + # upload and its advisory. That gap is covered by uv's dependency |
| 115 | + # cooldown (`exclude-newer`, a resolution-time setting added in uv |
| 116 | + # 0.9.17), which is enabled with a 7-day window in the root pyproject.toml: |
| 117 | + # |
| 118 | + # [tool.uv] |
| 119 | + # exclude-newer = "7 days" |
| 120 | + # |
| 121 | + - name: Verify Environment Sync (Anti-Malware Gate) |
| 122 | + run: uv sync --frozen --all-groups |
0 commit comments