Skip to content

Commit 44d6bba

Browse files
fix(ci): harden workflow files flagged on #14789
1 parent e6be245 commit 44d6bba

21 files changed

Lines changed: 149 additions & 98 deletions

.github/workflows/bot_pytest.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,25 @@ jobs:
1818
pull-requests: write
1919
outputs:
2020
comment_id: ${{ steps.comment.outputs.comment_id }}
21+
authorized: ${{ steps.auth.outputs.authorized }}
2122
steps:
23+
- name: Authorize commenter
24+
id: auth
25+
env:
26+
AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }}
27+
ACTOR: ${{ github.actor }}
28+
run: |
29+
case "$AUTHOR_ASSOCIATION" in
30+
OWNER|MEMBER|COLLABORATOR)
31+
echo "authorized=true" >> "$GITHUB_OUTPUT"
32+
;;
33+
*)
34+
echo "::error::User '${ACTOR}' (association: ${AUTHOR_ASSOCIATION}) is not authorized to trigger this workflow."
35+
echo "authorized=false" >> "$GITHUB_OUTPUT"
36+
exit 1
37+
;;
38+
esac
39+
2240
- name: Acknowledge with 👀
2341
env:
2442
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -46,6 +64,7 @@ jobs:
4664
gpu:
4765
name: Run pytest on GPU
4866
needs: gate
67+
if: ${{ needs.gate.outputs.authorized == 'true' }}
4968
# A newer command on the same PR supersedes an in-flight one. Scoped to this job
5069
# only so the superseded run's `report` still updates its comment.
5170
concurrency:
@@ -75,7 +94,7 @@ jobs:
7594
shell: bash
7695
steps:
7796
- name: Checkout PR head
78-
uses: actions/checkout@v7
97+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
7998
with:
8099
# Works for forks too — no fork credentials needed.
81100
ref: refs/pull/${{ github.event.issue.number }}/head
@@ -116,7 +135,7 @@ jobs:
116135
117136
- name: Test suite reports artifacts
118137
if: ${{ always() }}
119-
uses: actions/upload-artifact@v7.0.1
138+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
120139
with:
121140
name: bot_gpu_test_reports
122141
path: reports
@@ -126,7 +145,7 @@ jobs:
126145
needs: [gate, gpu]
127146
# Always run so the comment is updated on success, failure, or cancellation —
128147
# but only if `gate` actually posted a comment to update.
129-
if: ${{ always() && needs.gate.outputs.comment_id != '' }}
148+
if: ${{ always() && needs.gate.outputs.authorized == 'true' && needs.gate.outputs.comment_id != '' }}
130149
runs-on: ubuntu-22.04
131150
permissions:
132151
pull-requests: write

.github/workflows/claude_review.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ on:
66
pull_request_review_comment:
77
types: [created]
88

9-
permissions:
10-
contents: write
11-
pull-requests: write
12-
issues: read
9+
10+
permissions: {}
1311

1412
jobs:
1513
claude-review:
14+
permissions:
15+
contents: write
16+
issues: read
17+
pull-requests: write
1618
if: |
1719
(
1820
github.event_name == 'issue_comment' &&
@@ -34,7 +36,7 @@ jobs:
3436
cancel-in-progress: false
3537
runs-on: ubuntu-latest
3638
steps:
37-
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1
39+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3840
with:
3941
fetch-depth: 1
4042

.github/workflows/issue_labeler.yml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ on:
44
issues:
55
types: [opened]
66

7-
permissions:
8-
contents: read
9-
issues: write
7+
8+
permissions: {}
109

1110
jobs:
1211
label:
12+
permissions:
13+
contents: read
14+
issues: write
1315
runs-on: ubuntu-latest
1416
steps:
1517
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -22,7 +24,14 @@ jobs:
2224
ISSUE_TITLE: ${{ github.event.issue.title }}
2325
ISSUE_BODY: ${{ github.event.issue.body }}
2426
run: |
25-
LABELS=$(python utils/label_issues.py)
27+
# Issue title/body are untrusted user input: bound their length before
28+
# they are handed to the LLM. utils/label_issues.py must wrap them in a
29+
# clearly delimited user-content block and instruct the model to never
30+
# follow instructions contained inside that block.
31+
ISSUE_TITLE=$(printf '%s' "$ISSUE_TITLE" | head -c 500)
32+
ISSUE_BODY=$(printf '%s' "$ISSUE_BODY" | head -c 4000)
33+
export ISSUE_TITLE ISSUE_BODY
34+
LABELS=$(python utils/label_issues.py | tr -d '\r\n')
2635
echo "labels=$LABELS" >> "$GITHUB_OUTPUT"
2736
- name: Apply labels
2837
if: steps.get-labels.outputs.labels != ''
@@ -31,6 +40,17 @@ jobs:
3140
ISSUE_NUMBER: ${{ github.event.issue.number }}
3241
LABELS: ${{ steps.get-labels.outputs.labels }}
3342
run: |
34-
for label in $(echo "$LABELS" | python -c "import json,sys; print('\n'.join(json.load(sys.stdin)))"); do
35-
gh issue edit "$ISSUE_NUMBER" --add-label "$label"
36-
done
43+
# The model output is untrusted (it can be steered by the issue author).
44+
# Validate every returned label against a fixed server-side allowlist
45+
# before mutating the issue with the write-scoped token.
46+
ALLOWED_LABELS=$'bug\nenhancement\ndocumentation\nquestion\nfeature request\ngood first issue\nhelp wanted'
47+
printf '%s' "$LABELS" \
48+
| python -c "import json,sys; data=json.load(sys.stdin); data=data if isinstance(data,list) else []; print('\n'.join(str(x) for x in data[:10]))" \
49+
| while IFS= read -r label; do
50+
[ -n "$label" ] || continue
51+
if ! printf '%s\n' "$ALLOWED_LABELS" | grep -Fxq -- "$label"; then
52+
echo "Skipping label not in allowlist: $label"
53+
continue
54+
fi
55+
gh issue edit "$ISSUE_NUMBER" --add-label "$label"
56+
done

.github/workflows/mirror_community_pipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ jobs:
6969
run: |
7070
echo "CHECKOUT_REF: ${{ env.CHECKOUT_REF }}"
7171
echo "PATH_IN_REPO: ${{ env.PATH_IN_REPO }}"
72-
- uses: actions/checkout@v7
72+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
7373
with:
7474
ref: ${{ env.CHECKOUT_REF }}
7575

7676
# Setup + install dependencies
7777
- name: Set up Python
78-
uses: actions/setup-python@v7.0.0
78+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
7979
with:
8080
python-version: "3.10"
8181
- name: Install dependencies

.github/workflows/notify_slack_about_release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
runs-on: ubuntu-22.04
1414

1515
steps:
16-
- uses: actions/checkout@v7
16+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1717

1818
- name: Setup Python
19-
uses: actions/setup-python@v7.0.0
19+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
2020
with:
2121
python-version: '3.10'
2222

.github/workflows/pr_dependency_test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
check_dependencies:
2323
runs-on: ubuntu-22.04
2424
steps:
25-
- uses: actions/checkout@v7
25+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2626
- name: Set up Python
27-
uses: actions/setup-python@v7.0.0
27+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
2828
with:
2929
python-version: "3.10"
3030
- name: Install dependencies

.github/workflows/pr_labeler.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
name: PR Labeler
22

33
on:
4-
pull_request_target:
4+
pull_request:
55
types: [opened, synchronize, reopened]
66

7-
permissions:
8-
contents: read
9-
pull-requests: write
7+
8+
permissions: {}
109

1110
jobs:
1211
label:
12+
permissions:
13+
contents: read
14+
pull-requests: write
1315
runs-on: ubuntu-latest
1416
steps:
1517
- uses: actions/labeler@bf12e9b00b37c5c0ca2b87b79b2daf7891dbda13 # v7.0.0
1618
with:
1719
sync-labels: true
1820

1921
missing-tests:
22+
permissions:
23+
contents: read
24+
pull-requests: write
2025
runs-on: ubuntu-latest
2126
steps:
2227
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -50,6 +55,9 @@ jobs:
5055
fi
5156
5257
fixes-issue:
58+
permissions:
59+
issues: read
60+
pull-requests: write
5361
runs-on: ubuntu-latest
5462
steps:
5563
- name: Check for linked closing issues
@@ -85,6 +93,8 @@ jobs:
8593
fi
8694
8795
size-label:
96+
permissions:
97+
pull-requests: write
8898
runs-on: ubuntu-latest
8999
steps:
90100
- name: Label PR by diff size

.github/workflows/pr_modular_tests.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ jobs:
4444
check_code_quality:
4545
runs-on: ubuntu-22.04
4646
steps:
47-
- uses: actions/checkout@v7
47+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4848
- name: Set up Python
49-
uses: actions/setup-python@v7.0.0
49+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
5050
with:
5151
python-version: "3.10"
5252
- name: Install dependencies
@@ -64,9 +64,9 @@ jobs:
6464
needs: check_code_quality
6565
runs-on: ubuntu-22.04
6666
steps:
67-
- uses: actions/checkout@v7
67+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
6868
- name: Set up Python
69-
uses: actions/setup-python@v7.0.0
69+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
7070
with:
7171
python-version: "3.10"
7272
- name: Install dependencies
@@ -92,7 +92,7 @@ jobs:
9292
container:
9393
image: diffusers/diffusers-pytorch-cpu
9494
steps:
95-
- uses: actions/checkout@v7
95+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
9696
- name: Install dependencies
9797
run: |
9898
printf 'torch==2.10.0\ntorchvision==0.25.0\ntorchaudio==2.10.0\n' > "$UV_OVERRIDE"
@@ -122,7 +122,7 @@ jobs:
122122

123123
steps:
124124
- name: Checkout diffusers
125-
uses: actions/checkout@v7
125+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
126126
with:
127127
fetch-depth: 2
128128

@@ -151,7 +151,7 @@ jobs:
151151

152152
- name: Test suite reports artifacts
153153
if: ${{ always() }}
154-
uses: actions/upload-artifact@v7.0.1
154+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
155155
with:
156156
name: pr_pytorch_pipelines_torch_cpu_modular_pipelines_test_reports
157157
path: reports

.github/workflows/pr_test_fetcher.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
test_map: ${{ steps.set_matrix.outputs.test_map }}
3232
steps:
3333
- name: Checkout diffusers
34-
uses: actions/checkout@v7
34+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3535
with:
3636
fetch-depth: 0
3737
- name: Install dependencies
@@ -45,7 +45,7 @@ jobs:
4545
run: |
4646
python utils/tests_fetcher.py | tee test_preparation.txt
4747
- name: Report fetched tests
48-
uses: actions/upload-artifact@v7.0.1
48+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
4949
with:
5050
name: test_fetched
5151
path: test_preparation.txt
@@ -86,7 +86,7 @@ jobs:
8686
shell: bash
8787
steps:
8888
- name: Checkout diffusers
89-
uses: actions/checkout@v7
89+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
9090
with:
9191
fetch-depth: 2
9292

@@ -112,7 +112,7 @@ jobs:
112112
113113
- name: Test suite reports artifacts
114114
if: ${{ always() }}
115-
uses: actions/upload-artifact@v7.0.1
115+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
116116
with:
117117
name: ${{ matrix.modules }}_test_reports
118118
path: reports
@@ -141,7 +141,7 @@ jobs:
141141

142142
steps:
143143
- name: Checkout diffusers
144-
uses: actions/checkout@v7
144+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
145145
with:
146146
fetch-depth: 2
147147

@@ -167,7 +167,7 @@ jobs:
167167

168168
- name: Test suite reports artifacts
169169
if: ${{ always() }}
170-
uses: actions/upload-artifact@v7.0.1
170+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
171171
with:
172172
name: pr_${{ matrix.config.report }}_test_reports
173173
path: reports

0 commit comments

Comments
 (0)