Skip to content

chore(cargo): enforce 14-day min-publish-age for crates.io deps - #183

Merged
storopoli merged 2 commits into
mainfrom
chore/cargo-min-publish-age
Sep 2, 2026
Merged

storopoli merged 2 commits into
mainfrom
chore/cargo-min-publish-age

Conversation

@storopoli

@storopoli storopoli commented Sep 2, 2026

Copy link
Copy Markdown
Member

Description

Adds a 14-day cooldown for crates.io dependencies through Cargo's new min-publish-age setting (RFC 3923), in a root .cargo/config.toml:

[unstable]
min-publish-age = true

[registry]
global-min-publish-age = "14 days"

Dependabot already waits 14 days before proposing a bump. This makes plain cargo add, cargo update, and hand-edited version requirements follow the same rule, so a freshly published (and possibly compromised) release can't slip in through a developer's PR. Versions already in Cargo.lock are left alone. For an urgent fix there is a one-off escape hatch:

CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow cargo update -p <crate>

This repo pins a nightly that already has the feature, so the cooldown is active right away for anyone building with the repo toolchain.

Tracking: STR-3852.

Update: a follow-up commit also sets [resolver] incompatible-publish-age = "deny". That is cargo's default, but spelling it out in the repo config means a developer with allow in their user-level ~/.cargo/config.toml no longer switches the cooldown off here. The CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow escape hatch still works, since environment variables take precedence over both. Robin's suggestion from the Slack thread.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature/Enhancement (non-breaking change which adds functionality or enhances an existing one)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor
  • New or updated tests
  • Dependency Update

Notes to Reviewers

One gap worth knowing about: versions already in Cargo.lock are exempt by design, so a lockfile produced with the override still passes cargo build --locked in CI. If we want CI to catch that, cargo update --dry-run prints a Downgrading line for every locked version that violates the policy and can be turned into a check. That is out of scope for this PR.

The [unstable] table is temporary. Stable cargo ignores it, and nightly cargo needs it until the feature reaches stable in Rust 1.100 (2026-11-12). After that it can be dropped.

Verified locally with cargo update --dry-run --workspace:

Locking 0 packages to latest Rust 1.98.0-nightly compatible versions
note: pass `--verbose` to see 101 unchanged dependencies behind latest
warning: not updating lockfile due to dry run
Unusual: this Cargo build accepts both settings but omits the expected “as of 14 days ago” suffix. There were no `Downgrading` lines. No existing Cargo config or odd CI working directories were found, and `Cargo.lock` remains unchanged.

AI disclosure: the change and this PR body were produced with Claude Code and Codex, then reviewed and tested by me.

Is this PR addressing any specification, design doc or external reference document?

  • Yes
  • No

If yes, please add relevant links:

Checklist

  • I have performed a self-review of my code.
  • I have commented my code where necessary.
  • I have updated the documentation if needed.
  • My changes do not introduce new warnings.
  • I have added (where necessary) tests that prove my changes are effective or that my feature works.
  • New and existing tests pass with my changes.
  • I have disclosed my use of AI in the body of this PR.

Related Issues

STR-3852

This prevents the resolver from selecting crates.io releases published within the last 14 days unless they are already locked. It matches the organization’s Dependabot cooldown. The [unstable] table is temporary until Rust 1.100.
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

🔒 AI Security Review (claude-opus-5)

✅ No security issues found.

@robin-alpen robin-alpen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @storopoli !

deny is cargo's default, but a user-level ~/.cargo/config.toml with
"allow" would otherwise switch the cooldown off for this repo. The repo
config wins over the home config, while the
CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE environment variable still
overrides both for one-off updates. Suggested by Robin.
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

🔒 AI Security Review (claude-opus-5)

✅ No security issues found.

@storopoli
storopoli merged commit 627b399 into main Sep 2, 2026
10 checks passed
@storopoli
storopoli deleted the chore/cargo-min-publish-age branch September 2, 2026 22:27

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 73edae1ba4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .cargo/config.toml
Comment on lines +9 to +13
[unstable]
min-publish-age = true

[registry]
global-min-publish-age = "14 days"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the pinned Cargo before enabling this policy

The workspace still pins nightly-2026-07-01 in rust-toolchain.toml, whose Cargo predates the min-publish-age implementation. Cargo silently accepts unknown entries under [registry], so this setting is inert with the repository toolchain and cargo update can still resolve a freshly published crate; the missing expected age suffix in the recorded dry run is consistent with that. Bump the pinned nightly to a release containing the feature (or defer this config) before relying on it as a supply-chain control.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants