-
Notifications
You must be signed in to change notification settings - Fork 0
279 lines (239 loc) · 10.3 KB
/
Copy pathdependency-scan.yml
File metadata and controls
279 lines (239 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: Dependency Vulnerability Scan
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
# Run weekly on Monday at 6 AM UTC to catch newly disclosed vulnerabilities
- cron: '0 6 * * 1'
workflow_dispatch:
permissions:
contents: read
issues: write
pull-requests: write
security-events: write
jobs:
# ──────────────────────────────────────────────
# Maven (Desktop) - OWASP Dependency-Check
# ──────────────────────────────────────────────
maven-dependency-check:
name: Maven OWASP Dependency-Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Cache NVD database
uses: actions/cache@v4
with:
path: ~/.m2/repository/org/owasp/dependency-check-data
key: ${{ runner.os }}-nvd-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-nvd-
- name: Run OWASP Dependency-Check
id: owasp
continue-on-error: true
run: |
mvn dependency-check:check -B \
-DfailBuildOnCVSS=9 \
-DskipTests \
2>&1 | tee owasp-output.log
echo "exit_code=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT
env:
NVD_API_KEY: ${{ secrets.NVD_API_KEY }}
- name: Parse OWASP results
if: always()
id: parse-owasp
run: |
if [ -f target/dependency-check-report.xml ]; then
TOTAL=$(grep -c '<vulnerability' target/dependency-check-report.xml 2>/dev/null || echo "0")
CRITICAL=$(grep -c 'severity="CRITICAL"' target/dependency-check-report.xml 2>/dev/null || echo "0")
HIGH=$(grep -c 'severity="HIGH"' target/dependency-check-report.xml 2>/dev/null || echo "0")
MEDIUM=$(grep -c 'severity="MEDIUM"' target/dependency-check-report.xml 2>/dev/null || echo "0")
LOW=$(grep -c 'severity="LOW"' target/dependency-check-report.xml 2>/dev/null || echo "0")
else
TOTAL=0
CRITICAL=0
HIGH=0
MEDIUM=0
LOW=0
fi
echo "total=${TOTAL}" >> $GITHUB_OUTPUT
echo "critical=${CRITICAL}" >> $GITHUB_OUTPUT
echo "high=${HIGH}" >> $GITHUB_OUTPUT
echo "medium=${MEDIUM}" >> $GITHUB_OUTPUT
echo "low=${LOW}" >> $GITHUB_OUTPUT
echo "## Maven Dependency-Check Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Severity | Count |" >> $GITHUB_STEP_SUMMARY
echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Critical | ${CRITICAL} |" >> $GITHUB_STEP_SUMMARY
echo "| High | ${HIGH} |" >> $GITHUB_STEP_SUMMARY
echo "| Medium | ${MEDIUM} |" >> $GITHUB_STEP_SUMMARY
echo "| Low | ${LOW} |" >> $GITHUB_STEP_SUMMARY
echo "| **Total** | **${TOTAL}** |" >> $GITHUB_STEP_SUMMARY
- name: Upload OWASP report
if: always()
uses: actions/upload-artifact@v4
with:
name: maven-dependency-check-report
path: |
target/dependency-check-report.html
target/dependency-check-report.xml
target/dependency-check-report.json
retention-days: 30
- name: Comment on PR
if: github.event_name == 'pull_request' && always()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const total = '${{ steps.parse-owasp.outputs.total }}';
const critical = '${{ steps.parse-owasp.outputs.critical }}';
const high = '${{ steps.parse-owasp.outputs.high }}';
const medium = '${{ steps.parse-owasp.outputs.medium }}';
const low = '${{ steps.parse-owasp.outputs.low }}';
const hasIssues = parseInt(critical) > 0 || parseInt(high) > 0;
const comment = `## Dependency Vulnerability Scan (Maven)
| Severity | Count |
|----------|-------|
| Critical | ${critical} |
| High | ${high} |
| Medium | ${medium} |
| Low | ${low} |
| **Total** | **${total}** |
${hasIssues ? '**Action Required:** Critical or high vulnerabilities found. Review the dependency-check report artifact.' : 'No critical or high vulnerabilities found.'}
<details>
<summary>View Details</summary>
Download the \`maven-dependency-check-report\` artifact for the full HTML report.
To run locally: \`mvn dependency-check:check\`
Report: \`target/dependency-check-report.html\`
</details>
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Create issue for critical vulnerabilities
if: |
always() &&
github.event_name == 'schedule' &&
(steps.parse-owasp.outputs.critical > 0 || steps.parse-owasp.outputs.high > 0)
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const critical = '${{ steps.parse-owasp.outputs.critical }}';
const high = '${{ steps.parse-owasp.outputs.high }}';
const total = '${{ steps.parse-owasp.outputs.total }}';
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'security,dependency-vulnerability',
state: 'open'
});
if (issues.data.length === 0) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Security: Maven dependency vulnerabilities detected',
labels: ['security', 'dependency-vulnerability', 'automated', 'priority-high'],
body: `## Dependency Vulnerability Scan Results
**Scan Date:** ${new Date().toISOString().split('T')[0]}
**Total Vulnerabilities:** ${total}
- Critical: ${critical}
- High: ${high}
### Action Required
1. Run \`mvn dependency-check:check\` locally
2. Review \`target/dependency-check-report.html\`
3. Update affected dependencies or add justified suppressions
### Quick Commands
\`\`\`bash
# Check for available updates
mvn versions:display-dependency-updates
# Run vulnerability scan
mvn dependency-check:check
# View report
open target/dependency-check-report.html
\`\`\`
---
_Automatically created by the Dependency Vulnerability Scan workflow._
_Workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}_
`
});
}
# ──────────────────────────────────────────────
# Gradle (Core + Android) - Dependency submission
# ──────────────────────────────────────────────
gradle-dependency-submission:
name: Gradle Dependency Submission
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle
- name: Submit Gradle dependencies
uses: mikepenz/gradle-dependency-submission@v1
with:
gradle-build-module: |-
:jnexus-core
gradle-build-configuration: |-
runtimeClasspath
# ──────────────────────────────────────────────
# SBOM Generation and Upload
# ──────────────────────────────────────────────
sbom-generation:
name: Generate SBOM
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Generate CycloneDX SBOM
run: mvn cyclonedx:makeAggregateBom -DskipTests -B
- name: Upload SBOM artifacts
uses: actions/upload-artifact@v4
with:
name: sbom
path: |
target/jnexus-sbom.json
target/jnexus-sbom.xml
retention-days: 90
# ──────────────────────────────────────────────
# Summary
# ──────────────────────────────────────────────
scan-summary:
name: Scan Summary
runs-on: ubuntu-latest
needs: [maven-dependency-check]
if: always()
steps:
- name: Create summary
run: |
echo "## Dependency Vulnerability Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Scan | Status |" >> $GITHUB_STEP_SUMMARY
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Maven OWASP Dependency-Check | ${{ needs.maven-dependency-check.result }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "For detailed reports, download the artifacts from this workflow run." >> $GITHUB_STEP_SUMMARY