Skip to content

Commit 8cfe3e2

Browse files
authored
feat: Add github_actions_scan workflow. (#1)
1 parent 89191f2 commit 8cfe3e2

1 file changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: 'GitHub Actions Scan'
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
wif_provider:
7+
type: 'string'
8+
zizmor_result_bucket:
9+
type: 'string'
10+
pull_request:
11+
paths:
12+
- '.github/workflows/*.yml'
13+
- '.github/workflows/*.yaml'
14+
15+
permissions:
16+
contents: 'read'
17+
id-token: 'write'
18+
19+
env:
20+
WIF_PROVIDER: 'projects/102295818544/locations/global/workloadIdentityPools/gitsec-gha-artifacts/providers/gitsec-gha-artifacts-provider'
21+
22+
jobs:
23+
zizmor-scan:
24+
runs-on: 'ubuntu-latest'
25+
if: >-
26+
inputs.wif_provider != '' ||
27+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
28+
env:
29+
ZIZMOR_VERSION: '1.24.1'
30+
ZIZMOR_DOCKER_DIGEST: 'sha256:128ebbe369a95f9d4427737e794537256095b55f779a247aebc960dc4ea1f7b3'
31+
ZIZMOR_ENFORCE: 'false'
32+
ZIZMOR_RESULT_BUCKET: 'zizmor-7165'
33+
steps:
34+
- name: 'Checkout source'
35+
uses: 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' # ratchet:actions/checkout@v6
36+
with:
37+
persist-credentials: false
38+
- name: 'Authenticate to GCP'
39+
uses: 'google-github-actions/auth@c200f3691d83b41bf9bbd8638997a462592937ed' # ratchet:google-github-actions/auth@v2
40+
with:
41+
workload_identity_provider: >-
42+
${{ inputs.wif_provider != '' && inputs.wif_provider || env.WIF_PROVIDER }}
43+
- name: 'Install zizmor'
44+
shell: 'bash'
45+
run: 'docker pull "ghcr.io/zizmorcore/zizmor:${{ env.ZIZMOR_VERSION }}@${{ env.ZIZMOR_DOCKER_DIGEST }}"'
46+
- name: 'Run zizmor'
47+
shell: 'bash'
48+
run: >-
49+
docker run
50+
--rm
51+
--volume "${GITHUB_WORKSPACE}:/workspace:ro"
52+
--workdir "/workspace"
53+
"ghcr.io/zizmorcore/zizmor:${{ env.ZIZMOR_VERSION }}@${{ env.ZIZMOR_DOCKER_DIGEST }}"
54+
--format sarif
55+
--
56+
.github/workflows
57+
> zizmor.sarif.json
58+
- name: 'Enrich SARIF with GitHub metadata'
59+
shell: 'bash'
60+
run: >-
61+
jq
62+
--arg uri "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
63+
--arg sha "${GITHUB_SHA}"
64+
--argjson repo_id "${GITHUB_REPOSITORY_ID}"
65+
--argjson owner_id "${GITHUB_REPOSITORY_OWNER_ID}"
66+
--arg run_id "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/attempts/${GITHUB_RUN_ATTEMPT}"
67+
'.runs[] |= . + {
68+
"versionControlProvenance": [
69+
{
70+
"repositoryUri": $uri,
71+
"revisionId": $sha,
72+
"properties": {
73+
"github_repository_id": $repo_id,
74+
"github_owner_id": $owner_id
75+
}
76+
}
77+
],
78+
"invocations": [
79+
{
80+
"executionId": $run_id,
81+
"executionSuccessful": true
82+
}
83+
]
84+
}' zizmor.sarif.json > enriched.sarif.json
85+
- name: 'Upload result'
86+
shell: 'bash'
87+
env:
88+
GITHUB_PULL_REQUEST_NUMBER: '${{ github.event.pull_request.number }}'
89+
ZIZMOR_RESULT_BUCKET: >-
90+
${{ inputs.zizmor_result_bucket != '' && inputs.zizmor_result_bucket || env.ZIZMOR_RESULT_BUCKET }}
91+
run: >-
92+
gcloud storage cp
93+
enriched.sarif.json
94+
"gs://${ZIZMOR_RESULT_BUCKET}/${GITHUB_REPOSITORY}/${GITHUB_PULL_REQUEST_NUMBER}_${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}.sarif.json"
95+
- name: 'Check for high severity findings'
96+
id: 'check-findings-severity'
97+
shell: 'bash'
98+
run: |
99+
result=$(jq 'any(.runs[].results[]?; .properties["zizmor/severity"] == "High")' zizmor.sarif.json)
100+
echo "has_high=$result" >> "$GITHUB_OUTPUT"
101+
- name: 'Re-run zizmor with github format'
102+
if: >-
103+
steps.check-findings-severity.outputs.has_high == 'true'
104+
&&
105+
env.ZIZMOR_ENFORCE == 'true'
106+
shell: 'bash'
107+
run: >-
108+
docker run
109+
--rm
110+
--volume "${GITHUB_WORKSPACE}:/workspace:ro"
111+
--workdir "/workspace"
112+
"ghcr.io/zizmorcore/zizmor:${{ env.ZIZMOR_VERSION }}@${{ env.ZIZMOR_DOCKER_DIGEST }}"
113+
--format github
114+
--
115+
.github/workflows

0 commit comments

Comments
 (0)