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

release/trusted-publishing/nuget

Packages are published with trusted publishing

Implements release/trusted-publishing for the nuget artifact: it runs when the release publishes one (see artifacts).

Severitywarning
Tiers1
Artifactnuget
Scoperoot
Kindexpr
Sourcelibrary v0.3.1
Selected byfleetlint-recommended@v0.3.1

Requirement

A GitHub or GitLab workflow that pushes to nuget.org uses trusted publishing: id-token: write, the key from NuGet/login, and no NUGET_API_KEY or --api-key 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() > 0

Applies when

artifact_workflows("nuget").filter(w, ci_kind(w) in ["github", "gitlab"]).size() > 0

Check

For each item in:

artifact_workflows("nuget").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*(?:NUGET_API_KEY|NUGET_AUTH_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 nuget.org, take the key from NuGet/login in a job with id-token: write, and delete the NUGET_API_KEY 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.

See: https://fleetlint.org/baseline/#releases, https://fleetlint.org/baseline/#security, https://learn.microsoft.com/nuget/nuget-org/trusted-publishing


Generated by fleetlint docs from catalog v0.3.1.