jerryshao commented on code in PR #14778: URL: https://github.com/apache/gravitino/pull/14778#discussion_r4550175173
########## .github/workflows/cve-scan.yml: ########## @@ -0,0 +1,384 @@ +# +# 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 +# +# http://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: CVE Scan + +# Weekly Trivy scan of the artifacts Gravitino ships. See .github/trivy/README.md for what is +# scanned, how to run the same scan locally and how exemptions work. +# +# A target (one shipped artifact) fails when a HIGH or CRITICAL finding remains after the +# exemptions in .github/trivy are applied, or when Trivy produced no valid report. Expired +# exemptions bring their findings back, so a red run is also the reminder to re-triage them. +# A failed scheduled run opens (or updates) one tracking issue, which the first passing scheduled +# run closes again (job 'notify'). +# +# Every upload step uses 'if-no-files-found: warn'. A report is missing only after an earlier step +# of the same job failed (scan.sh fails closed), and that step already fails the job. Using 'error' +# would add a second, confusing failure to the same run. +on: + schedule: + - cron: '0 3 * * 1' # Mondays 03:00 UTC + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: cve-scan-${{ github.ref }} + cancel-in-progress: false + +env: + TRIVY_REPORT_DIR: ${{ github.workspace }}/trivy-reports + TARGET_DIR: ${{ github.workspace }}/trivy-targets + +jobs: + # Downloads the vulnerability DBs once per run. The scan jobs restore them read-only and run + # without network access. + trivy-db: + name: Trivy DB + # Forks can start the workflow manually, but only apache/gravitino runs the schedule. + if: github.event_name != 'schedule' || github.repository == 'apache/gravitino' + runs-on: ubuntu-latest + timeout-minutes: 20 + outputs: + cache-key: ${{ steps.key.outputs.cache-key }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Compute the cache key once for the whole run + id: key + run: echo "cache-key=trivy-db-v1-$(date -u +%Y-%m-%d)" >> "${GITHUB_OUTPUT}" + - name: Restore the DB cache + id: cache + uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 + with: + path: ~/.cache/trivy + key: ${{ steps.key.outputs.cache-key }} + - name: Download the DBs + if: steps.cache.outputs.cache-hit != 'true' + run: | + .github/trivy/scan.sh pull + .github/trivy/scan.sh download-db + - name: Record the DB snapshot + run: .github/trivy/scan.sh db-info + + server: + name: Server packages + if: github.event_name != 'schedule' || github.repository == 'apache/gravitino' + needs: trivy-db + runs-on: ubuntu-latest + timeout-minutes: 90 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: ./.github/actions/setup-java-toolchains + - name: Free up disk space + run: dev/ci/util_free_space.sh + - name: Restore the DB cache + uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 + with: + path: ~/.cache/trivy + key: ${{ needs.trivy-db.outputs.cache-key }} + fail-on-cache-miss: true + - name: Pull the Trivy image + run: .github/trivy/scan.sh pull + # The web UI is not built: its WAR holds a minified static export that Trivy cannot inspect. + # Its lock files are scanned in the lockfiles job (see .github/trivy/README.md). + - name: Build the server packages + run: ./gradlew compileDistribution compileIcebergRESTServer compileLanceRESTServer -PskipWeb=true -x test + # The standalone REST server directories hold the same third-party jars as the copies in + # distribution/package; they are scanned too so that each shipped package has its own report. + - name: Scan + run: | + rc=0 + .github/trivy/scan.sh scan server-distribution distribution/package || rc=1 + .github/trivy/scan.sh scan iceberg-rest-server distribution/gravitino-iceberg-rest-server || rc=1 + .github/trivy/scan.sh scan lance-rest-server distribution/gravitino-lance-rest-server || rc=1 + exit "${rc}" + - name: Upload the reports + if: ${{ !cancelled() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: cve-scan-server + path: ${{ env.TRIVY_REPORT_DIR }} + retention-days: 30 + if-no-files-found: warn + + # Every separately distributed fat jar. Each jar is staged in its own directory and scanned as + # its own target, so findings stay attributable to the artifact users download. + jars: + name: Shaded jars + if: github.event_name != 'schedule' || github.repository == 'apache/gravitino' + needs: trivy-db + runs-on: ubuntu-latest + timeout-minutes: 90 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: ./.github/actions/setup-java-toolchains + - name: Free up disk space + run: dev/ci/util_free_space.sh + - name: Restore the DB cache + uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 + with: + path: ~/.cache/trivy + key: ${{ needs.trivy-db.outputs.cache-key }} + fail-on-cache-miss: true + - name: Pull the Trivy image + run: .github/trivy/scan.sh pull + - name: Build the fat jars + run: | + ./gradlew -PskipWeb=true \ + :bundles:aws-bundle:shadowJar :bundles:gcp-bundle:shadowJar \ + :bundles:azure-bundle:shadowJar :bundles:aliyun-bundle:shadowJar \ + :bundles:tencent-bundle:shadowJar :bundles:iceberg-aws-bundle:shadowJar \ + :bundles:iceberg-gcp-bundle:shadowJar :bundles:iceberg-azure-bundle:shadowJar \ + :bundles:iceberg-aliyun-bundle:shadowJar \ + :clients:client-java-runtime:shadowJar :clients:filesystem-hadoop3-runtime:shadowJar \ + :maintenance:jobs:shadowJar \ + :flink-connector:flink-runtime-1.19:shadowJar :flink-connector:flink-runtime-1.20:shadowJar \ + :flink-connector:flink-runtime-2.1:shadowJar :flink-connector:flink-runtime-2.2:shadowJar \ + :spark-connector:spark-runtime-3.5:shadowJar :spark-connector:spark-runtime-4.0:shadowJar + # The Spark 3.5 runtime is also released for Scala 2.13. Spark 4.0 is Scala 2.13 only. + - name: Build the Spark 3.5 runtime for Scala 2.13 + run: ./gradlew -PskipWeb=true -PscalaVersion=2.13 :spark-connector:spark-runtime-3.5:shadowJar + # Every jar is staged even if another one cannot be found, and the step fails at the end. The + # Scan step then still scans and reports what was staged. + - name: Stage one directory per jar + id: stage + run: | + rc=0 + stage() { .github/trivy/scan.sh stage "${TARGET_DIR}" "$@" || rc=1; } + for cloud in aws gcp azure aliyun tencent iceberg-aws iceberg-gcp iceberg-azure iceberg-aliyun; do + stage "${cloud}-bundle" "bundles/${cloud}-bundle/build/libs/gravitino-${cloud}-bundle-*.jar" + done + stage client-java-runtime 'clients/client-java-runtime/build/libs/gravitino-client-java-runtime-*.jar' + stage filesystem-hadoop3-runtime 'clients/filesystem-hadoop3-runtime/build/libs/gravitino-filesystem-hadoop3-runtime-*.jar' + stage jobs 'maintenance/jobs/build/libs/gravitino-jobs-*.jar' + for flink in 1.19 1.20 2.1 2.2; do + stage "flink-runtime-${flink}" "flink-connector/v${flink}/flink-runtime/build/libs/gravitino-flink-connector-runtime-${flink}*.jar" + done + stage spark-runtime-3.5_2.12 'spark-connector/v3.5/spark-runtime/build/libs/gravitino-spark-connector-runtime-3.5_2.12-*.jar' + stage spark-runtime-3.5_2.13 'spark-connector/v3.5/spark-runtime/build/libs/gravitino-spark-connector-runtime-3.5_2.13-*.jar' + stage spark-runtime-4.0 'spark-connector/v4.0/spark-runtime/build/libs/gravitino-spark-connector-runtime-4.0_2.13-*.jar' + exit "${rc}" + # Runs after a failed Stage step too, but not when the build already failed. + - name: Scan + if: ${{ !cancelled() && steps.stage.conclusion != 'skipped' }} + run: .github/trivy/scan.sh scan-all "${TARGET_DIR}" + # A partial result (some jars staged) is still uploaded. + - name: Upload the reports + if: ${{ !cancelled() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: cve-scan-jars + path: ${{ env.TRIVY_REPORT_DIR }} + retention-days: 30 + if-no-files-found: warn + + # One target per Trino version range. Trino 473 and later need JDK 25, which Gradle provisions + # through its toolchain resolver, as in the Trino integration tests. + trino: + name: Trino connectors + if: github.event_name != 'schedule' || github.repository == 'apache/gravitino' + needs: trivy-db + runs-on: ubuntu-latest + timeout-minutes: 120 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: ./.github/actions/setup-java-toolchains + - name: Free up disk space + run: dev/ci/util_free_space.sh + - name: Restore the DB cache + uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 + with: + path: ~/.cache/trivy + key: ${{ needs.trivy-db.outputs.cache-key }} + fail-on-cache-miss: true + - name: Pull the Trivy image + run: .github/trivy/scan.sh pull + - name: Build the connector libraries + run: | + ./gradlew -PskipWeb=true \ + :trino-connector:trino-connector-469-472:copyRuntimeLibs \ + :trino-connector:trino-connector-473-477:copyRuntimeLibs \ + :trino-connector:trino-connector-478-479:copyRuntimeLibs \ + :trino-connector:trino-connector-480:copyRuntimeLibs \ + :trino-connector:trino-connector-481:copyRuntimeLibs \ + :trino-connector:trino-connector-482-483:copyRuntimeLibs + - name: Scan + run: | + rc=0 + for range in 469-472 473-477 478-479 480 481 482-483; do Review Comment: Each target can take up to the 45m scan timeout, so six sequential Trino scans could pass the 120 minute job limit in the worst case. Consider a matrix over the version ranges, or a lower per-target timeout. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
