Skip to content

Commit 94ecb71

Browse files
committed
ci(super-linter): stop Trivy from calling Maven Central
Maven Central answers "429 Too Many Requests" to Trivy's user agent from any IP, and Trivy 0.71.1 (shipped with super-linter v8.7.0) resolves parent and BOM POMs even when its vulnerability scanner is disabled, so every run aborted with a fatal error. Set TRIVY_OFFLINE_SCAN to stop Trivy issuing those requests, and restore the Maven workflow's dependency cache into the home directory that the super-linter container sees, so Trivy still resolves the full dependency tree from disk on the runs that scan for vulnerabilities. A cache miss now costs coverage (a warning) instead of failing the run.
1 parent f5c4e7f commit 94ecb71

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

‎.github/workflows/super-linter.yml‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,41 @@ jobs:
5959
fetch-depth: 0
6060
persist-credentials: false
6161

62+
#############################################################
63+
# Give Trivy a local Maven repository to resolve POMs from #
64+
# (see TRIVY_OFFLINE_SCAN below). Only the runs that enable #
65+
# Trivy's vulnerability scanner need it. #
66+
#############################################################
67+
- name: Restore Maven dependencies
68+
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
69+
# Same path and key as the Maven workflow, so this reuses the cache
70+
# that workflow saves. Restore only: this workflow never saves a
71+
# cache of its own.
72+
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
73+
with:
74+
path: .m2/repository
75+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
76+
restore-keys: |
77+
${{ runner.os }}-maven-
78+
79+
- name: Move Maven dependencies where Trivy looks for them
80+
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
81+
shell: bash
82+
run: |
83+
set -euo pipefail
84+
IFS=$'\n\t'
85+
if [ ! -d .m2/repository ]; then
86+
echo "No Maven cache restored: Trivy will report dependencies without their versions"
87+
exit 0
88+
fi
89+
# super-linter is a Docker action, and the runner mounts
90+
# "${RUNNER_TEMP}/_github_home" as the home directory inside the
91+
# container, which is where Trivy looks for .m2/repository. Moving
92+
# the dependencies out of the workspace also keeps Trivy from
93+
# scanning the cached jars themselves.
94+
mkdir -p "${RUNNER_TEMP}/_github_home/.m2"
95+
mv .m2/repository "${RUNNER_TEMP}/_github_home/.m2/repository"
96+
6297
################################
6398
# Run Linter against code base #
6499
################################
@@ -76,6 +111,17 @@ jobs:
76111
JAVA_FILE_NAME: google_checks.xml
77112
LINTER_RULES_PATH: .
78113
SAVE_SUPER_LINTER_SUMMARY: true
114+
# Trivy's pom.xml analyzer resolves parent and BOM POMs from Maven
115+
# Central even when the vuln scanner is off (Trivy 0.71.1, shipped
116+
# with super-linter v8.7.0), and Maven Central answers "429 Too Many
117+
# Requests" to Trivy's user agent from any IP, which aborts the whole
118+
# run. Keep this unconditional rather than tying it to TRIVY_SCANNERS
119+
# below: the runs that enable the vuln scanner get the same 429, so
120+
# online resolution never succeeds there either. Trivy still resolves
121+
# parent and BOM POMs from the local repository restored above, and a
122+
# cache miss only costs coverage (a warning) instead of failing the
123+
# run.
124+
TRIVY_OFFLINE_SCAN: true
79125
TRIVY_SCANNERS: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && 'vuln,misconfig,secret' || 'misconfig,secret'}}
80126
VALIDATE_ALL_CODEBASE: true
81127
# Only lint commit messages when the run was triggered by a commit

0 commit comments

Comments
 (0)