|
| 1 | +Protect Against Supply-Chain Attacks with Release-Age Cooldown |
| 2 | +============================================================== |
| 3 | + |
| 4 | +Fromager's release-age cooldown policy rejects package versions that were |
| 5 | +published fewer than a configured number of days ago. This protects automated |
| 6 | +builds from supply-chain attacks where a malicious version is published and |
| 7 | +immediately pulled in before it can be reviewed. |
| 8 | + |
| 9 | +How It Works |
| 10 | +------------ |
| 11 | + |
| 12 | +When a cooldown is active, any candidate whose ``upload-time`` is more recent |
| 13 | +than the cutoff (current time minus the configured minimum age) is not |
| 14 | +considered a valid option during constraint resolution. If no versions of a |
| 15 | +package satisfy both the cooldown window and any other provided constraints, |
| 16 | +resolution fails with an informative error. |
| 17 | + |
| 18 | +The cutoff timestamp is fixed at the start of each run, so all package |
| 19 | +resolutions within a single bootstrap share the same boundary. |
| 20 | + |
| 21 | +Enabling the Cooldown |
| 22 | +--------------------- |
| 23 | + |
| 24 | +Use the global ``--min-release-age`` flag, or set the equivalent environment |
| 25 | +variable ``FROMAGER_MIN_RELEASE_AGE``: |
| 26 | + |
| 27 | +.. code-block:: bash |
| 28 | +
|
| 29 | + # Reject versions published in the last 7 days |
| 30 | + fromager --min-release-age 7 bootstrap -r requirements.txt |
| 31 | +
|
| 32 | + # Same, via environment variable (useful for CI and builder integrations) |
| 33 | + FROMAGER_MIN_RELEASE_AGE=7 fromager bootstrap -r requirements.txt |
| 34 | +
|
| 35 | + # Disable the cooldown (default) |
| 36 | + fromager --min-release-age 0 bootstrap -r requirements.txt |
| 37 | +
|
| 38 | +The ``--min-release-age`` flag accepts a non-negative integer number of days. |
| 39 | +A value of ``0`` (the default) disables the check entirely. |
| 40 | + |
| 41 | +Scope |
| 42 | +----- |
| 43 | + |
| 44 | +The cooldown applies to **sdist resolution** — selecting which version of a |
| 45 | +package to build from source, including transitive dependencies. It does not |
| 46 | +apply to: |
| 47 | + |
| 48 | +* Wheel-only lookups, including cache servers (``--cache-wheel-server-url``) and |
| 49 | + packages configured as ``pre_built: true`` in variant settings. These use a |
| 50 | + different trust model and are not subject to the cooldown regardless of which |
| 51 | + server they are fetched from. |
| 52 | +* Packages resolved from Git URLs that do not provide timestamp metadata. |
| 53 | + |
| 54 | +Note that sdist resolution from a private package index depends on |
| 55 | +``upload-time`` being present in the index's PEP 691 JSON responses. If the |
| 56 | +index does not provide that metadata, candidates will be rejected under the |
| 57 | +fail-closed policy described below. |
| 58 | + |
| 59 | + |
| 60 | +Fail-Closed Behavior |
| 61 | +-------------------- |
| 62 | + |
| 63 | +If a candidate has no ``upload-time`` metadata — which can occur with older |
| 64 | +PyPI Simple HTML responses — it is rejected when a cooldown is active. Fromager |
| 65 | +uses the `PEP 691 JSON Simple API`_ when fetching package metadata, which |
| 66 | +reliably includes upload timestamps. |
| 67 | + |
| 68 | +.. _PEP 691 JSON Simple API: https://peps.python.org/pep-0691/ |
| 69 | + |
| 70 | +Example |
| 71 | +------- |
| 72 | + |
| 73 | +Given a package ``example-pkg`` with three available versions: |
| 74 | + |
| 75 | +* ``2.0.0`` — published 3 days ago |
| 76 | +* ``1.9.0`` — published 45 days ago |
| 77 | +* ``1.8.0`` — published 120 days ago |
| 78 | + |
| 79 | +With a 7-day cooldown, ``2.0.0`` is blocked and ``1.9.0`` is selected: |
| 80 | + |
| 81 | +.. code-block:: bash |
| 82 | +
|
| 83 | + fromager --min-release-age 7 bootstrap example-pkg |
| 84 | +
|
| 85 | +With a 60-day cooldown, both ``2.0.0`` and ``1.9.0`` are blocked and ``1.8.0`` |
| 86 | +is selected: |
| 87 | + |
| 88 | +.. code-block:: bash |
| 89 | +
|
| 90 | + fromager --min-release-age 60 bootstrap example-pkg |
| 91 | +
|
| 92 | +Per-Package Override |
| 93 | +-------------------- |
| 94 | + |
| 95 | +The cooldown can be adjusted on a per-package basis using the |
| 96 | +``resolver_dist.min_release_age`` setting in the package's settings file: |
| 97 | + |
| 98 | +.. code-block:: yaml |
| 99 | +
|
| 100 | + # overrides/settings/my-package.yaml |
| 101 | + resolver_dist: |
| 102 | + min_release_age: 0 # disable cooldown for this package |
| 103 | + # min_release_age: 30 # or use a different number of days |
| 104 | +
|
| 105 | +Valid values: |
| 106 | + |
| 107 | +* Omit the key (default): inherit the global ``--min-release-age`` setting. |
| 108 | +* ``0``: disable the cooldown for this package, regardless of the global flag. |
| 109 | +* Positive integer: use this many days instead of the global setting. |
| 110 | + |
| 111 | +This is useful when a specific package is trusted enough to allow recent |
| 112 | +versions, or when a package's release cadence makes the global cooldown |
| 113 | +impractical. |
0 commit comments