Skip to content

Commit 9e8c600

Browse files
authored
use zizmor to lint GitHub actions (#22294)
# Objective - Improve security of Bevy CI ## Solution - Use zizmor to lint actions https://github.com/zizmorcore/zizmor - Fix a few lints - pin actions - specify `persist-credentials` - set write permissions at job level instead of workflow level - set target branch for `pull_request_target` workflows - Add the linter as CI. With the proposed config, it should report potential issues in the security center and not block merging. There are still a few lints that fail and need more rework to fix
1 parent b0acc82 commit 9e8c600

14 files changed

+297
-148
lines changed

.github/workflows/action-on-PR-labeled.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ on:
77
pull_request_target:
88
types:
99
- labeled
10-
11-
permissions:
12-
pull-requests: 'write'
10+
branches:
11+
- "main"
1312

1413
jobs:
1514
comment-on-migration-guide-label:
15+
permissions:
16+
pull-requests: "write"
1617
runs-on: ubuntu-latest
1718
if: github.event.label.name == 'M-Migration-Guide'
1819
steps:
19-
- uses: actions/checkout@v6
20+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2021
with:
2122
ref: ${{ github.event.pull_request.head.sha }}
2223
fetch-depth: 2
24+
persist-credentials: false
2325
- name: Get changes
2426
id: get_changes
2527
shell: bash {0}
@@ -30,7 +32,7 @@ jobs:
3032
env:
3133
BASE_SHA: ${{ github.event.pull_request.base.sha }}
3234
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
33-
- uses: actions/github-script@v8
35+
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
3436
if: steps.get_changes.outputs.found_changes == '0'
3537
with:
3638
script: |
@@ -43,13 +45,16 @@ jobs:
4345
Please review the [instructions for writing migration guides](https://github.com/bevyengine/bevy/tree/main/release-content/migration_guides.md), then expand or revise the content in the [migration guides directory](https://github.com/bevyengine/bevy/tree/main/release-content/migration-guides) to reflect your changes.`
4446
})
4547
comment-on-release-note-label:
48+
permissions:
49+
pull-requests: "write"
4650
runs-on: ubuntu-latest
4751
if: github.event.label.name == 'M-Release-Note'
4852
steps:
49-
- uses: actions/checkout@v6
53+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
5054
with:
5155
ref: ${{ github.event.pull_request.head.sha }}
5256
fetch-depth: 2
57+
persist-credentials: false
5358
- name: Get changes
5459
id: get_changes
5560
shell: bash {0}
@@ -60,7 +65,7 @@ jobs:
6065
env:
6166
BASE_SHA: ${{ github.event.pull_request.base.sha }}
6267
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
63-
- uses: actions/github-script@v8
68+
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
6469
if: steps.get_changes.outputs.found_changes == '0'
6570
with:
6671
script: |

.github/workflows/ci-comment-failures.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
name: CI - PR Comments
22

3-
# This workflow has write permissions on the repo
4-
# It must not checkout a PR and run untrusted code
5-
6-
# Also requesting write permissions on PR to be able to comment
7-
permissions:
8-
pull-requests: 'write'
3+
# This workflow has write permissions on the repo
4+
# It must not checkout a PR and run untrusted code
95

106
on:
117
workflow_run:
@@ -14,16 +10,17 @@ on:
1410
- completed
1511

1612
jobs:
17-
1813
missing-examples:
14+
permissions:
15+
pull-requests: "write"
1916
runs-on: ubuntu-latest
2017
if: >
2118
github.event.workflow_run.event == 'pull_request' &&
2219
github.event.workflow_run.conclusion == 'failure'
2320
steps:
24-
- name: 'Download artifact'
21+
- name: "Download artifact"
2522
id: find-artifact
26-
uses: actions/github-script@v8
23+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
2724
with:
2825
result-encoding: string
2926
script: |
@@ -63,7 +60,7 @@ jobs:
6360
fi
6461
- name: "Comment on PR"
6562
if: ${{ steps.find-artifact.outputs.result == 'true' && steps.check-last-comment.outputs.result == 'false' }}
66-
uses: actions/github-script@v8
63+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
6764
with:
6865
github-token: ${{ secrets.GITHUB_TOKEN }}
6966
script: |
@@ -87,14 +84,16 @@ jobs:
8784
}
8885
8986
missing-features:
87+
permissions:
88+
pull-requests: "write"
9089
runs-on: ubuntu-latest
9190
if: >
9291
github.event.workflow_run.event == 'pull_request' &&
9392
github.event.workflow_run.conclusion == 'failure'
9493
steps:
95-
- name: 'Download artifact'
94+
- name: "Download artifact"
9695
id: find-artifact
97-
uses: actions/github-script@v8
96+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
9897
with:
9998
result-encoding: string
10099
script: |
@@ -134,7 +133,7 @@ jobs:
134133
fi
135134
- name: "Comment on PR"
136135
if: ${{ steps.find-artifact.outputs.result == 'true' && steps.check-last-comment.outputs.result == 'false' }}
137-
uses: actions/github-script@v8
136+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
138137
with:
139138
github-token: ${{ secrets.GITHUB_TOKEN }}
140139
script: |
@@ -158,14 +157,16 @@ jobs:
158157
}
159158
160159
msrv:
160+
permissions:
161+
pull-requests: "write"
161162
runs-on: ubuntu-latest
162163
if: >
163164
github.event.workflow_run.event == 'pull_request' &&
164165
github.event.workflow_run.conclusion == 'failure'
165166
steps:
166-
- name: 'Download artifact'
167+
- name: "Download artifact"
167168
id: find-artifact
168-
uses: actions/github-script@v8
169+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
169170
with:
170171
result-encoding: string
171172
script: |
@@ -205,7 +206,7 @@ jobs:
205206
fi
206207
- name: "Comment on PR"
207208
if: ${{ steps.find-artifact.outputs.result == 'true' && steps.check-last-comment.outputs.result == 'false' }}
208-
uses: actions/github-script@v8
209+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
209210
with:
210211
github-token: ${{ secrets.GITHUB_TOKEN }}
211212
script: |

0 commit comments

Comments
 (0)