Skip to content

Automate GitHub workflow security audits with zizmor#2975

Merged
namurphy merged 41 commits intoPlasmaPy:mainfrom
namurphy:pre-commit-zizmor
May 28, 2025
Merged

Automate GitHub workflow security audits with zizmor#2975
namurphy merged 41 commits intoPlasmaPy:mainfrom
namurphy:pre-commit-zizmor

Conversation

@namurphy
Copy link
Member

@namurphy namurphy commented Mar 25, 2025

zizmor is a static analysis tool to find common security issues in typical GitHub workflows. This PR:

  • Adds a Nox session to run zizmor
  • Fixes some security issues found by zizmor (like changing pull_request_targetpull_request, setting persist-credentials: false, and setting strict default permissions)
  • Sets up .github/zizmor.yml to ignore zizmor warnings and errors that are more difficult to fix.

The changes here are probably going to result in a bunch of conflicts in #2959, but it makes sense to merge this first.

Many thanks to the pyOpenSci community for helping me learn about zizmor in the first place!

Note

Several zizmor checks require a GitHub token, so running the zizmor Nox session locally will skip certain checks.

@github-actions github-actions bot added CI Related to continuous integration linters Code linters and autoformatters labels Mar 25, 2025
@codecov
Copy link

codecov bot commented Mar 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.40%. Comparing base (5c17b8f) to head (91e046f).
⚠️ Report is 162 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2975      +/-   ##
==========================================
+ Coverage   94.61%   95.40%   +0.78%     
==========================================
  Files         107      107              
  Lines        9664     9664              
  Branches     1464     1464              
==========================================
+ Hits         9144     9220      +76     
+ Misses        327      257      -70     
+ Partials      193      187       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot added testing GitHub Actions A continuous integration platform for automating tests and other tasks (see .github/ directory) packaging Related to packaging or distribution release Related to releasing a new version of PlasmaPy documentation infrastructure labels Mar 25, 2025
@namurphy
Copy link
Member Author

Following a helpful suggestion by our neighbors at SunPy in sunpy/sunpy#8134, I'm leaning towards putting this as a standalone Nox session that can be put into our CI workflow.

@github-actions github-actions bot added python Pull requests that update Python code nox Related to the nox automation software labels Mar 26, 2025
@github-actions github-actions bot added the maintenance General updates to package infrastructure label Apr 3, 2025
@namurphy namurphy changed the title Add zizmor as a pre-commit hook to perform GitHub workflow security audits Perform GitHub workflow security audits with zizmor during continuous integration tests Apr 7, 2025
@namurphy namurphy changed the title Perform GitHub workflow security audits with zizmor during continuous integration tests Automate GitHub workflow security audits with zizmor Apr 7, 2025
needs: add-no-changelog-label
steps:
- uses: scientific-python/action-towncrier-changelog@v1
- uses: scientific-python/action-towncrier-changelog@v1 # zizmor: ignore[unpinned-uses]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unpinned-uses rule checks that actions used via uses are pinned to a specific commit rather than the version. We can ignore this check for actions that come from trusted publishers.


- name: Generate token
uses: tibdex/github-app-token@v2
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems reasonable to pin actions by the commit hash (for extra security) if they are released by individuals or small organizations.

uv_output: str | bool = session.run(*uv_lock_upgrade, silent=running_on_ci)
uv_output: str | bool = session.run(
*uv_lock_upgrade,
*session.posargs,
Copy link
Member Author

@namurphy namurphy Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[unrelated change] Including *session.posargs here makes it so that we can pass flags to uv when running the Nox session (i.e., nox -s requirements -- -v).

@namurphy
Copy link
Member Author

@rocco8773 — would you have a chance to review this in the next few days? With the changes merged and conflicts resolved from #2959, I don't think there should be anything controversion in this PR. Kind thanks!

Copy link
Member

@rocco8773 rocco8773 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things looks good to me.

The only thing I go umm about is the use of # zimor: ignore[artipacked]. I'm not concerned about it being used, but more concerned a contributor might not know it exists and when to use it. I can just see myself updating a workflow in the future that causes a zizmor check to fail and I just forget that this inline comment exists.

I do not think adding a note about this to the documentation would help. The only thing I can think of doing is having a PR comment be made when zizmor check fails.

I do not think this needs to be resolved in the PR, but it is something to consider for a follow up PR.

@namurphy
Copy link
Member Author

namurphy commented Apr 29, 2025

The only thing I go umm about is the use of # zimor: ignore[artipacked]. I'm not concerned about it being used, but more concerned a contributor might not know it exists and when to use it.

The only thing I can think of doing is having a PR comment be made when zizmor check fails.

That's an important point. ✅ It wouldn't be hard to have the Nox session for zizmor print out a troubleshooting message. 🤔

I do not think this needs to be resolved in the PR, but it is something to consider for a follow up PR.

If I don't fix this now, I probably won't remember to later... 😅

  • Do this ↑

Thanks for the helpful review!

@github-actions github-actions bot added the run comprehensive tests Add this label to run comprehensive tests in CI label May 28, 2025
@namurphy namurphy merged commit e98f696 into PlasmaPy:main May 28, 2025
21 checks passed
@namurphy namurphy deleted the pre-commit-zizmor branch May 28, 2025 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Related to continuous integration documentation infrastructure GitHub Actions A continuous integration platform for automating tests and other tasks (see .github/ directory) linters Code linters and autoformatters maintenance General updates to package infrastructure nox Related to the nox automation software packaging Related to packaging or distribution python Pull requests that update Python code release Related to releasing a new version of PlasmaPy run comprehensive tests Add this label to run comprehensive tests in CI security Issues and PRs related to software security status: ready for review PRs that are ready for code review testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants