Skip to content

Commit 7ca0e04

Browse files
janniklasroseIsaac
andcommitted
Verify SHA-256 checksums before installing release archives
Reject missing, duplicate, malformed, or mismatching checksum records and propagate hash-tool failures before extraction. Cover both installers with portable regression tests and document the release integrity boundary. Refs #239 Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 2da6132 commit 7ca0e04

5 files changed

Lines changed: 249 additions & 0 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ on:
1616
# self-hosted runners listed on the "Settings" -> "Actions" -> "Runners" page.
1717
#
1818
jobs:
19+
checksum_verification:
20+
runs-on: ${{ matrix.os }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
os: [ubuntu-latest, macos-latest]
25+
steps:
26+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
27+
- run: bash assert/checksums.sh
28+
shell: bash
29+
1930
action_with_defaults:
2031
runs-on: ${{ matrix.os }}
2132

‎README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,21 @@ Alternatively, you can specify the version as a parameter to the action:
6161
Please note that the Databricks CLI is in public preview as defined on
6262
https://docs.databricks.com/en/release-notes/release-types.html.
6363
This means that it has medium-to-high maturity and can be used in production.
64+
65+
## Security
66+
67+
Release archives downloaded by the action and `install.sh` are verified against the SHA-256 checksums published with the CLI release before extraction. Snapshot builds do not use this release-manifest verification. Checksums detect corrupted downloads; they do not replace HTTPS certificate verification.
68+
69+
To pin the action's code, use a full commit SHA instead of a movable branch or tag:
70+
71+
```yml
72+
- uses: databricks/setup-cli@<full-commit-sha> # vX.Y.Z
73+
```
74+
75+
When using the installation script, select a release tag:
76+
77+
```bash
78+
curl -fsSL https://raw.githubusercontent.com/databricks/setup-cli/vX.Y.Z/install.sh | sh
79+
```
80+
81+
Use a full commit SHA in place of the tag when the script itself must be immutable. A pinned action revision does not pin the CLI if you request a floating version selector.

‎assert/checksums.sh‎

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"
6+
test_dir="$(mktemp -d)"
7+
trap 'rm -rf "$test_dir"' EXIT
8+
9+
version="$(cat "$repo_dir/VERSION")"
10+
archive="databricks_cli_${version}_linux_amd64.zip"
11+
manifest="databricks_cli_${version}_SHA256SUMS"
12+
mkdir -p "$test_dir/fixture"
13+
printf '#!/bin/sh\nprintf "Databricks CLI test fixture\\n"\n' > "$test_dir/fixture/databricks"
14+
(cd "$test_dir/fixture" && zip -q "$archive" databricks)
15+
16+
if command -v sha256sum >/dev/null 2>&1; then
17+
hash_tool="$(command -v sha256sum)"
18+
hash_kind=sha256sum
19+
checksum_output="$("$hash_tool" "$test_dir/fixture/$archive")"
20+
else
21+
hash_tool="$(command -v shasum)"
22+
hash_kind=shasum
23+
checksum_output="$("$hash_tool" -a 256 "$test_dir/fixture/$archive")"
24+
fi
25+
digest="${checksum_output%% *}"
26+
unzip_tool="$(command -v unzip)"
27+
shasum_tool="$(command -v shasum)"
28+
sh_tool="$(command -v sh)"
29+
bash_tool="$(command -v bash)"
30+
31+
for script in install.sh setup_release.sh; do
32+
for scenario in valid mismatch missing duplicate malformed trailing-fields hash-failure archive-failure manifest-failure no-tool shasum shasum-failure; do
33+
case_dir="$test_dir/$script-$scenario"
34+
mkdir -p "$case_dir/bin" "$case_dir/target" "$case_dir/tmp" "$case_dir/fixture"
35+
cp "$test_dir/fixture/$archive" "$case_dir/fixture/$archive"
36+
printf '%s %s\n' "$digest" "$archive" > "$case_dir/fixture/$manifest"
37+
case "$scenario" in
38+
mismatch) printf 'corrupted' >> "$case_dir/fixture/$archive" ;;
39+
missing) printf '%s unrelated.zip\n' "$digest" > "$case_dir/fixture/$manifest" ;;
40+
duplicate) printf '%s %s\n' "$digest" "$archive" >> "$case_dir/fixture/$manifest" ;;
41+
malformed) printf 'invalid %s\n' "$archive" > "$case_dir/fixture/$manifest" ;;
42+
trailing-fields) printf '%s %s extra\n' "$digest" "$archive" > "$case_dir/fixture/$manifest" ;;
43+
esac
44+
for utility in awk cat chmod cp cut install mkdir mktemp rm; do
45+
ln -s "$(command -v "$utility")" "$case_dir/bin/$utility"
46+
done
47+
cat > "$case_dir/bin/uname" <<'MOCK'
48+
#!/bin/sh
49+
case "$1" in
50+
-s) echo Linux ;;
51+
-m) echo x86_64 ;;
52+
*) exit 1 ;;
53+
esac
54+
MOCK
55+
cat > "$case_dir/bin/curl" <<'MOCK'
56+
#!/bin/sh
57+
for argument do url=$argument; done
58+
filename=${url##*/}
59+
case "$CHECKSUM_TEST_SCENARIO:$filename" in
60+
archive-failure:*.zip|manifest-failure:*_SHA256SUMS) exit 22 ;;
61+
esac
62+
cp "$CHECKSUM_TEST_FIXTURE/$filename" "$filename"
63+
MOCK
64+
cat > "$case_dir/bin/unzip" <<'MOCK'
65+
#!/bin/sh
66+
echo extraction >> "$CHECKSUM_TEST_EVENTS"
67+
exec "$CHECKSUM_TEST_UNZIP" "$@"
68+
MOCK
69+
cat > "$case_dir/hash-tool" <<'MOCK'
70+
#!/bin/sh
71+
echo "hash:${0##*/}" >> "$CHECKSUM_TEST_EVENTS"
72+
if [ "${0##*/}" = shasum ]; then
73+
"$CHECKSUM_TEST_SHASUM" "$@" || exit $?
74+
elif [ "$CHECKSUM_TEST_HASH_KIND" = shasum ]; then
75+
"$CHECKSUM_TEST_HASH" -a 256 "$@" || exit $?
76+
else
77+
"$CHECKSUM_TEST_HASH" "$@" || exit $?
78+
fi
79+
case "$CHECKSUM_TEST_SCENARIO" in
80+
hash-failure|shasum-failure) exit 7 ;;
81+
esac
82+
MOCK
83+
chmod +x "$case_dir/hash-tool"
84+
case "$scenario" in
85+
no-tool) ;;
86+
shasum|shasum-failure) cp "$case_dir/hash-tool" "$case_dir/bin/shasum" ;;
87+
*) cp "$case_dir/hash-tool" "$case_dir/bin/sha256sum" ;;
88+
esac
89+
chmod +x "$case_dir/bin/uname" "$case_dir/bin/curl" "$case_dir/bin/unzip"
90+
: > "$case_dir/events"
91+
: > "$case_dir/github-path"
92+
if [ "$script" = install.sh ]; then
93+
sed "s|TARGET=\"/usr/local/bin\"|TARGET=\"\$CHECKSUM_TEST_TARGET\"|" "$repo_dir/$script" > "$case_dir/$script"
94+
shell_tool="$sh_tool"
95+
script_path="$case_dir/$script"
96+
else
97+
shell_tool="$bash_tool"
98+
script_path="$repo_dir/$script"
99+
fi
100+
status=0
101+
env -i PATH="$case_dir/bin" TMPDIR="$case_dir/tmp" \
102+
VERSION="$version" RUNNER_OS=Linux RUNNER_ARCH=X64 \
103+
RUNNER_TEMP="$case_dir/tmp" GITHUB_PATH="$case_dir/github-path" \
104+
CHECKSUM_TEST_TARGET="$case_dir/target" CHECKSUM_TEST_SCENARIO="$scenario" \
105+
CHECKSUM_TEST_FIXTURE="$case_dir/fixture" CHECKSUM_TEST_EVENTS="$case_dir/events" \
106+
CHECKSUM_TEST_HASH="$hash_tool" CHECKSUM_TEST_HASH_KIND="$hash_kind" \
107+
CHECKSUM_TEST_SHASUM="$shasum_tool" \
108+
CHECKSUM_TEST_UNZIP="$unzip_tool" \
109+
"$shell_tool" "$script_path" > "$case_dir/output" 2>&1 || status=$?
110+
case "$scenario" in
111+
valid|shasum)
112+
if [ "$status" -ne 0 ]; then
113+
cat "$case_dir/output"
114+
echo "$script/$scenario unexpectedly failed" >&2
115+
exit 1
116+
fi
117+
grep -q '^extraction$' "$case_dir/events"
118+
if [ "$script" = install.sh ]; then
119+
test -x "$case_dir/target/databricks"
120+
else
121+
test -x "$(cat "$case_dir/github-path")/databricks"
122+
fi
123+
if [ "$scenario" = shasum ]; then
124+
grep -q '^hash:shasum$' "$case_dir/events"
125+
fi
126+
;;
127+
*)
128+
if [ "$status" -eq 0 ] || grep -q '^extraction$' "$case_dir/events" || [ -s "$case_dir/github-path" ] || [ -e "$case_dir/target/databricks" ]; then
129+
cat "$case_dir/output"
130+
echo "$script/$scenario did not fail before extraction" >&2
131+
exit 1
132+
fi
133+
;;
134+
esac
135+
echo "$script/$scenario passed"
136+
done
137+
done

‎install.sh‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,48 @@ cd "$tmpdir"
8282
# Download release archive.
8383
curl -fsSL -O "https://github.com/databricks/cli/releases/download/v${VERSION}/${FILE}.zip"
8484

85+
# Download and verify checksum.
86+
curl -fsSL -O "https://github.com/databricks/cli/releases/download/v${VERSION}/databricks_cli_${VERSION}_SHA256SUMS"
87+
88+
# Determine which checksum tool to use.
89+
CHECKSUM_TOOL=""
90+
if command -v sha256sum >/dev/null 2>&1; then
91+
CHECKSUM_TOOL="sha256sum"
92+
elif command -v shasum >/dev/null 2>&1; then
93+
CHECKSUM_TOOL="shasum -a 256"
94+
else
95+
echo "Error: Neither sha256sum nor shasum is available."
96+
echo "Please install one of these tools to verify checksum integrity."
97+
exit 1
98+
fi
99+
100+
# Extract the expected checksum for this specific file.
101+
if ! expected_hash=$(awk -v filename="${FILE}.zip" '
102+
$2 == filename { count++; hash = $1; fields = NF }
103+
END {
104+
if (count != 1 || fields != 2 || length(hash) != 64 || hash ~ /[^0-9a-fA-F]/) exit 1
105+
print tolower(hash)
106+
}
107+
' "databricks_cli_${VERSION}_SHA256SUMS"); then
108+
echo "Error: Expected exactly one valid SHA-256 checksum for ${FILE}.zip in databricks_cli_${VERSION}_SHA256SUMS" >&2
109+
exit 1
110+
fi
111+
112+
# Compute the actual checksum.
113+
if ! checksum_output=$($CHECKSUM_TOOL "${FILE}.zip"); then
114+
echo "Error: Unable to compute SHA-256 checksum for ${FILE}.zip" >&2
115+
exit 1
116+
fi
117+
actual_hash=${checksum_output%% *}
118+
119+
# Verify the checksum matches.
120+
if [ "$expected_hash" != "$actual_hash" ]; then
121+
echo "Error: Checksum mismatch for ${FILE}.zip"
122+
echo "Expected: $expected_hash"
123+
echo "Actual: $actual_hash"
124+
exit 1
125+
fi
126+
85127
# Unzip release archive.
86128
unzip -q "${FILE}.zip"
87129

‎setup_release.sh‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,47 @@ cd "$dir"
4848
# Download release archive.
4949
curl -fsSL -O "https://github.com/databricks/cli/releases/download/v${VERSION}/${FILE}.zip"
5050

51+
# Download and verify checksum.
52+
curl -fsSL -O "https://github.com/databricks/cli/releases/download/v${VERSION}/databricks_cli_${VERSION}_SHA256SUMS"
53+
54+
# Determine which checksum tool to use.
55+
if command -v sha256sum >/dev/null 2>&1; then
56+
CHECKSUM_TOOL="sha256sum"
57+
elif command -v shasum >/dev/null 2>&1; then
58+
CHECKSUM_TOOL="shasum -a 256"
59+
else
60+
echo "Error: Neither sha256sum nor shasum is available."
61+
echo "Please install one of these tools to verify checksum integrity."
62+
exit 1
63+
fi
64+
65+
# Extract the expected checksum for this specific file.
66+
if ! expected_hash=$(awk -v filename="${FILE}.zip" '
67+
$2 == filename { count++; hash = $1; fields = NF }
68+
END {
69+
if (count != 1 || fields != 2 || length(hash) != 64 || hash ~ /[^0-9a-fA-F]/) exit 1
70+
print tolower(hash)
71+
}
72+
' "databricks_cli_${VERSION}_SHA256SUMS"); then
73+
echo "Error: Expected exactly one valid SHA-256 checksum for ${FILE}.zip in databricks_cli_${VERSION}_SHA256SUMS" >&2
74+
exit 1
75+
fi
76+
77+
# Compute the actual checksum.
78+
if ! checksum_output=$($CHECKSUM_TOOL "${FILE}.zip"); then
79+
echo "Error: Unable to compute SHA-256 checksum for ${FILE}.zip" >&2
80+
exit 1
81+
fi
82+
actual_hash=${checksum_output%% *}
83+
84+
# Verify the checksum matches.
85+
if [ "$expected_hash" != "$actual_hash" ]; then
86+
echo "Error: Checksum mismatch for ${FILE}.zip"
87+
echo "Expected: $expected_hash"
88+
echo "Actual: $actual_hash"
89+
exit 1
90+
fi
91+
5192
# Unzip release archive.
5293
unzip -q "${FILE}.zip"
5394

0 commit comments

Comments
 (0)