Description
We currently publish NuGet packages using a static NUGET_API_KEY. We need to migrate this process to use NuGet.org's trusted publishing feature (OIDC). This method enhances security by eliminating the need to store long-lived API keys.
This migration is split into two parts: Part 1 updates the workflow file and can be merged immediately. Part 2 involves configuring NuGet.org and should be done right before the next release to avoid any token/trust expiration issues.
Official Documentation:
Part 1: Prepare Workflow and Secrets (Can be done now)
This part updates the repository's workflow file to use OIDC and adds the necessary secret, preparing the file for the switch. It won't break the current NUGET_API_KEY publishing yet.
1. Configure Repository Secret
2. Update publish-nuget.yml
Part 2: Go-Live at Next Release (Do all at once)
Perform these steps when you are ready to publish the next package version and fully switch to Trusted Publishing.
1. Configure nuget.org Trusted Publisher
2. Trigger Publish & Verify
3. Cleanup (If organization doesn't use NUGET_API_KEY anywhere anymore)
Description
We currently publish NuGet packages using a static
NUGET_API_KEY. We need to migrate this process to use NuGet.org's trusted publishing feature (OIDC). This method enhances security by eliminating the need to store long-lived API keys.This migration is split into two parts: Part 1 updates the workflow file and can be merged immediately. Part 2 involves configuring NuGet.org and should be done right before the next release to avoid any token/trust expiration issues.
Official Documentation:
Part 1: Prepare Workflow and Secrets (Can be done now)
This part updates the repository's workflow file to use OIDC and adds the necessary secret, preparing the file for the switch. It won't break the current
NUGET_API_KEYpublishing yet.1. Configure Repository Secret
NUGET_USER2. Update
publish-nuget.ymlIn
.github/workflows/publish-nuget.yml, find thepublishjob.Add the
permissionsblock to thepublishjob (this is required for OIDC token issuance):Add a new step that uses the
NuGet/login@v1action to exchange the OIDC token for a temporary API key. Place this step before the "Publish to NuGet" step:Update the "Publish to NuGet" step to remove the static
secrets.NUGET_API_KEYand use the temporary key generated by theNuGet/loginstep:Before:
After:
Merge these changes into the main branch. The workflow will still use the old static key if present, or it will now be prepared for the OIDC switch.
Part 2: Go-Live at Next Release (Do all at once)
Perform these steps when you are ready to publish the next package version and fully switch to Trusted Publishing.
1. Configure nuget.org Trusted Publisher
ByteAetherUlidpublish-nuget.yml2. Trigger Publish & Verify
workflow_dispatch).3. Cleanup (If organization doesn't use
NUGET_API_KEYanywhere anymore)NUGET_API_KEYrepository secret. Do not deleteNUGET_USER.