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
Copy file name to clipboardExpand all lines: README.md
+74-22Lines changed: 74 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,12 @@ The goals of this project are to:
17
17
- Obtain a perfect rating from [OpenSSF Scorecard](https://github.com/ossf/scorecard)
18
18
-[SLSA Level 3](https://slsa.dev) using GitHub OIDC
19
19
20
-
## Configuring git
20
+
## Configuring git for commit and tag signing
21
+
22
+
> **Info**
23
+
> Commit and tag signing is a practice that's recommended to avoid commit author spoofing
24
+
> but isn't strictly required for a secure project configuration.
25
+
> If you'd like to skip this step, you can jump ahead to [creating a GitHub repository](https://github.com/sethmlarson/secure-python-package-template/#creating-the-github-repository).
21
26
22
27
Git needs to be configured to be able to sign commits and tags. Git uses GPG for signing, so you need to
23
28
[create a GPG key](https://docs.github.com/en/authentication/managing-commit-signature-verification/generating-a-new-gpg-key)
@@ -150,26 +155,6 @@ To ssh://github.com/sethmlarson/package-name
150
155
151
156
Success! You should now see the commit and all files on your GitHub repository.
152
157
153
-
## Configuring PyPI
154
-
155
-
PyPI is increasing the minimum requirements for account security and credential management to make consuming packages on PyPI more secure. This includes [eventually requiring 2FA for all users and requiring API tokens to publish packages](https://pyfound.blogspot.com/2020/01/start-using-2fa-and-api-tokens-on-pypi.html). Instead of waiting for these best practices to become required we can opt-in to them now.
156
-
157
-
### Obtain an API token
158
-
159
-
API tokens will eventually be required for all packages to publish to PyPI.
160
-
161
-
- Upload a dummy v0.0 package under the desired package name using your PyPI username and password.
162
-
- Create an API token that is scoped to only the package
163
-
- Copy the value into your clipboard, it will be used later (see `PYPI_TOKEN`in the GitHub Environments section below)
164
-
165
-
### Opt-in to required 2FA
166
-
167
-
If you don't have 2FA enabled on PyPI already there's a section in the [PyPI Help page](https://pypi.org/help) about how to enable 2FA for your account. To make 2FA required for the new project:
168
-
169
-
- Open "Your projects" on PyPI
170
-
- Select "Manage"for the project
171
-
- Settings > Enable 2FA requirement for project
172
-
173
158
## Configuring the GitHub repository
174
159
175
160
### Dependabot
@@ -275,6 +260,73 @@ pip-compile \
275
260
users to privately submit vulnerability reports directly to the repository.
276
261
- Update the URL in the `SECURITY.md` file to the URL of your own repository.
277
262
263
+
## Configuring PyPI
264
+
265
+
PyPI is increasing the minimum requirements for account security and credential management to make consuming packages on PyPI more secure. This includes [eventually requiring 2FA for all users and requiring API tokens to publish packages](https://pyfound.blogspot.com/2020/01/start-using-2fa-and-api-tokens-on-pypi.html). Instead of waiting for these best practices to become required we can opt-in to them now.
266
+
267
+
### Opt-in to required 2FA
268
+
269
+
If you don't have 2FA enabled on PyPI already there's a section in the [PyPI Help page](https://pypi.org/help) about how to enable 2FA for your account. To make 2FA required for the new project:
270
+
271
+
- Open "Your projects" on PyPI
272
+
- Select "Manage"for the project
273
+
- Settings > Enable 2FA requirement for project
274
+
275
+
### Configuring a Trusted Publisher
276
+
277
+
If your project is hosted on GitHub you can take advantage of a new PyPI feature called "[Trusted Publishers](https://docs.pypi.org/trusted-publishers/)".
278
+
It's recommended to use a Trusted Publisher over an API key or password because it provides an additional layer of security
279
+
by requiring the package to originate from a pre-configured GitHub repository, workflow, and environment.
280
+
281
+
There's a [short guide on how to add a Trusted Publisher to the project](https://docs.pypi.org/trusted-publishers/adding-a-publisher/).
282
+
Below is an example of how to map the publishing GitHub Workflow definition to the PyPI Trusted Publisher.
283
+
284
+
>**Warning**
285
+
> Care should be taken that the publishing workflow can only be triggered
286
+
> by the GitHub accounts that you intend. Remember that git tags (without Protected Tags enabled)
287
+
> only require write access to the repository. This is why GitHub Environments with
288
+
> a set of required reviewers is highly recommended to have an explicit list of
289
+
> people who are allowed to completely execute the publish job.
290
+
291
+
Configuring the Trusted Publisher requires 4 values:
292
+
293
+
- GitHub repository owner
294
+
- GitHub repository name
295
+
- GitHub workflow filename
296
+
- GitHub environment name (optional, but highly recommended!)
297
+
298
+
Using this repository ([https://github.com/sethmlarson/secure-python-package-template](https://github.com/sethmlarson/secure-python-package-template)) as an example, the values to set up a Trusted Publisher would be:
0 commit comments