ci: migrate NuGet publish to trusted publishing (OIDC)#440
Merged
Conversation
Replace long-lived NUGET_API_KEY secret with short-lived OIDC token via NuGet/login@v1. Adds id-token: write permission and NUGET_USER secret reference to the deploy job.
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates the NuGet publish in the Deploy.yml workflow from a long-lived API key secret to NuGet trusted publishing via GitHub OIDC, using NuGet/login@v1 to mint a short-lived NuGet API key at publish time.
Changes:
- Adds
id-token: writejob permissions required for OIDC token issuance. - Adds a
NuGet/login@v1step and switchesdotnet nuget pushto use the minted API key output. - Updates the deploy job’s token permissions to an explicit minimal set.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
71
to
74
| $tagVersion = "${{ github.ref }}".substring(11) | ||
| echo "TAG_VERSION=$tagVersion" >> $env:GITHUB_OUTPUT | ||
| dotnet nuget push IntelliTect.Analyzers.$tagVersion.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate | ||
| dotnet nuget push IntelliTect.Analyzers.$tagVersion.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --skip-duplicate | ||
| id: tag-version |
When an explicit permissions block is set, unlisted permissions default to none. actions: read is required for actions/download-artifact.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates the NuGet publish step in
Deploy.ymlfrom a long-livedNUGET_API_KEYsecret to OIDC-based trusted publishing viaNuGet/login@v1.Changes
permissions: id-token: writeto thedeployjob (required for OIDC token issuance)NuGet/login@v1step to exchange the OIDC token for a short-lived NuGet API keysecrets.NUGET_API_KEYwithsteps.login.outputs.NUGET_API_KEYin the push stepnuget.org Setup (already done)
A trusted publishing policy has been created on nuget.org for
IntelliTect.Analyzers:Deploy.ymlProductionRequired Action Before Merging
Add a
NUGET_USERsecret to the Production GitHub environment:NUGET_USERIntelliTect-NugetaccountAfter First Successful Publish
Once a release triggers a successful publish via OIDC, the old
NUGET_API_KEYsecret can be removed from the repository secrets.