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 way to publish your Rust crates from GitHub Actions without manually managing API tokens.
7
+
It uses OpenID Connect (OIDC) to verify that your workflow is running from your repository, then provides a short-lived token for publishing.
8
+
</p>
9
+
10
+
<p>
11
+
Instead of storing long-lived API tokens in your repository secrets, Trusted Publishing allows GitHub Actions to authenticate
12
+
directly with crates.io using cryptographically signed tokens that prove the workflow's identity.
13
+
</p>
14
+
15
+
<p>
16
+
<strong>Note:</strong> crates.io currently only supports GitHub Actions, but we are planning to support other
17
+
CI/CD platforms like GitLab CI/CD in the future.
18
+
</p>
19
+
20
+
<h3>Security Benefits</h3>
21
+
<ul>
22
+
<li><strong>No long-lived API tokens</strong> to manage or rotate</li>
23
+
<li><strong>Tokens automatically expire</strong> after 30 minutes</li>
24
+
<li><strong>Repository and workflow verification</strong> prevents unauthorized publishing</li>
25
+
<li><strong>OIDC-based cryptographic verification</strong> with GitHub's public JWKS</li>
26
+
<li><strong>Optional GitHub Actions environments</strong> for additional access controls</li>
27
+
</ul>
28
+
29
+
<h2>Quick Start</h2>
30
+
<p>Follow these steps to set up Trusted Publishing for your crate:</p>
31
+
32
+
<ol>
33
+
<li><strong>Configure your crate for Trusted Publishing</strong> in the crates.io settings</li>
34
+
<li><strong>Set up your GitHub Actions workflow</strong> with the required permissions and authentication action</li>
35
+
<li><strong>Publish your crate</strong> using the automated workflow</li>
36
+
</ol>
37
+
38
+
<h3>Prerequisites</h3>
39
+
<ul>
40
+
<li>Your crate must already be published to crates.io (initial publish requires an API token)</li>
41
+
<li>You must be an owner of the crate on crates.io</li>
42
+
<li>Your repository must be on GitHub</li>
43
+
</ul>
44
+
45
+
<h2>Configuring Trusted Publishing</h2>
46
+
<p>
47
+
Configure your crate on crates.io:
48
+
</p>
49
+
50
+
<ol>
51
+
<li>Go to your crate's Settings → Trusted Publishing</li>
52
+
<li>Click "Add Trusted Publisher" and fill in:
53
+
<ul>
54
+
<li><strong>Repository owner:</strong> Your GitHub username or organization</li>
55
+
<li><strong>Repository name:</strong> The name of your repository</li>
56
+
<li><strong>Workflow filename:</strong> The filename of your GitHub Actions workflow (e.g., "release.yml")</li>
57
+
<li><strong>Environment:</strong> Optional environment name if you're using GitHub environments</li>
58
+
</ul>
59
+
</li>
60
+
<li>Save the configuration</li>
61
+
</ol>
62
+
63
+
<h2>GitHub Actions Setup</h2>
64
+
<p>
65
+
Create a workflow file at <code>.github/workflows/release.yml</code>. This example workflow will automatically publish your crate each time you push a version tag (like <code>v1.0.0</code>):
<strong>Optional:</strong> For enhanced security, create a GitHub Actions environment named "release"
90
+
in your repository settings with protection rules like required reviewers or deployment branches.
91
+
</p>
92
+
93
+
<h2>Security & Best Practices</h2>
94
+
<ul>
95
+
<li><strong>Use specific workflow filenames</strong> to reduce the attack surface</li>
96
+
<li><strong>Use GitHub Actions environments</strong> with protection rules for sensitive publishing</li>
97
+
<li><strong>Limit workflow triggers</strong> to specific tags or protected branches</li>
98
+
<li><strong>Review all actions used</strong> in your release workflow</li>
99
+
<li><strong>Monitor publishing activities</strong> through crates.io email notifications</li>
100
+
</ul>
101
+
102
+
<p>
103
+
<strong>How it works:</strong> GitHub Actions generates an OIDC token that proves your workflow's identity.
104
+
The <code>rust-lang/crates-io-auth-action</code> exchanges this for a 30-minute access token that
105
+
<code>cargo publish</code> uses automatically.
106
+
</p>
107
+
108
+
<h2>Migration from API Tokens</h2>
109
+
<p>
110
+
To migrate from API tokens: set up Trusted Publishing following the steps above, test it,
111
+
then remove the API token from your repository secrets. Both methods can be used simultaneously during transition.
112
+
</p>
113
+
114
+
<h2>Additional Resources</h2>
115
+
<ul>
116
+
<li><ahref="https://rust-lang.github.io/rfcs/3691-trusted-publishing-cratesio.html">RFC 3691: Trusted Publishing for crates.io</a></li>
117
+
<li><ahref="https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect">GitHub: About security hardening with OpenID Connect</a></li>
118
+
<li><ahref="https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment">GitHub: Using environments for deployment</a></li>
0 commit comments