Trusted Publishing and shared workflows #179952
-
Why are you starting this discussion?Question What GitHub Actions topic or product is this about?Workflow Configuration Discussion DetailsI am setting up GitHub Actions workflows for the build and publish of a NuGet package. I want to make use of "Trusted Publishing" so that I can work with short-lived tokens and do not have to keep track of API keys. How to set this up, is described here: I did this, and if I use a straight-forward workflow, this works fine. I create a "publish.yml" workflow, and on nuget.org I register a policy for that specific repo and that specific workflow. I have a bunch of projects that are set up the same way and that require the exact same publish workflow with some configuration. So, I went ahead and setup a repo for the shared workflows and then I reference those with the "uses" syntax. After I updated my main repo to use this shared workflow, "trusted publishing" broke. I got an error when performing the "nuget/login" step. See: https://github.com/NuGet/login. The error mentions that my policy refers to my main repo, while the "login" step is coming from the repo with the shared workflows. So, my conclusion is that I need to create a policy for the workflow that contains the "nuget/login" step and the repo where that workflow file is located. I added a new policy on nuget.org and removed the original policy. However, now I get an error (401) without any explanation about what is going wrong. I have some questions regarding this:
Kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
This comment was marked as off-topic.
This comment was marked as off-topic.
-
|
Trusted Publishing currently validates the workflow and repository where the token is actually obtained. When using shared workflows from another repo, the policy on NuGet needs to match the repository that contains the nuget/login step, which can cause 401 errors if it doesn’t. There isn’t a direct way to pass a secret token safely as an output from one workflow to another due to GitHub restrictions. The most reliable approach is to keep the nuget/login step in the originating repo’s workflow and call shared workflows after obtaining the token, passing non-secret configuration or parameters only. This ensures the policy validation works and your token remains secure. |
Beta Was this translation helpful? Give feedback.
Trusted Publishing currently validates the workflow and repository where the token is actually obtained. When using shared workflows from another repo, the policy on NuGet needs to match the repository that contains the nuget/login step, which can cause 401 errors if it doesn’t.
There isn’t a direct way to pass a secret token safely as an output from one workflow to another due to GitHub restrictions. The most reliable approach is to keep the nuget/login step in the originating repo’s workflow and call shared workflows after obtaining the token, passing non-secret configuration or parameters only. This ensures the policy validation works and your token remains secure.