Skip to content

Commit 91fdb20

Browse files
committed
workflows: Split new-prs into two workflows
We cannot use the default github token for labeling PRs, because this will not trigger the PR Subscriber job. However, we weren't allowed to use a different token via a secret, because secrets aren't allowed in PR workflows. The solution is to create two workflows, the first accepts the pull_request_taget event extracts the PR number and then starts the second workflow which adds the labels to the PRs. This separation ensures that nothing malicious in the first workflow is able to access the secret we use in the second workflow.
1 parent 358d9db commit 91fdb20

File tree

2 files changed

+69
-7
lines changed

2 files changed

+69
-7
lines changed

.github/workflows/new-prs.yml

+46-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,56 @@
11
name: "Labelling new pull requests"
22
on:
3-
- pull_request_target
3+
workflow_run:
4+
workflows: ["PR Receive"]
45

56
jobs:
67
automate-prs-labels:
78
permissions:
89
contents: read
910
pull-requests: write
1011
runs-on: ubuntu-latest
11-
if: github.repository == 'llvm/llvm-project'
12+
if: >
13+
github.repository == 'llvm/llvm-project' &&
14+
github.event.workflow_run.event == 'pull_request_target' &&
15+
github.event.workflow_run.conclusion == 'success'
1216
steps:
13-
- uses: actions/labeler@v4
14-
with:
15-
configuration-path: .github/new-prs-labeler.yml
16-
# workaround for https://github.com/actions/labeler/issues/112
17-
sync-labels: ''
17+
# From: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
18+
# Updated version here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
19+
- name: Debug
20+
run: |
21+
echo "Event: ${{ github.event.workflow_run.event }} Conclusion: ${{ github.event.workflow_run.conclusion }}"
22+
- name: 'Download artifact'
23+
uses: actions/github-script@v6
24+
with:
25+
script: |
26+
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
run_id: context.payload.workflow_run.id,
30+
});
31+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
32+
return artifact.name == "pr"
33+
})[0];
34+
var download = await github.rest.actions.downloadArtifact({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
artifact_id: matchArtifact.id,
38+
archive_format: 'zip',
39+
});
40+
var fs = require('fs');
41+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
42+
43+
- run: unzip pr.zip
44+
45+
- name: "Get PR Number"
46+
id: vars
47+
run:
48+
echo "pr-number=`cat NR`" >> $GITHUB_OUTPUT
49+
50+
- uses: actions/labeler@v4
51+
with:
52+
configuration-path: .github/new-prs-labeler.yml
53+
# workaround for https://github.com/actions/labeler/issues/112
54+
sync-labels: ''
55+
repo-token: ${{ secrets.ISSUE_SUBSCRIBER_TOKEN }}
56+
pr-number: ${{steps.vars.outputs.pr-number}}

.github/workflows/pr-receive.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
2+
3+
name: PR Receive
4+
on:
5+
pull_request_target:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
pr-target:
12+
runs-on: ubuntu-latest
13+
if: github.repository == 'llvm/llvm-project'
14+
steps:
15+
- name: Store PR Information
16+
run: |
17+
mkdir -p ./pr
18+
echo ${{ github.event.number }} > ./pr/NR
19+
20+
- uses: actions/upload-artifact@v3
21+
with:
22+
name: pr
23+
path: pr/

0 commit comments

Comments
 (0)