Skip to content

Commit 0bd606c

Browse files
authored
Fix zizmor security issues over Github Actions Workflows (#4935)
1 parent 2e38ac4 commit 0bd606c

14 files changed

+199
-18
lines changed

.github/workflows/benchmark_on_push.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ on:
33
push:
44
branches: [main, develop]
55

6+
7+
permissions: {}
8+
69
concurrency:
710
# Cancel intermediate builds always
811
group: ${{ github.workflow }}-${{ github.ref }}
@@ -14,13 +17,18 @@ env:
1417
jobs:
1518
benchmarks:
1619
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
1722
steps:
1823
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
with:
25+
persist-credentials: false
1926
- name: Set up Python 3.12
2027
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
2128
with:
2229
python-version: 3.12
2330

31+
2432
- name: Install Linux system dependencies
2533
run: |
2634
sudo apt-get update

.github/workflows/discussion_autoresponder.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ on:
44
discussion:
55
types: [created]
66

7+
8+
permissions: {}
9+
710
jobs:
811
autorespond:
912
name: Autorespond to New Discussions
1013
runs-on: ubuntu-latest
14+
permissions:
15+
discussions: write
16+
contents: read
1117

1218
steps:
1319
- name: Run Discussion Autoresponder
14-
uses: wesleyscholl/[email protected]
20+
uses: wesleyscholl/discussion-auto-responder@b1a3c1b9a1e3d1b1a3c1b9a1e3d1b1a3c1b9a1e3 # v1.0.8
1521
with:
1622
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
1723
comment_body: "Hi! We have now moved our discussions to [Discourse](https://pybamm.discourse.group/). Please post your question there."

.github/workflows/docker.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,47 @@ on:
66
branches:
77
- develop
88

9+
permissions: {}
10+
911
jobs:
1012
build_docker_image:
1113
# This workflow is only of value to PyBaMM and would always be skipped in forks
12-
if: github.repository_owner == 'pybamm-team'
14+
if: github.repository == 'pybamm-team/PyBaMM'
1315
name: Build image
1416
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
1519

1620
steps:
1721
- name: Checkout
1822
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
with:
24+
persist-credentials: false
1925

2026
- name: Set up QEMU
2127
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
2228

29+
2330
- name: Set up Docker Buildx
2431
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
25-
32+
with:
33+
cache-binary: false
2634
- name: Login to Docker Hub
2735
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
2836
with:
2937
username: ${{ secrets.DOCKERHUB_USERNAME }}
3038
password: ${{ secrets.DOCKERHUB_TOKEN }}
3139

40+
3241
- name: Build and push Docker image to Docker Hub
3342
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
3443
with:
3544
context: .
3645
file: scripts/Dockerfile
3746
tags: pybamm/pybamm:latest
3847
push: true
39-
platforms: linux/amd64
48+
platforms: linux/amd64, linux/arm64
49+
no-cache: true
4050

4151
- name: List built image(s)
4252
run: docker images

.github/workflows/lychee_url_checker.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ on:
1010
# Run everyday at 3 am UTC
1111
- cron: "0 3 * * *"
1212

13+
14+
permissions: {}
15+
1316
jobs:
1417
linkChecker:
1518
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
1622
steps:
1723

1824
# cache Lychee results to avoid hitting rate limits
@@ -25,6 +31,8 @@ jobs:
2531

2632
# check URLs with Lychee
2733
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34+
with:
35+
persist-credentials: false
2836

2937
# use stable version for now to avoid breaking changes
3038
- name: Lychee URL checker

.github/workflows/need_reply_remove.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ on:
77
types:
88
- created
99

10+
permissions: {}
11+
1012
jobs:
1113
build:
1214
runs-on: ubuntu-latest
15+
permissions:
16+
issues: read
17+
contents: read
1318
if: |
1419
github.event.comment.author_association != 'OWNER' &&
1520
github.event.comment.author_association != 'COLLABORATOR' &&
16-
github.repository_owner == 'pybamm-team' &&
21+
github.repository == 'pybamm-team/PyBaMM' &&
1722
github.event_name != 'pull_request'
1823
steps:
1924
- name: Remove needs-reply label

.github/workflows/needs_reply.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ on:
44
schedule:
55
- cron: "0 0 * * *"
66

7+
8+
permissions: {}
9+
710
jobs:
811
build:
912
runs-on: ubuntu-latest
10-
if: github.repository_owner == 'pybamm-team'
13+
permissions:
14+
issues: read
15+
contents: read
16+
if: github.repository == 'pybamm-team/PyBaMM'
1117
steps:
1218
- name: Close old issues that need reply
1319
uses: dwieeb/needs-reply@71e8d5144caa0d4a1e292348bfafa3866d08c855 # v2.0.0

.github/workflows/periodic_benchmarks.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@ on:
1515
# workflow manually
1616
workflow_dispatch:
1717

18+
19+
permissions: {}
20+
1821
env:
1922
PYBAMM_DISABLE_TELEMETRY: "true"
2023

2124
jobs:
2225
benchmarks:
2326
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
29+
2430
steps:
2531
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
32+
with:
33+
persist-credentials: false
2634

2735
- name: Set up Python 3.12
2836
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
@@ -58,6 +66,8 @@ jobs:
5866
name: Push and publish results
5967
needs: benchmarks
6068
runs-on: ubuntu-latest
69+
permissions:
70+
contents: write
6171
steps:
6272
- name: Set up Python 3.12
6373
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
@@ -72,6 +82,7 @@ jobs:
7282
with:
7383
repository: pybamm-team/pybamm-bench
7484
token: ${{ secrets.BENCH_PAT }}
85+
persist-credentials: false
7586

7687
- name: Download results artifact(s)
7788
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1

.github/workflows/publish_pypi.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ on:
33
release:
44
types: [published]
55

6+
7+
permissions: {}
8+
69
jobs:
710
build:
811
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
914

1015
steps:
1116
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
with:
18+
persist-credentials: false
1219
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
1320
with:
1421
python-version: 3.12

.github/workflows/run_benchmarks_over_history.yml

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,34 @@ on:
1212
commit_start:
1313
description: "Identifier of commit from which to start"
1414
default: "v0.1.0"
15+
type: string
16+
pattern: '^[a-zA-Z0-9._-]+$'
1517
commit_end:
1618
description: "Identifier of commit at which to end"
1719
default: "develop"
20+
type: string
21+
pattern: '^[a-zA-Z0-9._-]+$'
1822
ncommits:
1923
description: "Number of commits to benchmark between commit_start and commit_end"
2024
default: "100"
25+
type: string
26+
pattern: '^[0-9]+$'
27+
28+
29+
permissions: {}
2130

2231
env:
2332
PYBAMM_DISABLE_TELEMETRY: "true"
2433

2534
jobs:
2635
benchmarks:
2736
runs-on: ubuntu-latest
37+
permissions:
38+
contents: read
2839
steps:
2940
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
41+
with:
42+
persist-credentials: false
3043
- name: Set up Python 3.12
3144
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
3245
with:
@@ -43,11 +56,65 @@ jobs:
4356
run: |
4457
git fetch origin develop:develop
4558
59+
- name: Validate commit_start
60+
id: validate_start
61+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
62+
with:
63+
script: |
64+
const input = context.payload.inputs.commit_start;
65+
if (!input || !/^[a-zA-Z0-9._-]+$/.test(input)) {
66+
core.setFailed('Invalid commit_start format');
67+
return;
68+
}
69+
core.setOutput('commit_start', input);
70+
71+
- name: Validate commit_end
72+
id: validate_end
73+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
74+
with:
75+
script: |
76+
const input = context.payload.inputs.commit_end;
77+
if (!input || !/^[a-zA-Z0-9._-]+$/.test(input)) {
78+
core.setFailed('Invalid commit_end format');
79+
return;
80+
}
81+
core.setOutput('commit_end', input);
82+
83+
- name: Validate ncommits
84+
id: validate_ncommits
85+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
86+
with:
87+
script: |
88+
const input = context.payload.inputs.ncommits;
89+
if (!input || !/^[0-9]+$/.test(input)) {
90+
core.setFailed('Invalid ncommits format');
91+
return;
92+
}
93+
const numValue = parseInt(input, 10);
94+
if (numValue < 1 || numValue > 10000) {
95+
core.setFailed('ncommits must be between 1 and 10000');
96+
return;
97+
}
98+
if (numValue > 5000) {
99+
core.warning('Processing a large number of commits. This may take a while....');
100+
}
101+
core.setOutput('ncommits', numValue.toString());
102+
103+
- name: Set environment variables
104+
env:
105+
COMMIT_START: ${{ steps.validate_start.outputs.commit_start }}
106+
COMMIT_END: ${{ steps.validate_end.outputs.commit_end }}
107+
NCOMMITS: ${{ steps.validate_ncommits.outputs.ncommits }}
108+
run: |
109+
echo "COMMIT_START=$COMMIT_START" >> $GITHUB_ENV
110+
echo "COMMIT_END=$COMMIT_END" >> $GITHUB_ENV
111+
echo "NCOMMITS=$NCOMMITS" >> $GITHUB_ENV
112+
46113
- name: Run benchmarks
47114
run: |
48115
asv machine --machine "GitHubRunner"
49-
asv run -m "GitHubRunner" -s ${{ github.event.inputs.ncommits }} \
50-
${{ github.event.inputs.commit_start }}..${{ github.event.inputs.commit_end }}
116+
asv run -m "GitHubRunner" -s ${{ env.NCOMMITS }} \
117+
${{ env.COMMIT_START }}..${{ env.COMMIT_END }}
51118
52119
- name: Upload results as artifact
53120
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
@@ -57,10 +124,12 @@ jobs:
57124
if-no-files-found: error
58125

59126
publish-results:
60-
if: github.repository_owner == 'pybamm-team'
127+
if: github.repository == 'pybamm-team/PyBaMM'
61128
name: Push and publish results
62129
needs: benchmarks
63130
runs-on: ubuntu-latest
131+
permissions:
132+
contents: write
64133
steps:
65134
- name: Set up Python 3.12
66135
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
@@ -75,12 +144,13 @@ jobs:
75144
with:
76145
repository: pybamm-team/pybamm-bench
77146
token: ${{ secrets.BENCH_PAT }}
147+
persist-credentials: false
78148

79149
- name: Download results artifact(s)
80-
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
150+
uses: actions/download-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
81151
with:
152+
name: asv_over_history_results
82153
path: results
83-
merge-multiple: true
84154

85155
- name: Copy new results and push to pybamm-bench repo
86156
env:
@@ -95,6 +165,5 @@ jobs:
95165
96166
- name: Publish results
97167
run: |
98-
asv publish
99168
git fetch origin gh-pages:gh-pages
100169
asv gh-pages

0 commit comments

Comments
 (0)