Skip to content

Commit 8127b00

Browse files
committed
fix: Use PRT to allow for WIF authentication on PRs from forks
1 parent 614d8b1 commit 8127b00

1 file changed

Lines changed: 61 additions & 25 deletions

File tree

.github/workflows/github_actions_scan.yml

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ on:
77
type: 'string'
88
zizmor_result_bucket:
99
type: 'string'
10-
pull_request:
10+
pull_request_target:
1111

1212
permissions: {}
1313

1414
env:
15+
ZIZMOR_VERSION: '1.24.1'
16+
ZIZMOR_DOCKER_DIGEST: 'sha256:128ebbe369a95f9d4427737e794537256095b55f779a247aebc960dc4ea1f7b3'
17+
ZIZMOR_ENFORCE: 'false'
18+
ZIZMOR_RESULT_BUCKET: 'zizmor-7165'
1519
WIF_PROVIDER: 'projects/102295818544/locations/global/workloadIdentityPools/gitsec-gha-artifacts/providers/gitsec-gha-artifacts-provider'
1620

1721
jobs:
@@ -25,6 +29,7 @@ jobs:
2529
- name: 'Checkout source'
2630
uses: 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' # ratchet:actions/checkout@v6
2731
with:
32+
ref: '${{ github.event.pull_request.head.sha }}'
2833
fetch-depth: 0
2934
persist-credentials: false
3035
- name: 'Check for workflow changes'
@@ -50,34 +55,27 @@ jobs:
5055
github.event_name == 'pull_request' &&
5156
!startsWith(github.workflow_ref, format('{0}/', github.repository))
5257
)
53-
env:
54-
ZIZMOR_VERSION: '1.24.1'
55-
ZIZMOR_DOCKER_DIGEST: 'sha256:128ebbe369a95f9d4427737e794537256095b55f779a247aebc960dc4ea1f7b3'
56-
ZIZMOR_ENFORCE: 'false'
57-
ZIZMOR_RESULT_BUCKET: 'zizmor-7165'
5858
permissions:
5959
contents: 'read'
60-
id-token: 'write'
60+
outputs:
61+
has-high-severity: '${{ steps.check-findings-severity.outputs.has-high-severity }}'
62+
zizmor-enforce: '${{ steps.check-findings-severity.outputs.zizmor-enforce }}'
6163
steps:
6264
- name: 'Checkout source'
6365
uses: 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' # ratchet:actions/checkout@v6
6466
with:
67+
ref: '${{ github.event.pull_request.head.sha }}'
6568
persist-credentials: false
66-
- name: 'Authenticate to GCP'
67-
uses: 'google-github-actions/auth@c200f3691d83b41bf9bbd8638997a462592937ed' # ratchet:google-github-actions/auth@v2
68-
with:
69-
workload_identity_provider: >-
70-
${{ inputs.wif_provider != '' && inputs.wif_provider || env.WIF_PROVIDER }}
71-
- name: 'Install zizmor'
72-
shell: 'bash'
73-
run: 'docker pull "ghcr.io/zizmorcore/zizmor:${ZIZMOR_VERSION}@${ZIZMOR_DOCKER_DIGEST}"'
7469
- name: 'Run zizmor'
7570
shell: 'bash'
71+
env:
72+
GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
7673
run: >-
7774
docker run
7875
--rm
7976
--volume "${GITHUB_WORKSPACE}:/workspace:ro"
8077
--workdir "/workspace"
78+
--env GH_TOKEN="${GH_TOKEN}"
8179
"ghcr.io/zizmorcore/zizmor:${ZIZMOR_VERSION}@${ZIZMOR_DOCKER_DIGEST}"
8280
--format sarif
8381
--
@@ -112,6 +110,36 @@ jobs:
112110
}
113111
]
114112
}' zizmor.sarif.json > enriched.sarif.json
113+
- name: 'Upload result'
114+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # ratchet:actions/upload-artifact@v7
115+
with:
116+
name: 'zizmor'
117+
path: 'enriched.sarif.json'
118+
if-no-files-found: 'error'
119+
retention-days: 1
120+
- name: 'Check for high severity findings'
121+
id: 'check-findings-severity'
122+
shell: 'bash'
123+
run: |
124+
result=$(jq 'any(.runs[].results[]?; .properties["zizmor/severity"] == "High")' zizmor.sarif.json)
125+
echo "has-high-severity=$result" >> "$GITHUB_OUTPUT"
126+
echo "zizmor-enforce=${ZIZMOR_ENFORCE}" >> "$GITHUB_OUTPUT"
127+
128+
zizmor-upload:
129+
needs: ['zizmor-scan']
130+
runs-on: 'ubuntu-latest'
131+
permissions:
132+
contents: 'read'
133+
id-token: 'write'
134+
steps:
135+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # ratchet:actions/download-artifact@v8
136+
with:
137+
name: 'zizmor'
138+
- name: 'Authenticate to GCP'
139+
uses: 'google-github-actions/auth@c200f3691d83b41bf9bbd8638997a462592937ed' # ratchet:google-github-actions/auth@v2
140+
with:
141+
workload_identity_provider: >-
142+
${{ inputs.wif_provider != '' && inputs.wif_provider || env.WIF_PROVIDER }}
115143
- name: 'Upload result'
116144
shell: 'bash'
117145
env:
@@ -122,23 +150,31 @@ jobs:
122150
gcloud storage cp
123151
enriched.sarif.json
124152
"gs://${ZIZMOR_RESULT_BUCKET}/${GITHUB_REPOSITORY}/${GITHUB_PULL_REQUEST_NUMBER}_${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}.sarif.json"
125-
- name: 'Check for high severity findings'
126-
id: 'check-findings-severity'
127-
shell: 'bash'
128-
run: |
129-
result=$(jq 'any(.runs[].results[]?; .properties["zizmor/severity"] == "High")' zizmor.sarif.json)
130-
echo "has_high=$result" >> "$GITHUB_OUTPUT"
153+
154+
zizmor-output:
155+
needs: ['zizmor-scan']
156+
runs-on: 'ubuntu-latest'
157+
permissions:
158+
contents: 'read'
159+
if: >-
160+
needs.zizmor-scan.outputs.zizmor-enforce == 'true' &&
161+
needs.zizmor-scan.outputs.has-high-severity == 'true'
162+
steps:
163+
- name: 'Checkout source'
164+
uses: 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' # ratchet:actions/checkout@v6
165+
with:
166+
ref: '${{ github.event.pull_request.head.sha }}'
167+
persist-credentials: false
131168
- name: 'Re-run zizmor with github format'
132-
if: >-
133-
steps.check-findings-severity.outputs.has_high == 'true'
134-
&&
135-
env.ZIZMOR_ENFORCE == 'true'
136169
shell: 'bash'
170+
env:
171+
GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
137172
run: >-
138173
docker run
139174
--rm
140175
--volume "${GITHUB_WORKSPACE}:/workspace:ro"
141176
--workdir "/workspace"
177+
--env GH_TOKEN="${GH_TOKEN}"
142178
"ghcr.io/zizmorcore/zizmor:${ZIZMOR_VERSION}@${ZIZMOR_DOCKER_DIGEST}"
143179
--format github
144180
--

0 commit comments

Comments
 (0)