release/trusted-publishing/crate
Packages are published with trusted publishing
Implements release/trusted-publishing for the crate artifact: it runs when the release publishes one (see artifacts).
| Severity | warning |
| Tiers | 1 |
| Artifact | crate |
| Scope | root |
| Kind | expr |
| Source | library v0.4.0 |
| Selected by | fleetlint-recommended@v0.4.0 |
Requirement
A GitHub or GitLab workflow that publishes to crates.io (cargo publish, katyo/publish-crates) uses trusted publishing (rust-lang/crates-io-auth-action with id-token: write) and no CARGO_REGISTRY_TOKEN or --token from secrets; on GitLab id_tokens:.
Why
A registry token in CI secrets is valid for months and publishes from anywhere once leaked; an OIDC token is minted per run, scoped to this repository and workflow, and expires in minutes.
Capability applies when
repo.artifacts.size() > 0Applies when
artifact_workflows("crate").filter(w, ci_kind(w) in ["github", "gitlab"]).size() > 0Check
For each item in:
artifact_workflows("crate").filter(w, ci_kind(w) in ["github", "gitlab"])ci_kind(item) == "gitlab"
? text(item).matches("(?m)^\\s*id_tokens:")
: text(item).matches("id-token:\\s*write")
&& !grep(item, r'^\s*-?\s*(?:CARGO_REGISTRY_TOKEN)\s*:\s*["\x27]?\$\{\{\s*secrets\.(\w+)').exists(m, m.match.upperAscii() != "GITHUB_TOKEN")
&& !grep(item, r'--(?:token|api-key)[\s=]+["\x27]?\$\{\{\s*secrets\.(\w+)').exists(m, m.match.upperAscii() != "GITHUB_TOKEN")Fix
Register the workflow as a trusted publisher on crates.io, get the token from rust-lang/crates-io-auth-action in a job with id-token: write, and delete the CARGO_REGISTRY_TOKEN secret.
Agent instruction: Grant id-token: write on the publishing job, remove the registry token from env/with (pypa/gh-action-pypi-publish without password, npm publish with npm 11.5.1 or newer, rust-lang/crates-io-auth-action for cargo, rubygems/release-gem for gems, NuGet/login for nuget.org, dart-lang/setup-dart for pub.dev; on GitLab add id_tokens: with the registry’s audience), and tell the user to register the trusted publisher and delete the secret.
Sources
- https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect (guidance)
- https://docs.gitlab.com/ci/secrets/id_token_authentication/ (spec, id_tokens)
- https://fleetlint.org/baseline/#releases (convention)
- https://fleetlint.org/baseline/#security
- https://github.com/rust-lang/crates-io-auth-action (spec)
Generated by fleetlint docs from catalog v0.4.0.