Skip to content

Commit be601f1

Browse files
mahlau-flexyaugenst-flex
authored andcommitted
ci: security fixes in github actions as suggested by zizmor
1 parent e8258e1 commit be601f1

10 files changed

+135
-37
lines changed

.github/workflows/tidy3d-docs-sync-readthedocs-repo.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ on:
1818
- 'v*'
1919
- 'demo/*'
2020

21+
permissions:
22+
contents: read
23+
2124
jobs:
2225
extract_branch_or_tag:
2326
outputs:
@@ -46,6 +49,7 @@ jobs:
4649
fetch-depth: 0
4750
ref: ${{ needs.extract_branch_or_tag.outputs.ref_name }}
4851
fetch-tags: true
52+
persist-credentials: true
4953

5054
- name: push-mirror-repo
5155
env:

.github/workflows/tidy3d-python-client-daily.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ on:
66
- cron: '0 5 * * *' # Runs at 5am UTC
77

88
permissions:
9-
contents: write
10-
pull-requests: write
9+
contents: read
1110

1211
jobs:
1312
update-lockfile:
1413
uses: ./.github/workflows/tidy3d-python-client-update-lockfile.yml
14+
permissions:
15+
contents: write
16+
pull-requests: write
1517
with:
1618
run-workflow: true
17-
secrets: inherit
1819

1920
submodule-tests:
2021
uses: ./.github/workflows/tidy3d-python-client-submodules-test.yml
2122
with:
2223
run-workflow: true
23-
secrets: inherit

.github/workflows/tidy3d-python-client-develop-cli.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
- develop
1010
- latest
1111

12+
permissions:
13+
contents: read
14+
1215
jobs:
1316
test-dev-commands:
1417
strategy:
@@ -23,6 +26,7 @@ jobs:
2326
ref: develop
2427
fetch-depth: 1
2528
submodules: false
29+
persist-credentials: false
2630

2731
- name: Set up Python
2832
uses: actions/setup-python@v5
@@ -58,9 +62,9 @@ jobs:
5862
# ----- install & configure poetry -----
5963
#----------------------------------------------
6064
- name: Install Poetry
61-
uses: snok/install-poetry@v1
65+
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
6266
with:
63-
version: 1.8.2
67+
version: 2.1.1
6468
virtualenvs-create: true
6569
virtualenvs-in-project: true
6670

.github/workflows/tidy3d-python-client-release.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name: "public/tidy3d/python-client-release"
22

3-
permissions:
4-
contents: write
5-
63
on:
74
push:
85
tags:
96
- 'v*.*.*'
107

8+
permissions:
9+
contents: read
10+
1111
jobs:
1212
test-latest-submodules:
1313
runs-on: ubuntu-latest
@@ -19,6 +19,7 @@ jobs:
1919
submodules: 'recursive'
2020
# This fetches only a single branch by default, so additional fetch is needed
2121
fetch-depth: 0 # Optionally, set to 0 to fetch all history for all branches and tags
22+
persist-credentials: false
2223

2324
- name: Initialize and update submodule
2425
run: |
@@ -74,20 +75,23 @@ jobs:
7475
7576
github-release:
7677
runs-on: ubuntu-latest
78+
permissions:
79+
contents: write
7780
steps:
7881
- uses: actions/checkout@v4
7982
with:
8083
ref: ${{ github.ref }}
84+
persist-credentials: false
8185
- name: Exit if any RC release
8286
if: contains(github.ref, 'rc') == false
83-
uses: everlytic/branch-merge@1.1.2
87+
uses: everlytic/branch-merge@c4a244dc23143f824ae6c022a10732566cb8e973 # v1.1.5
8488
with:
8589
github_token: ${{ secrets.GH_PAT }}
8690
source_ref: ${{ github.ref }}
8791
target_branch: "latest"
8892
commit_message_template: ':tada: RELEASE: Merged {source_ref} into target {target_branch}'
8993
- name: Release
90-
uses: softprops/action-gh-release@v1
94+
uses: softprops/action-gh-release@aec2ec56f94eb8180ceec724245f64ef008b89f5 # v2.4.0
9195
with:
9296
generate_release_notes: true
9397
env:
@@ -98,6 +102,7 @@ jobs:
98102
- uses: actions/checkout@v4
99103
with:
100104
ref: ${{ github.ref }}
105+
persist-credentials: false
101106
- uses: actions/setup-python@v2
102107
- name: Install dependencies
103108
run: |
@@ -107,18 +112,19 @@ jobs:
107112
env:
108113
TWINE_USERNAME: __token__
109114
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
110-
run: |
115+
run: | # zizmor: ignore[use-trusted-publishing]
111116
python -m build
112-
python -m twine upload --repository pypi dist/*
117+
python -m twine upload --repository pypi dist/*
113118
sync_to_develop:
114119
runs-on: ubuntu-latest
115120
steps:
116121
- uses: actions/checkout@v4
117122
with:
118123
ref: "latest"
124+
persist-credentials: false
119125
- name: Exit if any RC release
120126
if: contains(github.ref, 'rc') == false
121-
uses: everlytic/branch-merge@1.1.2
127+
uses: everlytic/branch-merge@c4a244dc23143f824ae6c022a10732566cb8e973 # v1.1.5
122128
with:
123129
github_token: ${{ secrets.GH_PAT }}
124130
source_ref: "latest"

.github/workflows/tidy3d-python-client-submodules-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ on:
2222
type: boolean
2323
default: true
2424

25+
permissions:
26+
contents: read
27+
2528
jobs:
2629
test-latest-submodules:
2730
runs-on: ubuntu-latest
@@ -33,6 +36,7 @@ jobs:
3336
submodules: 'recursive'
3437
# This fetches only a single branch by default, so additional fetch is needed
3538
fetch-depth: 0 # Optionally, set to 0 to fetch all history for all branches and tags
39+
persist-credentials: true
3640

3741
- name: Initialize and update submodule
3842
run: |

.github/workflows/tidy3d-python-client-tests.yml

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ on:
2323

2424
permissions:
2525
contents: read
26-
pull-requests: write
2726

2827
jobs:
2928
determine-test-scope:
@@ -164,7 +163,8 @@ jobs:
164163
with:
165164
fetch-depth: 1
166165
submodules: false
167-
- uses: astral-sh/ruff-action@v3
166+
persist-credentials: false
167+
- uses: astral-sh/ruff-action@57714a7c8a2e59f32539362ba31877a1957dded1 # v3.5.1
168168
with:
169169
version: 0.11.11
170170
- name: Run ruff format
@@ -185,8 +185,24 @@ jobs:
185185
with:
186186
persist-credentials: false
187187

188+
- name: Install the latest version of uv
189+
uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v6.7.0
190+
188191
- name: Run zizmor 🌈
189-
uses: zizmorcore/zizmor-action@e673c3917a1aef3c65c972347ed84ccd013ecda4 # v0.2.0
192+
run: uvx zizmor .github/workflows/* --format=sarif . > results.sarif
193+
env:
194+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
195+
196+
- name: Upload SARIF file
197+
uses: github/codeql-action/upload-sarif@192325c86100d080feab897ff886c34abd4c83a3 # v3.30.3
198+
with:
199+
sarif_file: results.sarif
200+
category: zizmor
201+
202+
- name: run zizmor directly # this gets a success or fail result
203+
run: uvx zizmor .github/workflows/*
204+
env:
205+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
190206

191207
lint-branch-name:
192208
needs: determine-test-scope
@@ -199,14 +215,16 @@ jobs:
199215
- name: extract-branch-name
200216
id: extract-branch-name
201217
run: |
202-
BRANCH_NAME="${{ github.head_ref }}"
218+
BRANCH_NAME="${GITHUB_HEAD_REF}"
203219
echo "Branch name: $BRANCH_NAME"
204220
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
205221
206222
- name: enforce-jira-key
207223
id: enforce-jira-key
224+
env:
225+
STEPS_EXTRACT_BRANCH_NAME_OUTPUTS_BRANCH_NAME: ${{ steps.extract-branch-name.outputs.branch_name }}
208226
run: |
209-
BRANCH_NAME="${{ steps.extract-branch-name.outputs.branch_name }}"
227+
BRANCH_NAME="${STEPS_EXTRACT_BRANCH_NAME_OUTPUTS_BRANCH_NAME}"
210228
echo $BRANCH_NAME
211229
JIRA_PATTERN='[A-Z]{2,}-[0-9]+'
212230
@@ -246,6 +264,7 @@ jobs:
246264
uses: actions/checkout@v4
247265
with:
248266
fetch-depth: 0 # fetch all commits in the PR
267+
persist-credentials: false
249268

250269
- name: Setup node
251270
uses: actions/setup-node@v4
@@ -264,9 +283,11 @@ jobs:
264283
265284
- name: Check commit messages (merge_group)
266285
if: github.event_name == 'merge_group'
286+
env:
287+
GITHUB_EVENT_MERGE_GROUP_HEAD_SHA: ${{ github.event.merge_group.head_sha }}
267288
run: |
268289
# For merge groups, check the commits being merged
269-
npx commitlint --from ${{ github.event.merge_group.base_sha }} --to ${{ github.event.merge_group.head_sha }} --verbose || {
290+
npx commitlint --from ${{ github.event.merge_group.base_sha }} --to ${GITHUB_EVENT_MERGE_GROUP_HEAD_SHA} --verbose || {
270291
echo "Commit message linting failed; please follow the conventional commits format at https://www.conventionalcommits.org/"
271292
exit 1
272293
}
@@ -288,6 +309,7 @@ jobs:
288309
ref: ${{ github.event.pull_request.head.ref }}
289310
repository: ${{ github.event.pull_request.head.repo.full_name }}
290311
fetch-depth: 0
312+
persist-credentials: false
291313

292314
- name: git-config
293315
run: |
@@ -324,13 +346,16 @@ jobs:
324346
325347
- name: run-schema-diff
326348
id: schema-diff
349+
env:
350+
GITHUB_EVENT_PULL_REQUEST_BASE_REPO_FULL_NAME: ${{ github.event.pull_request.base.repo.full_name }}
351+
GITHUB_EVENT_PULL_REQUEST_BASE_REF: ${{ github.event.pull_request.base.ref }}
327352
run: |
328353
set -euo pipefail
329354
cd "$GITHUB_WORKSPACE"
330355
331356
# Determine base repo/ref for PRs; default to current repo and 'develop' otherwise
332-
BASE_REPO="${{ github.event.pull_request.base.repo.full_name }}"
333-
BASE_REF="${{ github.event.pull_request.base.ref }}"
357+
BASE_REPO="${GITHUB_EVENT_PULL_REQUEST_BASE_REPO_FULL_NAME}"
358+
BASE_REF="${GITHUB_EVENT_PULL_REQUEST_BASE_REF}"
334359
if [ -z "$BASE_REPO" ]; then
335360
BASE_REPO="${{ github.repository }}"
336361
fi
@@ -375,9 +400,11 @@ jobs:
375400
376401
- name: verify-allowed-changes
377402
if: steps.schema-diff.outputs.changed == 'true'
403+
env:
404+
STEPS_GET_VERSION_OUTPUTS_VERSION: ${{ steps.get-version.outputs.version }}
378405
run: |
379406
set -e
380-
version="${{ steps.get-version.outputs.version }}"
407+
version="${STEPS_GET_VERSION_OUTPUTS_VERSION}"
381408
if [[ "$version" == *rc* ]]; then
382409
echo "✅ Passing: Schema changed on a release candidate version ($version), which is permitted."
383410
else
@@ -403,12 +430,14 @@ jobs:
403430
env: # Set environment variables for the whole job
404431
PIP_ONLY_BINARY: gdstk
405432
MPLBACKEND: agg
406-
433+
permissions:
434+
pull-requests: write
407435
steps:
408436
- uses: actions/checkout@v4
409437
with:
410438
fetch-depth: 0 # Required 0 for diff report.
411439
submodules: false
440+
persist-credentials: false
412441

413442
- name: install-project
414443
env:
@@ -449,11 +478,13 @@ jobs:
449478
matrix.python-version == '3.13' &&
450479
github.event_name == 'pull_request' &&
451480
!contains(github.event.pull_request.labels.*.name, 'ignore_diff_coverage')
481+
env:
482+
GITHUB_EVENT_PULL_REQUEST_BASE_REF: ${{ github.event.pull_request.base.ref }}
452483
run: |
453484
source ${GITHUB_WORKSPACE}/.venv/bin/activate
454485
git config --global --add safe.directory ${GITHUB_WORKSPACE}
455486
diff-cover ${GITHUB_WORKSPACE}/coverage.xml \
456-
--compare-branch origin/${{ github.event.pull_request.base.ref }} \
487+
--compare-branch origin/${GITHUB_EVENT_PULL_REQUEST_BASE_REF} \
457488
--format markdown:diff-coverage.md
458489
459490
- uses: actions/github-script@v7
@@ -519,9 +550,10 @@ jobs:
519550
with:
520551
fetch-depth: 1
521552
submodules: false
553+
persist-credentials: false
522554

523555
- name: install-poetry
524-
uses: snok/install-poetry@v1
556+
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
525557
with:
526558
version: 2.1.1
527559
virtualenvs-create: true
@@ -534,7 +566,6 @@ jobs:
534566

535567
- name: install-project
536568
shell: bash
537-
if: ${{ matrix.platform }} != "windows-latest"
538569
run: |
539570
poetry --version
540571
python --version
@@ -570,7 +601,7 @@ jobs:
570601
- name: create-badge
571602
if: ${{ github.ref == 'refs/heads/develop' }}
572603
# https://gist.githubusercontent.com/nedbat/8c6980f77988a327348f9b02bbaf67f5
573-
uses: schneegans/dynamic-badges-action@v1.7.0
604+
uses: schneegans/dynamic-badges-action@e9a478b16159b4d31420099ba146cdc50f134483 # v1.7.0
574605
with:
575606
auth: ${{ secrets.GH_TIDY3D_COVERAGE_GIST }}
576607
gistID: 4702549574741e87deaadba436218ebd
@@ -598,15 +629,24 @@ jobs:
598629
- lint-branch-name
599630
- zizmor
600631
runs-on: ubuntu-latest
632+
env:
633+
NEEDS_LOCAL_TESTS_RESULT: ${{ needs.local-tests.result }}
634+
NEEDS_REMOTE_TESTS_RESULT: ${{ needs.remote-tests.result }}
635+
NEEDS_LINT_RESULT: ${{ needs.lint.result }}
636+
NEEDS_VERIFY_SCHEMA_CHANGE_RESULT: ${{ needs.verify-schema-change.result }}
637+
NEEDS_LINT_COMMIT_MESSAGES_RESULT: ${{ needs.lint-commit-messages.result }}
638+
NEEDS_LINT_BRANCH_NAME_RESULT: ${{ needs.lint-branch-name.result }}
639+
NEEDS_ZIZMOR_RESULT: ${{ needs.zizmor.result }}
601640
steps:
602641
- name: check-linting-result
603642
if: ${{ needs.lint.result != 'success' }}
604643
run: |
605644
echo "❌ Linting failed."
606645
exit 1
607-
646+
608647
- name: check-schema-change-verification
609648
if: ${{ needs.verify-schema-change.result != 'success' }}
649+
610650
run: |
611651
echo "❌ Schema change verification failed."
612652
exit 1

0 commit comments

Comments
 (0)