Running a Harbor Trivy image scan in offline mode fails with the following error:
DEBUG No plugins loadedDEBUG Default config file "trivy.yaml" not found, using built-in valuesDEBUG Cache dir dir="~/.cache/trivy"DEBUG Cache dir dir="~/.cache/trivy"DEBUG Parsed severities severities=[UNKNOWN LOW MEDIUM HIGH CRITICAL]DEBUG Ignore statuses statuses=[]DEBUG [vulndb] Skipping DB update...ERROR The local DB has an old schema version which is not supported by the current version of Trivy CLI. DB needs to be updated.FATAL Fatal error - init error: github.com/aquasecurity/trivy/pkg/commands/artifact.Run - DB error: github.com/aquasecurity/trivy/pkg/commands/artifact.NewRunner - database error: github.com/aquasecurity/trivy/pkg/commands/operation.DownloadDB - validate error: github.com/aquasecurity/trivy/pkg/db.(*Client).NeedsUpdate - --skip-update cannot be specified with the old DB schema. Local DB: 1, Expected: 2 github.com/aquasecurity/trivy/pkg/db.(*Client).validate
{"Version":1,"Type":1,"NextUpdate":"xxxx-xx-xxT18:48:16.989777438Z","UpdatedAt":"xxxx-xx-xxT12:48:16.989777838Z","DownloadedAt":"0001-01-01T00:00:00Z"}VMware vCenter Server 8.x
vSphere with Tanzu 8.x
Trivy’s local vulnerability database is outdated.
The environment is still using Trivy DB Version 1.
DB v1 reached end of support in February 2023, and all current Trivy releases require DB Version 2.
Download the Trivy Vulnerability DB on a Jumpbox (with internet)
# Install Trivy binarycurl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.58.0
# Create a temporary directoryTRIVY_TEMP_DIR=$(mktemp -d)
# Download the DBtrivy --cache-dir $TRIVY_TEMP_DIR image --download-db-only
# Adjust permissionschmod o+r $TRIVY_TEMP_DIR/db/metadata.jsonchmod o+r $TRIVY_TEMP_DIR/db/trivy.db
Transfer the DB Into the Air-Gapped Environment and verify
#STEP 1 — Identify the Trivy scanner pod
NS=$(kubectl get ns | grep -E 'vmware-system|registry' | awk '{print $1}')POD=$(kubectl -n $NS get pod -l component=trivy -o jsonpath="{.items[0].metadata.name}")
#STEP 2 — Create the Trivy DB cache directory inside the pod
kubectl -n $NS exec $POD -- mkdir -p /home/scanner/.cache/trivy/db
#STEP 3 — Copy the downloaded trivy-data.db and metadata.json into the pod
cat $TRIVY_TEMP_DIR/db/metadata.json | kubectl -n $NS exec $POD -i -- tee /home/scanner/.cache/trivy/db/metadata.json >/dev/nullcat $TRIVY_TEMP_DIR/db/trivy-data.db | kubectl -n $NS exec $POD -i -- tee /home/scanner/.cache/trivy/db/trivy-data.db >/dev/null
#STEP 4 — Verify the DB files exist
kubectl -n $NS exec $POD -- ls -l /home/scanner/.cache/trivy/db