diff --git a/.github/security/image_update.py b/.github/security/image_update.py index b29ea45..c3a77e2 100644 --- a/.github/security/image_update.py +++ b/.github/security/image_update.py @@ -72,6 +72,7 @@ r"@sha256:(?P[0-9a-f]{64})(?P +AS +[A-Za-z0-9_.-]+)?$", re.M) SHA256 = re.compile(r"[0-9a-f]{64}") TIMEOUT = 60 +RETRIES = 3 Api = Callable[..., Any] Fetch = Callable[..., tuple[bytes, dict[str, str]]] @@ -114,12 +115,14 @@ def gh_api(endpoint: str, method: str = "GET", payload: Any = None) -> Any: def http_get(url: str, headers: dict[str, str], head: bool = False) -> tuple[bytes, dict[str, str]]: - """GET (or HEAD) `url` with curl, HTTPS only; the body and the response headers.""" + """GET (or HEAD) `url` with curl, HTTPS only; the body and the response headers. + A transient failure, such as a 504 from the registry, is retried.""" args = ["curl", "--fail", "--silent", "--show-error", "--proto", "=https", + "--retry", str(RETRIES), "--retry-all-errors", "--max-time", str(TIMEOUT), "--head" if head else "--dump-header", *([] if head else ["-"]), url] for name, value in headers.items(): args[1:1] = ["--header", f"{name}: {value}"] - result = subprocess.run(args, capture_output=True, timeout=TIMEOUT + 10) + result = subprocess.run(args, capture_output=True, timeout=(TIMEOUT + 10) * (RETRIES + 1)) if result.returncode != 0: raise ApiError(f"GET {url}: {result.stderr.decode('utf-8', 'replace').strip()}") head_part, _, payload = result.stdout.partition(b"\r\n\r\n") diff --git a/.github/workflows/malware-scan.yml b/.github/workflows/malware-scan.yml index 2deaf65..1ae675b 100644 --- a/.github/workflows/malware-scan.yml +++ b/.github/workflows/malware-scan.yml @@ -168,10 +168,10 @@ jobs: run: | set -euo pipefail pins=.github/security/yara.json - curl -fsSL -o yr.tar.gz "$(jq -r .yara_x.url "$pins")" + curl --retry 3 --retry-all-errors -fsSL -o yr.tar.gz "$(jq -r .yara_x.url "$pins")" echo "$(jq -r .yara_x.sha256 "$pins") yr.tar.gz" | sha256sum --check tar -xzf yr.tar.gz yr - curl -fsSL -o forge.zip "$(jq -r .yara_forge.url "$pins")" + curl --retry 3 --retry-all-errors -fsSL -o forge.zip "$(jq -r .yara_forge.url "$pins")" echo "$(jq -r .yara_forge.sha256 "$pins") forge.zip" | sha256sum --check unzip -q forge.zip -d forge YARA_FORGE_RELEASE=$(jq -r .yara_forge.release "$pins")