Skip to content

Commit 0d6ad3e

Browse files
authored
ci: add 2-day package install cooldown (supply-chain guard) (1/n) (#21722)
* ci: add 2-day install cooldown via UV_EXCLUDE_NEWER / PIP_UPLOADED_PRIOR_TO Workflow-level supply-chain guard: when CI installs Python packages, the resolver refuses any PyPI release published within the last 2 days. Catches typosquats and malicious uploads that get yanked within ~24h before they land in our CI image. - uv-based workflows (ci-tests-*, code-checks, docs-build, _legacy-checkpoints): UV_EXCLUDE_NEWER="2 days". Requires uv >= 0.10.0; setup-uv@v7 pulls latest uv. - pip-based workflows (ci-pkg-install, release-pkg, release-nightly): PIP_UPLOADED_PRIOR_TO="P2D" plus a pip-upgrade step. Requires pip >= 26.1.
1 parent c7eae51 commit 0d6ad3e

7 files changed

Lines changed: 33 additions & 4 deletions

File tree

.github/workflows/_legacy-checkpoints.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ on:
4444
env:
4545
LEGACY_FOLDER: "tests/legacy"
4646
TORCH_URL: "https://download.pytorch.org/whl/cpu/"
47+
# Supply-chain guard: skip PyPI releases newer than this. See https://docs.astral.sh/uv/reference/settings/#exclude-newer
48+
UV_EXCLUDE_NEWER: "2 days"
4749

4850
defaults:
4951
run:
@@ -71,12 +73,15 @@ jobs:
7173
PACKAGE_NAME: pytorch
7274
FREEZE_REQUIREMENTS: 1
7375
timeout-minutes: 20
74-
run: uv pip install . --extra-index-url="${TORCH_URL}"
76+
# `unsafe-best-match` required: PyTorch extra-index mirrors an older fsspec that
77+
# conflicts with lightning's version range under UV_EXCLUDE_NEWER.
78+
run: uv pip install . --extra-index-url="${TORCH_URL}" --index-strategy unsafe-best-match
7579
if: inputs.pl_version == ''
7680

7781
- name: Install PL version
7882
timeout-minutes: 20
79-
run: uv pip install "pytorch-lightning==${{ inputs.pl_version }}" --extra-index-url="${TORCH_URL}"
83+
# `unsafe-best-match` required: same fsspec/PyTorch-index conflict as above.
84+
run: uv pip install "pytorch-lightning==${{ inputs.pl_version }}" --extra-index-url="${TORCH_URL}" --index-strategy unsafe-best-match
8085
if: inputs.pl_version != ''
8186

8287
- name: Adjust tests -> PL

.github/workflows/ci-pkg-install.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ jobs:
4545
os: ["ubuntu-22.04", "macOS-14", "windows-2022"]
4646
pkg-name: ["fabric", "pytorch", "lightning", "notset"]
4747
python-version: ["3.10", "3.11"]
48+
env:
49+
# Supply-chain guard: skip PyPI releases newer than this (ISO 8601 duration). See https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-uploaded-prior-to
50+
PIP_UPLOADED_PRIOR_TO: "P2D"
4851
steps:
4952
- uses: actions/checkout@v6
5053
- uses: actions/setup-python@v6
5154
with:
5255
python-version: ${{ matrix.python-version }}
56+
- name: Upgrade pip (for --uploaded-prior-to, pip >= 26.1)
57+
run: python -m pip install --upgrade "pip>=26.1"
5358
- uses: actions/download-artifact@v8
5459
with:
5560
name: dist-packages-${{ github.sha }}

.github/workflows/ci-tests-fabric.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ jobs:
6868
# TODO: Remove this - Enable running MPS tests on this platform
6969
DISABLE_MPS: ${{ matrix.os == 'macOS-14' && '1' || '0' }}
7070
UV_TORCH_BACKEND: "cpu"
71+
# Supply-chain guard: skip PyPI releases newer than this. See https://docs.astral.sh/uv/reference/settings/#exclude-newer
72+
UV_EXCLUDE_NEWER: "2 days"
7173
steps:
7274
- uses: actions/checkout@v6
7375

.github/workflows/ci-tests-pytorch.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ jobs:
7373
# TODO: Remove this - Enable running MPS tests on this platform
7474
DISABLE_MPS: ${{ matrix.os == 'macOS-14' && '1' || '0' }}
7575
UV_TORCH_BACKEND: "cpu"
76+
# Supply-chain guard: skip PyPI releases newer than this. See https://docs.astral.sh/uv/reference/settings/#exclude-newer
77+
UV_EXCLUDE_NEWER: "2 days"
7678
steps:
7779
- uses: actions/checkout@v6
7880

.github/workflows/code-checks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ defaults:
2727
jobs:
2828
mypy:
2929
runs-on: ubuntu-22.04
30+
env:
31+
# Supply-chain guard: skip PyPI releases newer than this. See https://docs.astral.sh/uv/reference/settings/#exclude-newer
32+
UV_EXCLUDE_NEWER: "2 days"
3033
steps:
3134
- uses: actions/checkout@v6
3235

.github/workflows/docs-build.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ env:
4848
FREEZE_REQUIREMENTS: "1"
4949
TORCH_URL: "https://download.pytorch.org/whl/cpu/"
5050
PYPI_LOCAL_DIR: "pypi_pkgs/"
51+
# Supply-chain guard: skip PyPI releases newer than this. See https://docs.astral.sh/uv/reference/settings/#exclude-newer
52+
UV_EXCLUDE_NEWER: "2 days"
5153

5254
jobs:
5355
docs-make:
@@ -103,9 +105,15 @@ jobs:
103105
104106
- name: Install package & dependencies
105107
timeout-minutes: 20
108+
# `unsafe-best-match` lets uv consider all indexes when resolving a package,
109+
# not just the first one it's found on. Required here because the PyTorch CPU
110+
# extra-index mirrors an older `fsspec` that conflicts with `lightning[all]`'s
111+
# version range under `UV_EXCLUDE_NEWER`; without this flag uv refuses to fall
112+
# back to PyPI for a newer compatible version.
106113
run: |
107114
uv pip install .[all] -U -r requirements/${{ matrix.pkg-name }}/docs.txt \
108-
-f ${PYPI_LOCAL_DIR} --extra-index-url="${TORCH_URL}"
115+
-f ${PYPI_LOCAL_DIR} --extra-index-url="${TORCH_URL}" \
116+
--index-strategy unsafe-best-match
109117
uv pip list
110118
111119
- name: Install req. for Notebooks/tutorials
@@ -179,7 +187,7 @@ jobs:
179187
- name: Inject version selector
180188
working-directory: docs/build
181189
run: |
182-
pip install -q wget
190+
uv pip install -q wget
183191
python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/inject-selector-script.py
184192
python inject-selector-script.py html ${{ matrix.pkg-name }}
185193

.github/workflows/release-nightly.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ jobs:
2121
runs-on: ubuntu-22.04
2222
env:
2323
PKG_NAME: "lightning"
24+
# Supply-chain guard: skip PyPI releases newer than this (ISO 8601 duration). See https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-uploaded-prior-to
25+
PIP_UPLOADED_PRIOR_TO: "P2D"
2426
steps:
2527
- uses: actions/checkout@v6
2628
- uses: actions/setup-python@v6
2729
with:
2830
python-version: "3.10"
2931

32+
- name: Upgrade pip (for --uploaded-prior-to, pip >= 26.1)
33+
run: python -m pip install --upgrade "pip>=26.1"
3034
- name: Convert actual version to nightly
3135
run: |
3236
pip install -q -r .actions/requirements.txt

0 commit comments

Comments
 (0)