diff --git a/.github/workflows/README.md b/.github/workflows/README.md index bff53e3419..2e7b071b8f 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -326,7 +326,7 @@ without opening the job. The vulnerability engine is the odometer digit above distro and filesystem, and its glyph follows the architecture glyph in the label (`πŸ³πŸ§…πŸŒ€πŸ¦“πŸ¦ΎπŸ”Ί`). The deploy-time scan of `sys-ctl-hlth-runtime` then runs Syft and that engine only, plus Grype over the source-built runtimes Syft finds. -The `vulnerability-db` job of [call-test-deploy.yml](call-test-deploy.yml) downloads the Trivy, Grype and OSV databases once per day into the Actions cache; each deploy job restores the Grype database and the drawn engine's into `build/vulnerability-db`, which the stack and every swarm node mount read-only, and fails when one is missing, so no deploy job downloads a database itself. +The `vulnerability-db` job of [call-test-deploy.yml](call-test-deploy.yml) downloads the Trivy, Grype and OSV databases once per day into the Actions cache; each deploy job restores the Grype database and the drawn engine's into `build/vulnerability-db`, which the stack and every swarm node mount read-only. A failed restore gets one more attempt with a fresh download URL, and the job fails when a database is still missing, so no deploy job downloads a database itself. Under act these steps are skipped: the deploy draws its engine and refreshes the shared host directory `INFINITO_VULNERABILITY_DB_HOST_PATH`, which [workflow.sh](../../scripts/tests/deploy/act/workflow.sh) binds into the job container at the same path. `cron-images-mirror-all.yml` writes the findings of its `scan` job per image and per CVE into the job summary and the `vulnerability-findings` artifact; dispatched with `issues: false` it is a dry run that leaves the issues untouched. diff --git a/.github/workflows/call-test-deploy.yml b/.github/workflows/call-test-deploy.yml index 6bc49318e5..1ba3248044 100644 --- a/.github/workflows/call-test-deploy.yml +++ b/.github/workflows/call-test-deploy.yml @@ -418,14 +418,32 @@ jobs: run: nohup ./scripts/tests/deploy/ci/host-metrics-sampler.sh "${INFINITO_RESCUE_DIAGNOSTICS_BASE}/host-metrics.log" >/dev/null 2>&1 & - name: "πŸ‡ Restore the Grype database" + id: grype_db if: ${{ !env.ACT && matrix.engine != '' }} + continue-on-error: true + uses: actions/download-artifact@v8 + with: + name: vulnerability-db-${{ inputs.index }}-grype + path: build/vulnerability-db/grype + + - name: "πŸ‡ Retry the Grype database restore" + if: ${{ steps.grype_db.outcome == 'failure' }} uses: actions/download-artifact@v8 with: name: vulnerability-db-${{ inputs.index }}-grype path: build/vulnerability-db/grype - name: "πŸ”¬ Restore the ${{ matrix.engine }} database" + id: engine_db if: ${{ !env.ACT && matrix.engine != '' && matrix.engine != 'grype' }} + continue-on-error: true + uses: actions/download-artifact@v8 + with: + name: vulnerability-db-${{ inputs.index }}-${{ matrix.engine }} + path: build/vulnerability-db/${{ matrix.engine }} + + - name: "πŸ”¬ Retry the ${{ matrix.engine }} database restore" + if: ${{ steps.engine_db.outcome == 'failure' }} uses: actions/download-artifact@v8 with: name: vulnerability-db-${{ inputs.index }}-${{ matrix.engine }} diff --git a/tests/lint/repository/test_deploy_vulnerability_databases.py b/tests/lint/repository/test_deploy_vulnerability_databases.py index 115b8eb26b..e760be38d5 100644 --- a/tests/lint/repository/test_deploy_vulnerability_databases.py +++ b/tests/lint/repository/test_deploy_vulnerability_databases.py @@ -109,16 +109,35 @@ class TestDatabaseHandover(unittest.TestCase): sorted(f"{HANDOVER}{engine}" for engine in SCANNERS), ) + def _attempts(self) -> dict[str, list[dict]]: + attempts: dict[str, list[dict]] = {} + for step in self.jobs["deploy"]["steps"]: + name = step.get("with", {}).get("name", "") + if step.get("uses", "").startswith("actions/download") and name.startswith( + HANDOVER + ): + attempts.setdefault(name, []).append(step) + return attempts + def test_a_deploy_downloads_what_the_run_handed_over(self) -> None: self.assertEqual( - sorted( - args["name"] - for args in self._with("deploy", "download") - if args.get("name", "").startswith(HANDOVER) - ), + sorted(self._attempts()), [f"{HANDOVER}${{{{ matrix.engine }}}}", f"{HANDOVER}grype"], ) + def test_a_failed_download_gets_exactly_one_more_attempt(self) -> None: + for name, attempts in self._attempts().items(): + with self.subTest(name=name): + self.assertEqual(len(attempts), 2) + first, last = attempts + self.assertIs(first.get("continue-on-error"), True) + self.assertEqual( + last.get("if"), + f"${{{{ steps.{first.get('id')}.outcome == 'failure' }}}}", + ) + self.assertNotIn("continue-on-error", last) + self.assertEqual(last["with"], first["with"]) + def test_the_osv_cache_key_follows_the_ecosystem_list(self) -> None: osv = next( step