Skip to content

Commit 9aef78f

Browse files
committed
Add Temporarily Enabled Policies section
1 parent 2d88d79 commit 9aef78f

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

docs/nuget-org/trusted-publishing.md

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Trusted publishing
2+
title: Trusted Publishing
33
description: Trusted Publishing on nuget.org
44
author: etvorun
55
ms.author: evgenyt
@@ -9,51 +9,61 @@ ms.topic: conceptual
99

1010
# Trusted Publishing on nuget.org
1111

12-
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.
1313

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.
1515

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.
1917
18+
## How it works
2019

20+
Here’s the basic flow:
2121

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.
2327

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.
2529

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.
3031

31-
Currently, nuget.org supports [GitHub Actions](https://docs.github.com/actions/how-tos) as a trusted publisher.
3232

33-
## GitHub Actions
33+
## GitHub Actions Setup
3434

35-
To use Trusted Publishing with GitHub Actions:
35+
To get started:
3636

3737
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.
4141

42-
Here's a basic GitHub Actions workflow YAML example:
42+
Heres a basic example:
4343

4444
```yaml
4545
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
56-
- name: NuGet push
57-
run: dotnet nuget push artifacts/my-sdk.nupkg -k ${{steps.nuget_login.outputs.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json
46+
# Build your artifacts/my-sdk.nupkg package here
47+
48+
# Get a short-lived NuGet API key
49+
- name: NuGet login
50+
id: nuget_login
51+
uses: nuget/login@v1
52+
with:
53+
user: ${{secrets.NUGET_USER}}
54+
source: https://api.nuget.org/v3/index.json
55+
56+
# Push the package
57+
- name: NuGet push
58+
run: dotnet nuget push artifacts/my-sdk.nupkg -k ${{steps.nuget_login.outputs.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json
5859
```
5960
61+
## Temporarily Enabled Policies
62+
63+
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

Comments
 (0)