Skip to content

Commit

Permalink
Audit GHA workflows with zizmor (#1136)
Browse files Browse the repository at this point in the history
* Don't persist credentials in pypi.yml

Ref: <https://woodruffw.github.io/zizmor/audits/#artipacked>

* Don't persist credentials

This is an insecure default on GitHub that increases the chances of credential leakage.
<https://unit42.paloaltonetworks.com/github-repo-artifacts-leak-tokens/>

* Add zizmor exception for RTD pull_request_target trigger

* Create zizmor workflow
  • Loading branch information
maresb authored Jan 16, 2025
1 parent 581f65a commit 091b664
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
shell: bash -leo pipefail {0}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: mamba-org/setup-micromamba@v2
with:
micromamba-version: "1.5.10-0" # until https://github.com/mamba-org/setup-micromamba/issues/225 is resolved
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
with:
fetch-depth: 0
submodules: true
persist-credentials: false

- name: Build SDist
run: pipx run build --sdist
Expand All @@ -45,6 +46,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- uses: hynek/build-and-inspect-python-package@v2

build_wheels:
Expand All @@ -60,6 +62,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Build wheels
uses: pypa/[email protected]
Expand All @@ -76,6 +79,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@v5
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/rtd-link-preview.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Read the Docs Pull Request Preview
on:
pull_request_target:
# See <https://github.com/readthedocs/actions/issues/45>
pull_request_target: # zizmor: ignore[dangerous-triggers]
types:
- opened

permissions:
pull-requests: write

jobs:
documentation-links:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: readthedocs/actions/preview@v1
with:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- uses: dorny/paths-filter@v3
id: changes
with:
Expand Down Expand Up @@ -56,6 +57,8 @@ jobs:
python-version: ["3.10", "3.12"]
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
Expand Down Expand Up @@ -146,6 +149,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Python ${{ matrix.python-version }}
uses: mamba-org/setup-micromamba@v2
with:
Expand Down Expand Up @@ -229,6 +233,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Python 3.10
uses: mamba-org/setup-micromamba@v2
with:
Expand Down Expand Up @@ -286,6 +291,8 @@ jobs:
if: ${{ needs.changes.outputs.changes == 'true' && needs.all-checks.result == 'success' }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@v5
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/zizmor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# https://github.com/woodruffw/zizmor
name: zizmor GHA analysis

on:
push:
branches: ["main"]
pull_request:
branches: ["**"]

jobs:
zizmor:
name: zizmor latest via PyPI
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false

- uses: hynek/setup-cached-uv@v2

- name: Run zizmor 🌈
run: uvx zizmor --format sarif . > results.sarif
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
# Path to SARIF file relative to the root of the repository
sarif_file: results.sarif
# Optional category for the results
# Used to differentiate multiple results for one commit
category: zizmor

0 comments on commit 091b664

Please sign in to comment.