-
-
Notifications
You must be signed in to change notification settings - Fork 974
186 lines (183 loc) Β· 8.52 KB
/
Copy pathvulnerability-scan.yml
File metadata and controls
186 lines (183 loc) Β· 8.52 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
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: "Vulnerability Scan"
on:
schedule:
# Run every Monday at 03:00 UTC
- cron: '0 3 * * 1'
workflow_dispatch:
# Opt in per pull request by applying the "vulnerability scan" label. Applying a label
# requires write access, so only a committer can start a scan.
pull_request:
types: [labeled, synchronize, reopened]
# Used only to tell a fork pull request that it cannot be scanned. A `pull_request` run
# raised from a fork gets neither the Sonatype credentials nor a token that can comment,
# so the notice has to come from `pull_request_target`. That job checks out the base
# branch and never runs anything from the pull request.
pull_request_target:
types: [labeled, synchronize, reopened]
# Do not scan concurrently; OSS Index has per-account rate limits.
# The event name is part of the group so the `pull_request` scan and the `pull_request_target`
# notice for the same pull request cannot cancel one another.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
jobs:
scan-grails-core:
name: "OSS Index Scan - grails-core"
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: "π₯ Checkout repository"
uses: actions/checkout@v6
- name: "βοΈ Determine Java version from .sdkmanrc"
# Read the JDK the build targets out of the file that already declares it, so a
# baseline bump does not leave a stale literal behind here. Only the major is kept:
# a scan is outside the reproducible-build surface, so CI takes the runner's current
# release of that major rather than pinning the patch version.
id: sdkmanrc
run: |
set -euo pipefail
sdkman_java=$(grep -E '^java=' .sdkmanrc | cut -d= -f2 || true)
if [ -z "${sdkman_java}" ]; then
echo "β Could not determine the java version from .sdkmanrc" >&2
exit 1
fi
echo "Scanning with JDK ${sdkman_java%%.*} (from .sdkmanrc: ${sdkman_java})"
echo "java-version=${sdkman_java%%.*}" >> "$GITHUB_OUTPUT"
- name: "βοΈ Setup JDK"
uses: actions/setup-java@v4
with:
distribution: liberica
java-version: ${{ steps.sdkmanrc.outputs.java-version }}
- name: "π Setup Gradle"
uses: gradle/actions/setup-gradle@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e # v6.1.0
with:
develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
- name: "π Run OSS Index Vulnerability Scan"
env:
SONATYPE_GUIDE_USERNAME: ${{ secrets.SONATYPE_GUIDE_USERNAME }}
SONATYPE_GUIDE_TOKEN: ${{ secrets.SONATYPE_GUIDE_TOKEN }}
continue-on-error: true
id: scan
run: ./gradlew ossIndexAudit --continue --info 2>&1 | tee /tmp/ossindex-scan.log; exit ${PIPESTATUS[0]}
- name: "π Publish Vulnerability Summary"
if: always()
run: >
.github/scripts/ossIndexReport.sh
/tmp/ossindex-scan.log
'${{ steps.scan.outcome }}'
'π OSS Index Vulnerability Scan β grails-core'
>> $GITHUB_STEP_SUMMARY
scan-pull-request:
name: "OSS Index Scan - pull request"
# `synchronize` and `reopened` re-scan a pull request that already carries the label.
if: >-
github.event_name == 'pull_request'
&& contains(github.event.pull_request.labels.*.name, 'vulnerability scan')
&& github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-24.04
permissions:
contents: read
pull-requests: write
steps:
- name: "π₯ Checkout pull request"
uses: actions/checkout@v6
- name: "βοΈ Determine Java version from .sdkmanrc"
# Read the JDK the build targets out of the file that already declares it, so a
# baseline bump does not leave a stale literal behind here. Only the major is kept:
# a scan is outside the reproducible-build surface, so CI takes the runner's current
# release of that major rather than pinning the patch version.
id: sdkmanrc
run: |
set -euo pipefail
sdkman_java=$(grep -E '^java=' .sdkmanrc | cut -d= -f2 || true)
if [ -z "${sdkman_java}" ]; then
echo "β Could not determine the java version from .sdkmanrc" >&2
exit 1
fi
echo "Scanning with JDK ${sdkman_java%%.*} (from .sdkmanrc: ${sdkman_java})"
echo "java-version=${sdkman_java%%.*}" >> "$GITHUB_OUTPUT"
- name: "βοΈ Setup JDK"
uses: actions/setup-java@v4
with:
distribution: liberica
java-version: ${{ steps.sdkmanrc.outputs.java-version }}
- name: "π Setup Gradle"
uses: gradle/actions/setup-gradle@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e # v6.1.0
with:
develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
- name: "π Run OSS Index Vulnerability Scan"
env:
SONATYPE_GUIDE_USERNAME: ${{ secrets.SONATYPE_GUIDE_USERNAME }}
SONATYPE_GUIDE_TOKEN: ${{ secrets.SONATYPE_GUIDE_TOKEN }}
continue-on-error: true
id: scan
run: ./gradlew ossIndexAudit --continue --info 2>&1 | tee /tmp/ossindex-scan.log; exit ${PIPESTATUS[0]}
- name: "π Build Vulnerability Report"
if: always()
# 60000 bytes keeps the listing clear of GitHub's 65536 character comment limit.
run: >
.github/scripts/ossIndexReport.sh
/tmp/ossindex-scan.log
'${{ steps.scan.outcome }}'
'π OSS Index Vulnerability Scan β pull request'
60000
> /tmp/ossindex-report.md
- name: "π Publish Vulnerability Summary"
if: always()
run: cat /tmp/ossindex-report.md >> $GITHUB_STEP_SUMMARY
- name: "π¬ Comment Vulnerability Report"
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
.github/scripts/postStickyComment.sh
'${{ github.event.pull_request.number }}'
'<!-- grails-vulnerability-scan -->'
/tmp/ossindex-report.md
notify-fork-pull-request:
name: "OSS Index Scan - unavailable"
# A fork pull request cannot reach the Sonatype credentials, so say so instead of
# leaving the label looking as though a scan ran.
if: >-
github.event_name == 'pull_request_target'
&& contains(github.event.pull_request.labels.*.name, 'vulnerability scan')
&& github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-24.04
permissions:
pull-requests: write
steps:
# Checks out the base branch, not the pull request; nothing from the fork is executed.
- name: "π₯ Checkout base branch"
uses: actions/checkout@v6
- name: "π Build Notice"
run: |
{
echo "## π OSS Index Vulnerability Scan β pull request"
echo "β οΈ Vulnerability scanning is not available because this branch is not on \`${{ github.repository }}\`."
echo
echo "The scan needs Sonatype Guide credentials, which GitHub withholds from workflow runs raised by a fork. Push the branch to \`${{ github.repository }}\` and open a pull request from there to have it scanned."
} > /tmp/ossindex-report.md
- name: "π¬ Comment Notice"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
.github/scripts/postStickyComment.sh
'${{ github.event.pull_request.number }}'
'<!-- grails-vulnerability-scan -->'
/tmp/ossindex-report.md