|
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | 4 | repo="cisco-ai-defense/pickle-fuzzer" |
| 5 | +signer_workflow="${repo}/.github/workflows/release.yml" |
5 | 6 |
|
6 | 7 | version_input="${INPUT_VERSION:-}" |
7 | 8 | action_ref="${GITHUB_ACTION_REF:-}" |
8 | 9 |
|
| 10 | +is_safe_release_tag() { |
| 11 | + [[ "$1" =~ ^v[0-9A-Za-z][0-9A-Za-z._+-]*$ ]] |
| 12 | +} |
| 13 | + |
9 | 14 | if [[ -n "$version_input" ]]; then |
10 | 15 | version="$version_input" |
11 | | -elif [[ -n "$action_ref" && "$action_ref" == v* ]]; then |
12 | | - version="$action_ref" |
| 16 | + version_source="inputs.version" |
| 17 | +elif [[ -n "$action_ref" && ( "$action_ref" == v* || "$action_ref" == refs/tags/v* ) ]]; then |
| 18 | + version="${action_ref##refs/tags/}" |
| 19 | + version_source="GITHUB_ACTION_REF" |
13 | 20 | else |
14 | | - version="latest" |
| 21 | + echo "INPUT_VERSION is required when the action ref is not a release tag." >&2 |
| 22 | + if [[ -n "$action_ref" ]]; then |
| 23 | + echo "Received GITHUB_ACTION_REF=${action_ref}." >&2 |
| 24 | + else |
| 25 | + echo "Received an empty GITHUB_ACTION_REF (for example from a local checkout)." >&2 |
| 26 | + fi |
| 27 | + echo "Set the action version input to an immutable release tag such as v1.2.3, or explicitly set it to latest if you accept a mutable release." >&2 |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +if [[ "$version" != "latest" ]] && ! is_safe_release_tag "$version"; then |
| 32 | + echo "Unsupported release tag from ${version_source}: ${version}" >&2 |
| 33 | + echo "Expected a release tag like v1, v1.2.3, or v1.2.3-rc1." >&2 |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +if ! command -v gh >/dev/null 2>&1; then |
| 38 | + echo "GitHub CLI is required to resolve and verify release provenance." >&2 |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +if [[ "$version" == "latest" ]]; then |
| 43 | + version="$(gh release view --repo "${repo}" --json tagName --jq '.tagName')" |
| 44 | + if [[ -z "$version" ]]; then |
| 45 | + echo "Failed to resolve the latest release tag for ${repo}." >&2 |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + if ! is_safe_release_tag "$version"; then |
| 49 | + echo "Resolved latest release tag is invalid: ${version}" >&2 |
| 50 | + exit 1 |
| 51 | + fi |
15 | 52 | fi |
16 | 53 |
|
17 | 54 | os="${RUNNER_OS:-}" |
|
61 | 98 | fi |
62 | 99 | mkdir -p "$install_dir" |
63 | 100 |
|
64 | | -if [[ "$version" == "latest" ]]; then |
65 | | - url="https://github.com/${repo}/releases/latest/download/${asset}" |
66 | | - checksum_url="https://github.com/${repo}/releases/latest/download/${asset}.sha256" |
67 | | -else |
68 | | - url="https://github.com/${repo}/releases/download/${version}/${asset}" |
69 | | - checksum_url="https://github.com/${repo}/releases/download/${version}/${asset}.sha256" |
70 | | -fi |
| 101 | +url="https://github.com/${repo}/releases/download/${version}/${asset}" |
71 | 102 |
|
72 | 103 | echo "Downloading ${url}" |
73 | 104 | curl -fsSL -o "${install_dir}/${bin_name}" "$url" |
74 | 105 |
|
75 | | -checksum_path="${install_dir}/${asset}.sha256" |
76 | | -echo "Downloading ${checksum_url}" |
77 | | -curl -fsSL -o "${checksum_path}" "$checksum_url" |
78 | | - |
79 | | -expected_checksum="$(awk '{print $1}' "$checksum_path" | tr '[:upper:]' '[:lower:]')" |
80 | | -if [[ -z "$expected_checksum" ]]; then |
81 | | - echo "Checksum file is empty or invalid: ${checksum_path}" >&2 |
82 | | - exit 1 |
83 | | -fi |
84 | | - |
85 | | -if command -v sha256sum >/dev/null 2>&1; then |
86 | | - actual_checksum="$(sha256sum "${install_dir}/${bin_name}" | awk '{print $1}')" |
87 | | -elif command -v shasum >/dev/null 2>&1; then |
88 | | - actual_checksum="$(shasum -a 256 "${install_dir}/${bin_name}" | awk '{print $1}')" |
89 | | -elif command -v certutil >/dev/null 2>&1; then |
90 | | - file_native="${install_dir}/${bin_name}" |
91 | | - if command -v cygpath >/dev/null 2>&1; then |
92 | | - file_native="$(cygpath -w "${install_dir}/${bin_name}")" |
93 | | - fi |
94 | | - actual_checksum="$(certutil -hashfile "$file_native" SHA256 | awk 'NR==2 {print tolower($1)}')" |
95 | | -else |
96 | | - echo "No SHA-256 tool available to verify checksum." >&2 |
97 | | - exit 1 |
98 | | -fi |
99 | | - |
100 | | -actual_checksum="$(echo "$actual_checksum" | tr '[:upper:]' '[:lower:]')" |
101 | | -if [[ -z "$actual_checksum" ]]; then |
102 | | - echo "Failed to compute SHA-256 checksum." >&2 |
103 | | - exit 1 |
104 | | -fi |
105 | | - |
106 | | -if [[ "$expected_checksum" != "$actual_checksum" ]]; then |
107 | | - echo "Checksum mismatch for ${bin_name}." >&2 |
108 | | - echo "Expected: ${expected_checksum}" >&2 |
109 | | - echo "Actual: ${actual_checksum}" >&2 |
| 106 | +verify_args=( |
| 107 | + attestation verify |
| 108 | + "${install_dir}/${bin_name}" |
| 109 | + --repo "${repo}" |
| 110 | + --signer-workflow "${signer_workflow}" |
| 111 | + --source-ref "refs/tags/${version}" |
| 112 | +) |
| 113 | + |
| 114 | +echo "Verifying release provenance for ${bin_name}" |
| 115 | +if ! gh "${verify_args[@]}" >/dev/null; then |
| 116 | + echo "Failed to verify GitHub release provenance for ${bin_name}." >&2 |
110 | 117 | exit 1 |
111 | 118 | fi |
112 | 119 |
|
|
0 commit comments