Skip to content

Commit aa69b1d

Browse files
Update code scan workflow
1 parent 78621fd commit aa69b1d

1 file changed

Lines changed: 152 additions & 3 deletions

File tree

Lines changed: 152 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,156 @@
11
name: DigiCert Code Scan
2-
on: workflow_dispatch
2+
3+
on:
4+
workflow_dispatch:
5+
36
jobs:
4-
noop:
7+
analyze:
8+
name: Analyze (${{ matrix.language }})
9+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
10+
11+
permissions:
12+
# required for all workflows
13+
security-events: write
14+
15+
# required to fetch internal or private CodeQL packs
16+
packages: read
17+
18+
# only required for workflows in private repositories
19+
actions: read
20+
contents: read
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
include:
26+
# - This will be replaced with the generated language and build mode content on runtime
27+
- language: Java
28+
build-mode: none
29+
- language: JavaScript
30+
build-mode: none
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
# Initializes the CodeQL tools for scanning.
36+
- name: Initialize CodeQL
37+
uses: github/codeql-action/init@v3
38+
with:
39+
languages: ${{ matrix.language }}
40+
build-mode: ${{ matrix.build-mode }}
41+
42+
- name: Perform CodeQL Analysis
43+
uses: github/codeql-action/analyze@v3
44+
with:
45+
category: '/language:${{matrix.language}}'
46+
upload: false
47+
output: "codeql-${{ matrix.language }}.sarif"
48+
49+
- name: Upload SARIF result as artifact
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: codeql-sarif-${{ matrix.language }}
53+
path: codeql-${{ matrix.language }}.sarif
54+
55+
gitleaks-analyze:
56+
name: Gitleaks Scan (SARIF)
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@v4
61+
with:
62+
fetch-depth: 0
63+
64+
- name: Install jq
65+
run: |
66+
sudo apt-get update -y
67+
sudo apt-get install -y jq
68+
69+
- name: Download Gitleaks and verify checksum
70+
env:
71+
GITLEAKS_VERSION: 8.18.4
72+
run: |
73+
curl -sSL -o gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz
74+
curl -sSL -o checksums.txt https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_checksums.txt
75+
grep "gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" checksums.txt | sha256sum -c -
76+
tar -xzf gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz
77+
chmod +x gitleaks && sudo mv gitleaks /usr/local/bin/gitleaks
78+
gitleaks version
79+
80+
- name: Run Gitleaks (SARIF output)
81+
run: |
82+
echo "Scanning commit: $(git rev-parse HEAD)"
83+
84+
SCAN_DIR=$(mktemp -d)
85+
trap 'rm -rf "$SCAN_DIR"' EXIT
86+
87+
git archive HEAD | tar -x -C "$SCAN_DIR"
88+
89+
gitleaks detect \
90+
--source "$SCAN_DIR" \
91+
--report-format sarif \
92+
--report-path gitleaks.sarif \
93+
--no-banner \
94+
--redact \
95+
--no-git || true
96+
97+
echo "Findings: $(jq '.runs[0].results | length' gitleaks.sarif)"
98+
99+
jq -r '.runs[0].results[]? |
100+
"\(.ruleId) \(.locations[0].physicalLocation.artifactLocation.uri):\(.locations[0].physicalLocation.region.startLine)"' \
101+
gitleaks.sarif || true
102+
103+
- name: Upload Gitleaks SARIF as artifact
104+
uses: actions/upload-artifact@v4
105+
with:
106+
name: gitleaks-sarif
107+
path: gitleaks.sarif
108+
109+
zip-sarif:
110+
name: Zip All SARIF Results
111+
runs-on: ubuntu-latest
112+
needs: [analyze, gitleaks-analyze]
113+
steps:
114+
- name: Download all SARIF artifacts
115+
uses: actions/download-artifact@v4
116+
with:
117+
# Grab both codeql and gitleaks SARIF artifacts for zipping
118+
pattern: "*-sarif*"
119+
path: ./sarif-results
120+
merge-multiple: true
121+
122+
- name: Zip SARIF results
123+
run: |
124+
cd sarif-results
125+
find . -name "*.sarif" -print | zip ../digicert_scan_results.zip -@
126+
127+
- name: Delete all SARIF files after zipping
128+
run: |
129+
find ./sarif-results -name "*.sarif" -delete
130+
131+
- name: Upload zipped SARIF results as artifact
132+
uses: actions/upload-artifact@v4
133+
with:
134+
name: digicert_scan_results
135+
path: digicert_scan_results.zip
136+
137+
sbom:
138+
name: Generate SBOM
5139
runs-on: ubuntu-latest
6140
steps:
7-
- run: echo "This is just a placeholder"
141+
- name: Checkout code
142+
uses: actions/checkout@v4
143+
144+
- name: Run Trivy to generate SBOM
145+
uses: aquasecurity/trivy-action@master
146+
with:
147+
scan-type: 'fs'
148+
format: 'cyclonedx'
149+
output: 'sbom-cdxgen.cyclonedx.json'
150+
151+
- name: Upload SBOM as artifact
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: sbom-cdxgen
155+
path: |
156+
sbom-cdxgen.cyclonedx.json

0 commit comments

Comments
 (0)