Skip to content

Commit

Permalink
Try to use pull_request_target-triggered actions in a secure way, giv…
Browse files Browse the repository at this point in the history
…en those actions have access to repo secrets
  • Loading branch information
crew102 committed Dec 28, 2024
1 parent 1972fca commit 145e958
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
on: [push, pull_request]

# Details on pull_request_target and why it's insecure:
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
# Post describing a workaround, from which we take inspiration:
# https://michaelheap.com/access-secrets-from-forks/

name: R-CMD-check

on:
push:
branches:
- master
- 'feature/**'
- 'bugfix/**'
pull_request_target:
types: [opened, synchronize]

jobs:
pre-check:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
steps:
- name: Confirm crew102 triggered the build for the PR
run: |
if [ "${{ github.actor }}" == "crew102" ]; then
echo "Actor is crew102"
else
echo "Actor is ${{ github.actor }}, failing build."
exit 1
fi
R-CMD-check:
needs: [pre-check]
runs-on: ${{ matrix.config.os }}

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

steps:
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v3
with:
# Use the head SHA for pull requests
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- uses: r-lib/actions/setup-r@v1
with:
Expand Down

0 comments on commit 145e958

Please sign in to comment.