-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(security): add SHA-256 integrity verification for Ollama installer #2048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
52a0efe
fix(security): add SHA-256 integrity verification for Ollama installe…
ericksoa a5af19a
fix(ci): skip hash entries whose variable is not yet in the target file
ericksoa 2a1d0ca
style: apply shfmt formatting to check-installer-hash.sh
ericksoa 8d6d43e
fix(ci): add shasum fallback in check-installer-hash.sh for macOS
ericksoa 6c0f00b
style: apply shfmt formatting to install.sh and scripts/install.sh
ericksoa 24ef020
chore: complete shfmt formatting for -ci and -bn flags
ericksoa a6597e5
Merge branch 'main' into fix/ollama-sha256-verification
ericksoa 3c32ee6
Merge branch 'main' into fix/ollama-sha256-verification
ericksoa cda84be
Merge branch 'main' into fix/ollama-sha256-verification
ericksoa 60c4c81
Merge branch 'main' into fix/ollama-sha256-verification
ericksoa 9059ee8
Merge branch 'main' into fix/ollama-sha256-verification
ericksoa dcf2a9f
merge: resolve conflicts with main — keep multi-installer registry
ericksoa 81ec938
Merge branch 'main' into fix/ollama-sha256-verification
ericksoa 334d091
Merge branch 'main' into fix/ollama-sha256-verification
ericksoa ccfcc35
merge: resolve conflicts with main after k8s/ removal
ericksoa 00ee714
Merge branch 'main' into fix/ollama-sha256-verification
ericksoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Verifies pinned installer SHA-256 hashes still match upstream scripts. | ||
| # Checked: Ollama installer. | ||
| # Runs on every PR and push to main, plus a weekly scheduled check. | ||
|
|
||
| name: installer-hash-check | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| push: | ||
| branches: [main] | ||
| schedule: | ||
| # Weekly fallback in case upstream changes between PRs | ||
| - cron: "30 9 * * 1" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| check-hash: | ||
| if: github.repository == 'NVIDIA/NemoClaw' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | ||
|
|
||
| - name: Verify installer hashes are current | ||
| run: bash scripts/check-installer-hash.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Verifies that pinned SHA-256 hashes for downloaded installers still match | ||
| # the current upstream scripts. | ||
| # | ||
| # Checked installers: | ||
| # 1. Ollama installer — scripts/install.sh (OLLAMA_INSTALL_SHA256) | ||
| # | ||
| # Usage: | ||
| # scripts/check-installer-hash.sh # exit 0 if current, 1 if stale | ||
| # scripts/check-installer-hash.sh --update # rewrite stale hashes in-place | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" | ||
|
|
||
| case "${1:-}" in | ||
| "" | --update) ;; | ||
| *) | ||
| echo "Usage: scripts/check-installer-hash.sh [--update]" >&2 | ||
| exit 2 | ||
| ;; | ||
| esac | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Helpers | ||
| # --------------------------------------------------------------------------- | ||
| fetch_hash() { | ||
| local url="$1" tmpfile | ||
| tmpfile=$(mktemp) | ||
| trap 'rm -f "$tmpfile"' RETURN | ||
|
|
||
| curl --proto '=https' --tlsv1.2 -fsSL \ | ||
| --connect-timeout 10 --max-time 30 \ | ||
| --retry 3 --retry-delay 1 --retry-all-errors \ | ||
| -o "$tmpfile" "$url" | ||
|
|
||
| if command -v sha256sum >/dev/null 2>&1; then | ||
| sha256sum "$tmpfile" | awk '{print $1}' | ||
| elif command -v shasum >/dev/null 2>&1; then | ||
| shasum -a 256 "$tmpfile" | awk '{print $1}' | ||
| else | ||
| echo "ERROR: No SHA-256 tool available (sha256sum/shasum)." >&2 | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| extract_pinned() { | ||
| local file="$1" var_name="$2" | ||
| sed -n "s/.*${var_name}=\"\\([a-f0-9]\\{64\\}\\)\".*/\\1/p" "$file" | head -1 | ||
| } | ||
|
|
||
| update_pinned() { | ||
| local file="$1" old_hash="$2" new_hash="$3" | ||
| sed -i.bak "s/${old_hash}/${new_hash}/" "$file" | ||
| rm -f "${file}.bak" | ||
| } | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Registry of pinned hashes: (label, file, variable, upstream URL) | ||
| # --------------------------------------------------------------------------- | ||
| LABELS=() | ||
| FILES=() | ||
| VARS=() | ||
| URLS=() | ||
|
|
||
| register() { | ||
| LABELS+=("$1") | ||
| FILES+=("$2") | ||
| VARS+=("$3") | ||
| URLS+=("$4") | ||
| } | ||
|
|
||
| register "Ollama installer" \ | ||
| "${REPO_ROOT}/scripts/install.sh" \ | ||
| "OLLAMA_INSTALL_SHA256" \ | ||
| "https://ollama.com/install.sh" | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Main | ||
| # --------------------------------------------------------------------------- | ||
| failures=0 | ||
|
|
||
| for i in "${!LABELS[@]}"; do | ||
| label="${LABELS[$i]}" | ||
| file="${FILES[$i]}" | ||
| var="${VARS[$i]}" | ||
| url="${URLS[$i]}" | ||
|
|
||
| pinned=$(extract_pinned "$file" "$var") | ||
|
|
||
| if [[ -z "$pinned" ]]; then | ||
| echo " SKIP: ${var} not found in ${file} (not yet merged?)" | ||
| continue | ||
| fi | ||
|
|
||
| echo "Checking ${label} (${var})..." | ||
| echo " Fetching ${url}..." | ||
| upstream=$(fetch_hash "$url") | ||
|
|
||
| if [[ "$pinned" == "$upstream" ]]; then | ||
| echo " OK: hash is up-to-date (${pinned})" | ||
| continue | ||
| fi | ||
|
|
||
| if [[ "${1:-}" == "--update" ]]; then | ||
| update_pinned "$file" "$pinned" "$upstream" | ||
| echo " UPDATED ${file}: ${var}" | ||
| echo " old: ${pinned}" | ||
| echo " new: ${upstream}" | ||
| else | ||
| echo " STALE: pinned hash does not match upstream." | ||
| echo " pinned: ${pinned}" | ||
| echo " upstream: ${upstream}" | ||
| failures=$((failures + 1)) | ||
| fi | ||
| done | ||
|
|
||
| if ((failures > 0)); then | ||
| echo "" | ||
| echo "${failures} hash(es) are stale. To update, run:" | ||
| echo "" | ||
| echo " scripts/check-installer-hash.sh --update" | ||
| echo "" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "" | ||
| echo "All installer hashes are current." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.