Skip to content

Commit 5902526

Browse files
authored
Workflow for PR run checks to manage secret usage (#71)
* Workflow for PR run checks to manage secret usage * Use full permission check * Make check-run only for workflow calls and scan on targets * Check target * Preliminary needs * Keep target removed * Temporarily open up * Revert "Temporarily open up" This reverts commit 24c4e28. * Always run check * Allow PRs again, and check only on targets * Incremental for both PR events * Do not skip * Removal for final testing post-merge
1 parent 7e191c1 commit 5902526

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

.github/workflows/check-run.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Check PR run
2+
3+
on:
4+
workflow_call:
5+
6+
permissions: read-all
7+
8+
jobs:
9+
check:
10+
name: Check
11+
runs-on: ubuntu-22.04
12+
13+
steps:
14+
- name: Get user permission
15+
id: get-permission
16+
uses: actions-cool/check-user-permission@956b2e73cdfe3bcb819bb7225e490cb3b18fd76e # v2.2.1
17+
with:
18+
require: write
19+
username: ${{ github.triggering_actor }}
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- name: Check user permission
24+
if: steps.get-permission.outputs.require-result == 'false'
25+
run: |
26+
echo "User ${{ github.triggering_actor }} does not have the necessary access for this repository."
27+
echo "Current permission level is ${{ steps.get-permission.outputs.user-permission }}."
28+
echo "Job originally triggered by ${{ github.actor }}."
29+
exit 1

.github/workflows/scan.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,33 @@ on:
77
- "main"
88
- "rc"
99
- "hotfix-rc"
10-
pull_request:
10+
pull_request_target:
11+
types: [opened, synchronize]
1112

1213
permissions: read-all
1314

1415
jobs:
16+
check-run:
17+
name: Check PR run
18+
uses: ./.github/workflows/check-run.yml
19+
1520
sast:
1621
name: SAST scan
1722
runs-on: ubuntu-22.04
23+
needs: check-run
1824
permissions:
1925
security-events: write
2026

2127
steps:
2228
- name: Check out repo
2329
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
30+
with:
31+
ref: ${{ github.event.pull_request.head.sha }}
2432

2533
- name: Scan with Checkmarx
2634
uses: checkmarx/ast-github-action@749fec53e0db0f6404a97e2e0807c3e80e3583a7 #2.0.23
2735
env:
28-
INCREMENTAL: "${{ github.event_name == 'pull_request' && '--sast-incremental' || '' }}"
36+
INCREMENTAL: "${{ contains(github.event_name, 'pull_request') && '--sast-incremental' || '' }}"
2937
with:
3038
project_name: ${{ github.repository }}
3139
cx_tenant: ${{ secrets.CHECKMARX_TENANT }}
@@ -42,12 +50,14 @@ jobs:
4250
quality:
4351
name: Quality scan
4452
runs-on: ubuntu-22.04
53+
needs: check-run
4554

4655
steps:
4756
- name: Check out repo
4857
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
4958
with:
5059
fetch-depth: 0
60+
ref: ${{ github.event.pull_request.head.sha }}
5161

5262
- name: Scan with SonarCloud
5363
uses: sonarsource/sonarcloud-github-action@49e6cd3b187936a73b8280d59ffd9da69df63ec9 # v2.1.1

0 commit comments

Comments
 (0)