Skip to content

Commit bfaca7a

Browse files
committed
Fix: more images and removing todos
1 parent 47c930e commit bfaca7a

File tree

8 files changed

+53
-13
lines changed

8 files changed

+53
-13
lines changed

_posts/2024-12-13-python-packaging-security.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ last_modified: 2024-12-19
1818

1919
## Is your PyPI publication workflow secure?
2020

21-
We can learn a lot from the recent Python package breach [involving Ultralytics](https://blog.pypi.org/posts/2024-12-11-ultralytics-attack-analysis/). This breach highlighted our need to use more secure PyPI publishing workflows for Python packages.
21+
We can learn a lot from the Python package breach [involving Ultralytics](https://blog.pypi.org/posts/2024-12-11-ultralytics-attack-analysis/). This breach highlighted the importance of making our PyPI publishing workflows for Python packages more secure.
2222

2323
In this breach, hackers exploited a GitHub action workflow to inject malicious code into a Python package. This package was then published to PyPI. The outcome: Users who downloaded the package unknowingly allowed their machines to be hijacked for Bitcoin mining.
2424

@@ -28,11 +28,10 @@ While unsettling, there’s a silver lining: the PyPI security team had already
2828

2929
{% include pyos-blockquote.html quote="Because the Ultralytics project was using Trusted Publishing and the PyPA’s publishing GitHub Action: PyPI staff, volunteers, and security researchers were able to dig into how maliciously injected software was able to make its way into the package." author="Seth Larson, PSF Security Expert" class="highlight magenta" %}
3030

31-
This incident underscores the importance of understanding Python packaging security best practices, and this includes understanding how to lock things down on GitHub & GitLab!
31+
This means that the important thing for us, as maintainers, is that we all should know how to lock down our publishing workflows.
32+
Here, I'll cover the lessons learned that you can apply TODAY to your Python packaging workflows!
3233

33-
But never fear, here, I'll cover the lessons learned that you can apply TODAY to your Python packaging workflows!
34-
35-
*Special thanks to [Sviatoslav Sydorenko](https://github.com/webknjaz) for reviewing this blog post!!*
34+
*Special thanks to [Sviatoslav Sydorenko](https://github.com/webknjaz) for reviewing and providing significant input on this blog post!!*
3635

3736
<div class="notice" markdown="1">
3837
## TL;DR Takeaways
@@ -58,7 +57,7 @@ Don’t wait--start securing your Python publishing workflows today. 🔒
5857

5958
The Ultralytics breach highlights the need for us all to follow and understand secure PyPI publishing practices and carefully monitor workflows. Below are actionable steps you can take to enhance security when publishing Python packages to PyPI using GitHub actions.
6059

61-
[PyPA provides a great overview of using actions to publish your Python package.](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)
60+
<i class="fa-solid fa-circle-info"></i> [PyPA provides a great overview of using actions to publish your Python package.](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)
6261
{: .notice }
6362

6463
## 1. Create a dedicated GitHub environment for publishing actions
@@ -83,16 +82,21 @@ If you look at the workflow example below, notice that we have an [environment c
8382
8483
To lockdown a GitHub environment:
8584
86-
* First, go to the **settings** in your repository where the workflow is run
85+
* First, go to the <kbd>Settings</kbd> in your repository where the workflow is run
8786
* Within settings, select **environments** from the left-hand sidebar
88-
* Add a new environment. Use `pypi` as your environment name; this is what PyPA (the Python Packaging Authority) recommends.
89-
* Ensure **Required reviewers** is enabled. This setting allows you to designate specific individuals who can approve and manually run the workflow on GitHub. Any reviewers you add must have the appropriate permissions to authorize the workflow by clicking a button. This adds a human verification step to the process.
90-
* Once the required reviewers are checked, add maintainers who you want to be able to enable the action to run.
87+
* Add a new environment. Use <kbd>pypi</kbd> as your environment name; this is what PyPA (the Python Packaging Authority) recommends.
88+
* Ensure <kbd>Required reviewers</kbd> is enabled. This setting allows you to designate specific individuals who can approve and manually run the workflow on GitHub. Any reviewers you add must have the appropriate permissions to authorize the workflow by clicking a button. This adds a human verification step to the process.
89+
* Once the <kbd>Required reviewers</kbd> button is checked, add maintainers who you want to be able to enable the action to run.
9190
92-
*Optionally, you can prevent self-review, preventing someone from triggering a release or a build and then running it!*
91+
*Optionally, you can click <kbd>prevent self-review</kbd>, preventing someone from triggering a release or a build and then running it!*
92+
93+
<figure>
94+
<img src="/images/python-packaging/create-github-environment.gif" alt="Animated gif file that shows the github interface where you can click on settings and go to the environment setting to create or edit a GitHub environment">
95+
<figcaption>
96+
To create a new environment to use in a GitHub action, 1) go to your repo's settings; 2) click <kbd>environment</kbd>; 3) add a new environment. In this screenshot, we already have a <kbd>pypi</kbd> environment created. Note that you can name your environment whatever you want, however, PyPI suggests that you use the name <kbd>pypi</kbd> for a Trusted Publisher workflow.
97+
</figcaption>
98+
</figure>
9399
94-
TODO: add an animated gif that shows the process on GitHub of creating the environment in setting and adding users. Or add screenshots.
95-
{: .notice }
96100
97101
<figure>
98102
<img src="/images/python-packaging/github-action-environment-pypi.png" alt="Screenshot of the GitHub settings interface showing the ‘Environments’ section with configuration options for ‘pypi.’ The ‘Deployment protection rules’ section is visible, with ‘Required reviewers’ enabled and two reviewers listed: ‘lwasser’ and ‘willingc.’ Other options such as ‘Prevent self-review’ and ‘Wait timer’ are present but not enabled.">
@@ -135,6 +139,7 @@ The steps for setting up Trusted Publisher are:
135139
7. Fill out a form that looks like the one below in the add a new pending publisher section. Notice that you can select GitHub, GitLab, Google and Active State as platforms.
136140
10. Notice that the form asks for your project name, owner, repo name, workflow's file name, and environment (**STRONGLY recommended**).
137141
142+
138143
<figure>
139144
<picture>
140145
<source srcset="/images/python-packaging/trusted-publisher-form.webp" type="image/webp">
@@ -147,6 +152,18 @@ The steps for setting up Trusted Publisher are:
147152
148153
For an example of a GitHub workflow that uses trusted publishing, check out our active pyOpenSci [PyPI publishing GitHub workflow](https://github.com/pyOpenSci/pyosMeta/blob/main/.github/workflows/publish-pypi.yml), which follows the Trusted Publisher approach.
149154
155+
156+
<figure>
157+
<picture>
158+
<source srcset="/images/python-packaging/trusted-publisher-manage.webp" type="image/webp">
159+
<img src="trusted-publisher-form.webp" alt="PyPI Trusted Publisher manage settings showing what the Trusted Publisher setup looks like after you've created it in PyPI. It shows all of the items that you filled out in the form and has a remove button if you want to remove it from PyPI. " loading="lazy">
160+
</picture>
161+
<figcaption>
162+
Example of the PyPI Trusted Publisher setup in PyPI once you've created the Trusted PuUblisher link by filling the form out above.
163+
</figcaption>
164+
</figure>
165+
166+
150167
**Note:** Read more here about [support for publishing to GitLab](https://docs.pypi.org/trusted-publishers/adding-a-publisher/#gitlab-cicd) using trusted publishing.
151168
{: .notice }
152169

_sass/minimal-mistakes/_base.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,24 @@ pre {
262262
font-size: 1em;
263263
}
264264

265+
266+
267+
268+
kbd {
269+
background-color: $kbd-color-background;
270+
color: $kbd-color-text;
271+
border-radius: 0.25rem;
272+
box-shadow: 0 2px 0 1px $kbd-color-border;
273+
line-height: 1;
274+
font-size: .75em;
275+
padding: .15em .25em;
276+
277+
&:hover {
278+
box-shadow: 0 1px 0 0.5px $kbd-color-border;
279+
top: 1px;
280+
}
281+
}
282+
265283
pre {
266284
overflow-x: auto; /* add scrollbars to wide code blocks*/
267285
}

_sass/minimal-mistakes/_variables.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ $h-size-4: 1.0625em !default; // ~17px
7070
$h-size-5: 1.03125em !default; // ~16.5px
7171
$h-size-6: 1em !default; // ~16px
7272

73+
/* kbd colors */
74+
$kbd-color-background: #bbbdc3;
75+
$kbd-color-border: #999ba5;
76+
$kbd-color-text: #222325;
77+
7378
/*
7479
Colors
7580
========================================================================== */
863 KB
Loading
3.39 KB
Loading
232 KB
Loading
69 KB
Loading
119 KB
Loading

0 commit comments

Comments
 (0)