Skip to content

Publish to nuget.org through trusted publishing - #1

Open
wasabii wants to merge 1 commit into
mainfrom
nuget-trusted-publishing
Open

wasabii wants to merge 1 commit into
mainfrom
nuget-trusted-publishing

Conversation

@wasabii

@wasabii wasabii commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Why

The release job pushes to nuget.org with NUGET_TOKEN, a long-lived API key that the ikvmnet repositories share as an organization secret. On 2026-11-03 it expired, and the ikvm-bytecode 9.4.1 release failed with a 403 until the key was renewed. It will expire again, and when it does, every repository's next release fails the same way.

What

The same change as ikvmnet/ikvm-bytecode#7:

  • The release job gets a short-lived nuget.org key from NuGet/login@v1 just before pushing. The action trades the job's GitHub OIDC token for a key that is valid for an hour, provided the token matches a trusted publishing policy on nuget.org.
  • The login's user comes from a new NUGET_USER secret: the nuget.org username of the account that created the policy. nuget.org refuses an organization name there.
  • The job grants id-token: write. Naming any permission drops the rest, so it also names contents: write for the release and packages: write for the GitHub Packages push.

Before the next release

  • Add a NUGET_USER secret to the organization, available to this repository, holding the nuget.org username (not the email address) of the account that creates the policy. One organization secret covers every repository that makes this change.
  • Add a trusted publishing policy on nuget.org (your username menu → Trusted Publishing), owned by ikvm-revived, with repository owner ikvmnet, repository ikvm-reference-assemblies, workflow IKVM.ReferenceAssemblies.yml and no environment. If it ever names an environment, the release job needs a matching environment:.

Testing

This PR's run only checks that the workflow file is valid. The release job doesn't run for pull requests, and after merging it logs in to nuget.org only for a release tag, so the first release after this merges is the first real test.

The release job pushed to nuget.org with NUGET_TOKEN, a long-lived API
key that the ikvmnet repositories share as an organization secret. It
expired on 2026-11-03 and failed an ikvm-bytecode release until it was
renewed, and it will expire again.

The job now gets a short-lived key from NuGet/login, which trades the
job's GitHub OIDC token for a key valid for an hour, checked against
the trusted publishing policy on nuget.org. The login needs the
nuget.org username of the account that created that policy, which it
reads from the NUGET_USER secret.

Granting id-token drops every permission the job does not name, so
contents and packages are named too, for the release and the GitHub
Packages push.
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.

1 participant