You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trusted Publishing is a secure and streamlined way to publish NuGet packages without needing to manage long-lived API keys. Instead, it uses short-lived credentials issued by a trusted CI/CD system like GitHub Actions.
12
+
Trusted Publishing is a better way to publish NuGet packages. You don’t need to manage long-lived API keys anymore. Instead, you use short-lived credentials issued by your CI/CD system, like GitHub Actions.
13
13
14
-
This approach improves security by reducing the risk of credential leaks and simplifies automation by eliminating the need to rotate or store API keys.
14
+
This makes your publishing process safer by reducing the risk of leaked credentials. It also makes automation easier because you don’t need to rotate or store secrets. This approach is part of a broader industry shift toward secure, keyless publishing. If you're curious, check out the OpenSSF initiative: https://repos.openssf.org/trusted-publishers-for-all-package-repositories.
15
15
16
-
To learn more about the broader industry effort behind this, check out the [OpenSSF initiative](https://repos.openssf.org/trusted-publishers-for-all-package-repositories).
17
-
18
-
> ⚠️ **Note:** If you don't see the **Trusted Publishing** option in your nuget.org account, the feature may not be available for your account yet. It will roll out gradually as the feature becomes generally available.
16
+
> ⚠️ **Heads up:** If you don’t see the **Trusted Publishing** option in your nuget.org account, it might not be available to you yet. We’re rolling it out gradually.
19
17
18
+
## How it works
20
19
20
+
Here’s the basic flow:
21
21
22
-
## How it works
22
+
1. Your CI/CD system (like GitHub Actions) runs a workflow.
23
+
2. It issues a short-lived token.
24
+
3. That token is sent to nuget.org.
25
+
4. NuGet verifies it and returns a temporary API key.
26
+
5. Your workflow uses that key to push the package.
23
27
24
-
Trusted Publishing allows nuget.org to securely integrate with your CI/CD provider.
28
+
NuGet’s temporary API keys are valid for **15 minutes**, so your workflow should request the key shortly before publishing. If you request it too early, it might expire before the push happens.
25
29
26
-
When your workflow runs, the CI/CD provider (like GitHub Actions) issues a short-lived token.
27
-
This token is sent to nuget.org, which verifies it and uses it to generate a temporary API key.
28
-
That API key is then used by the workflow to publish your package.
29
-
This approach eliminates the need to store long-lived API keys and helps keep your publishing process secure and automated.
30
+
This setup gives you a secure and automated way to publish packages, without the risks that come with long-lived secrets.
30
31
31
-
Currently, nuget.org supports [GitHub Actions](https://docs.github.com/actions/how-tos) as a trusted publisher.
32
32
33
-
## GitHub Actions
33
+
## GitHub Actions Setup
34
34
35
-
To use Trusted Publishing with GitHub Actions:
35
+
To get started:
36
36
37
37
1. Log into nuget.org.
38
-
2. Click your username in the top-right corner and select**Trusted Publishing** from the dropdown menu.
39
-
3. Add a new Trusted Publisher, specifying your GitHub organization, repository, workflow file, and other required details.
40
-
4. In GitHub, configure your GitHub Actions workflow to request a short-lived API key from nuget.org and publish your package.
38
+
2. Click your username and choose**Trusted Publishing**.
39
+
3. Add a new trusted publishing policy. You’ll need to provide your GitHub org, repo, workflow file, and few other details.
40
+
4. In your GitHub repo, update your workflow to request a short-lived API key and push your package.
41
41
42
-
Here's a basic GitHub Actions workflow YAML example:
42
+
Here’s a basic example:
43
43
44
44
```yaml
45
45
steps:
46
-
# TODO: steps to produce artifacts/my-sdk.nupkg
47
-
# Get a short-lived NuGet API key to use for package publishing
48
-
- name: NuGet login
49
-
id: nuget_login
50
-
uses: nuget/login@v1
51
-
with:
52
-
user: ${{secrets.NUGET_USER}}
53
-
source: https://api.nuget.org/v3/index.json
54
-
55
-
# Use short-lived NuGet API key to publish the package
Sometimes when you create a Trusted Publishing policy, we can’t get the GitHub repository and owner IDs right away. This usually happens with private repos.
64
+
65
+
Why does that matter? Because we use those IDs to lock the policy to the original repo and owner. That helps prevent resurrection attacks. Without the IDs, someone could delete a repo, recreate it with the same name, and try to publish as if nothing changed.
66
+
67
+
If we don’t have the IDs, the policy starts out as **temporarily enabled**. You’ll see this in the UI. It works like a regular policy, but it only lasts for **7 days**.
68
+
Once you publish from that repo, we’ll grab the IDs from the GitHub token and upgrade the policy to **permanently enabled**.
69
+
If no publish happens in time, the policy is disabled. You can reset the 7-day timer at any point, even if the policy has already been disabled after the initial window expired.
0 commit comments