Skip to content

Commit 19f3d04

Browse files
committed
ci: duplicate formal to fix posting comments
Duplicate formal so the event trigger can be set to pull_request_target and fix posting comments. This event allows the workflow to do things like label or comment on pull requests from forks, but it's not recommended for build jobs due to security implications. The build jobs still depends on formal that's why it has a duplicate one with less privileges. It doesn't look like there's an easy and secure way to have a workflow with lower privileges (e.g. build) depend on workflow with higher ones (e.g. formal or labeler that modify a PR). There's only the reverse with going from lower privileges to higher ones with workflow_run, for example when posting build results after a build to a PR. Either switching existing combined workflow to pull_request_target or splitting it into formal and build and switching build to workflow_run gives build unsafe privileges. Splitting and switching build to workflow_dispatch requires a custom token. Fixed: 7658669 ("multi-arch-test-build: post formal summaries to PR") Link: https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target Link: https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ Signed-off-by: George Sapkin <[email protected]>
1 parent bbaa539 commit 19f3d04

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

.github/workflows/formal.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Test Formalities
2+
3+
on:
4+
pull_request_target:
5+
6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
10+
jobs:
11+
formalities:
12+
name: Test Formalities
13+
uses: openwrt/actions-shared-workflows/.github/workflows/formal.yml@main
14+
with:
15+
post_comment: true
16+
17+
label_formality_status:
18+
name: Add Formality Check Labels
19+
runs-on: ubuntu-slim
20+
needs: formalities
21+
if: always()
22+
23+
steps:
24+
- name: Add 'not following guidelines' label
25+
if: needs.formalities.result == 'failure'
26+
uses: buildsville/[email protected]
27+
with:
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
labels: "not following guidelines"
30+
type: add
31+
32+
- name: Remove 'not following guidelines' label
33+
if: needs.formalities.result == 'success'
34+
uses: buildsville/[email protected]
35+
with:
36+
token: ${{ secrets.GITHUB_TOKEN }}
37+
labels: "not following guidelines"
38+
type: remove

.github/workflows/labeler.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
name: 'Pull Request Labeler'
1+
name: Labeler
2+
23
on:
3-
- pull_request_target
4+
pull_request_target:
45

56
permissions:
67
contents: read
78
pull-requests: write
89

910
jobs:
1011
labeler:
11-
permissions:
12-
contents: read
13-
pull-requests: write
14-
15-
name: Pull Request Labeler
12+
name: Labeler
1613
runs-on: ubuntu-slim
1714
steps:
18-
- uses: actions/labeler@v6
15+
- name: Label pull request
16+
uses: actions/labeler@v6
1917
with:
2018
repo-token: '${{ secrets.GITHUB_TOKEN }}'
2119
sync-labels: true

.github/workflows/multi-arch-test-build.yml

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,15 @@ on:
55

66
permissions:
77
contents: read
8-
pull-requests: write
98

109
jobs:
1110
formalities:
1211
name: Test Formalities
1312
uses: openwrt/actions-shared-workflows/.github/workflows/formal.yml@main
14-
with:
15-
post_comment: true
16-
17-
label_formality_status:
18-
name: Add formality check labels
19-
runs-on: ubuntu-slim
20-
needs: formalities
21-
if: always()
2213
permissions:
14+
contents: read
2315
pull-requests: write
2416

25-
steps:
26-
- name: Add 'not following guidelines' label
27-
if: needs.formalities.result == 'failure'
28-
uses: buildsville/[email protected]
29-
with:
30-
token: ${{ secrets.GITHUB_TOKEN }}
31-
labels: "not following guidelines"
32-
type: add
33-
34-
- name: Remove 'not following guidelines' label
35-
if: needs.formalities.result == 'success'
36-
uses: buildsville/[email protected]
37-
with:
38-
token: ${{ secrets.GITHUB_TOKEN }}
39-
labels: "not following guidelines"
40-
type: remove
41-
4217
build:
4318
name: Feeds Package Test Build
4419
needs: formalities

0 commit comments

Comments
 (0)