Skip to content

Commit 145e958

Browse files
committed
Try to use pull_request_target-triggered actions in a secure way, given those actions have access to repo secrets
1 parent 1972fca commit 145e958

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

.github/workflows/R-CMD-check.yaml

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
22
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
3-
on: [push, pull_request]
3+
4+
# Details on pull_request_target and why it's insecure:
5+
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
6+
# Post describing a workaround, from which we take inspiration:
7+
# https://michaelheap.com/access-secrets-from-forks/
48

59
name: R-CMD-check
610

11+
on:
12+
push:
13+
branches:
14+
- master
15+
- 'feature/**'
16+
- 'bugfix/**'
17+
pull_request_target:
18+
types: [opened, synchronize]
19+
720
jobs:
21+
pre-check:
22+
if: github.event_name == 'pull_request_target'
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Confirm crew102 triggered the build for the PR
26+
run: |
27+
if [ "${{ github.actor }}" == "crew102" ]; then
28+
echo "Actor is crew102"
29+
else
30+
echo "Actor is ${{ github.actor }}, failing build."
31+
exit 1
32+
fi
33+
834
R-CMD-check:
35+
needs: [pre-check]
936
runs-on: ${{ matrix.config.os }}
1037

1138
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
@@ -29,7 +56,11 @@ jobs:
2956
PATENTSVIEW_API_KEY: ${{ secrets.PATENTSVIEW_API_KEY }}
3057

3158
steps:
32-
- uses: actions/checkout@v2
59+
- name: Checkout code
60+
uses: actions/checkout@v3
61+
with:
62+
# Use the head SHA for pull requests
63+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
3364

3465
- uses: r-lib/actions/setup-r@v1
3566
with:

0 commit comments

Comments
 (0)