fleetlint Policy for a fleet of repositories
v0.4
Getting started

release/trusted-publishing

Packages are published with trusted publishing

Severitywarning
Tiers1
Stacksany
Scoperoot
Kindexpr
Sourcelibrary v0.1.0
Selected byfleetlint-recommended@v0.1.0

Requirement

A tag-triggered workflow that publishes to npm, PyPI, crates.io or RubyGems authenticates with the registry’s trusted publishing (OIDC): on GitHub the job has id-token: write and no registry token from secrets is passed (NPM_TOKEN/NODE_AUTH_TOKEN, a pypi-publish password, TWINE_PASSWORD, UV_PUBLISH_TOKEN, CARGO_REGISTRY_TOKEN, GEM_HOST_API_KEY, --token); on GitLab the pipeline declares id_tokens:. Gitea and Forgejo workflows are not checked: the registries do not trust their 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.

Applies when

tagged_workflows().exists(w, ci_kind(w) in ["github", "gitlab"] && steps(w).exists(s,
  s.uses.matches("^(pypa/gh-action-pypi-publish|rubygems/release-gem|JS-DevTools/npm-publish|katyo/publish-crates)@")
  || s.run.matches("\\b(npm publish|pnpm publish|yarn npm publish|bun publish|twine upload|uv publish|poetry publish|flit publish|hatch publish|pdm publish|cargo publish|gem push)\\b")))

Check

For each item in:

tagged_workflows().filter(w, ci_kind(w) in ["github", "gitlab"] && steps(w).exists(s,
  s.uses.matches("^(pypa/gh-action-pypi-publish|rubygems/release-gem|JS-DevTools/npm-publish|katyo/publish-crates)@")
  || s.run.matches("\\b(npm publish|pnpm publish|yarn npm publish|bun publish|twine upload|uv publish|poetry publish|flit publish|hatch publish|pdm publish|cargo publish|gem push)\\b")))
ci_kind(item) == "gitlab"
  ? text(item).matches("(?m)^\\s*id_tokens:")
  : text(item).matches("id-token:\\s*write")
    && !steps(item).exists(s, s.uses.startsWith("pypa/gh-action-pypi-publish") && "password" in s.with)
    && !grep(item, r'^\s*-?\s*(?:NODE_AUTH_TOKEN|NPM_TOKEN|TWINE_PASSWORD|TWINE_API_KEY|UV_PUBLISH_TOKEN|UV_PUBLISH_PASSWORD|POETRY_PYPI_TOKEN_\w+|POETRY_HTTP_BASIC_PYPI_PASSWORD|FLIT_PASSWORD|HATCH_INDEX_AUTH|PDM_PUBLISH_PASSWORD|CARGO_REGISTRY_TOKEN|GEM_HOST_API_KEY)\s*:\s*["\x27]?\$\{\{\s*secrets\.(\w+)').exists(m, m.match.upperAscii() != "GITHUB_TOKEN")
    && !grep(item, r'--token[\s=]+["\x27]?\$\{\{\s*secrets\.(\w+)').exists(m, m.match.upperAscii() != "GITHUB_TOKEN")

Fix

Register the repository and workflow as a trusted publisher on the registry, grant id-token: write to the release job and delete the 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; on GitLab add id_tokens: with the registry’s audience), and tell the user to register the trusted publisher and delete the secret.

See: https://fleetlint.org/baseline/#releases, https://fleetlint.org/baseline/#security


Generated by fleetlint docs from catalog v0.1.0.