Skip to content

Commit e7b59cc

Browse files
committed
Use pull_request_target instead of pull_request
The pull_request didn't allowed us to run a CI for external contributions due to access restriction to secrets. The pull_request_target should allow it. However a new gating mechanism is need to prevent attackers from leaking a secrets. This commit adds a new gated environment that is required for PR coming from forks. Signed-off-by: Ales Raszka <araszka@redhat.com>
1 parent 98c2492 commit e7b59cc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.github/workflows/build-and-test.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: # yamllint disable-line rule:truthy
55
push:
66
branches:
77
- main
8-
pull_request:
8+
pull_request_target:
99
types: [opened, synchronize, reopened, labeled]
1010
workflow_dispatch:
1111

@@ -17,6 +17,8 @@ jobs:
1717
steps:
1818
- name: Checkout repository
1919
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
20+
with:
21+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
2022

2123
- name: Set up PDM
2224
uses: pdm-project/setup-pdm@94a823180e06fcde4ad29308721954a521c96ed0 # v4.4
@@ -45,6 +47,7 @@ jobs:
4547
build:
4648
name: Build and push image
4749
runs-on: ubuntu-latest
50+
environment: ${{ github.event.pull_request.head.repo.fork && 'build-and-test' || '' }}
4851

4952
steps:
5053
- name: Set variables
@@ -56,6 +59,8 @@ jobs:
5659
echo "tags=${{ github.sha }}">> $GITHUB_OUTPUT
5760
fi
5861
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
62+
with:
63+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
5964

6065
- name: Build Image
6166
id: build-image
@@ -95,6 +100,8 @@ jobs:
95100
runs-on: ubuntu-latest
96101
steps:
97102
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
103+
with:
104+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
98105

99106
- name: Prepare
100107
id: prepare

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ running OCP cluster and requires some resources a tests are execute only when
212212
workflow.
213213

214214
All PRs should pass a tests before merging.
215+
216+
### CI/CD for external contributors
217+
The repository contains Github Actions workflows that automatically run all
218+
CI steps including linting, building and testing the operator pipelines.
219+
220+
In case of a pull request from a forked repository the tests are not executed
221+
automatically due to security reasons. To run the tests an owner of the repository
222+
must review the pull request to make sure it doesn't contain any malicious code
223+
then approve the `build-and-test` workflow environment.
224+
225+
The manuall approval is not needed for contributors who have write access to the
226+
repository and not using a forked repository.
227+
228+
215229
## Additional Documentation
216230

217231
- [OpenShift cluster configuration](docs/cluster-config.md)

0 commit comments

Comments
 (0)