Skip to content

fix(tools): verify release downloads and add install opt-out - #199

Merged
mrz1836 merged 1 commit into
masterfrom
fix/verified-tool-installs
Nov 10, 2026
Merged

mrz1836 merged 1 commit into
masterfrom
fix/verified-tool-installs

Conversation

@mrz1836

@mrz1836 mrz1836 commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

What Changed

  • golangci-lint and gitleaks are installed from their GitHub releases (new internal/tools/release.go). The pinned version must be a release tag (v1.2.3). go-pre-commit downloads the archive and the checksums file over https only (redirects to plain http are refused), with size caps. It takes the one checksums line for the archive's exact name (zero or several lines are refused), checks the SHA-256 before extracting anything, and extracts only the binary: a regular file, with no links, no entries that escape the archive, and no duplicates. The binary is written to a temp file and renamed into $GOBIN (or $GOPATH/bin). latest is resolved from the /releases/latest redirect. No install script is downloaded or run.
  • Each failed step is an error naming the tool, version, and step, for example tool installation failed: golangci-lint v2.15.0: verify checksum: …. golangci-lint still falls back to go install on any failure, now with the /v2 module path. When both methods fail, both errors are reported. A successful golangci-lint install is now checked against PATH, as the other tools already were.
  • New GO_PRE_COMMIT_AUTO_INSTALL_TOOLS (default true). Set to false, nothing is installed, and a missing tool fails its check with the exact command, for example go install github.com/golangci/golangci-lint/v2/cmd/[email protected]. Tools already on PATH are used either way.
  • The lint and gitleaks checks pass the install error through and suggest that exact command; fumpt does the same when installs are off. The gitleaks module path is corrected to github.com/zricethezav/gitleaks/v8.
  • README ("How tools are installed"), the config help text, and the contributor notes in .github/ are updated.

Why It Was Necessary

  • golangci-lint was installed with curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- …: a script from a moving branch, piped to a shell. gitleaks was downloaded with curl and never checked.
  • A curl | sh pipeline exits 0 when a step fails, so a failed install looked like a success and the go install fallback never ran. That fallback also used the v1 module path, so it could not install any v2 version.
  • On darwin/arm64 with golangci-lint v2.15.0, the script fails its own checksum step: the checksums file lists both golangci-lint-2.15.0-darwin-arm64.tar.gz and …tar.gz.sbom.json, and the script matches the name as a substring. The lint check then reported only golangci-lint not found and suggested a v1 go install …@latest. golangci-lint could not be installed on Apple silicon.
  • There was no way to turn automatic installs off.

Testing Performed

  • New internal/tools/installer_release_test.go and a rewritten installer_gitleaks_test.go cover:
    • the .sbom.json sibling line, which is ignored
    • an exact name listed twice (same or different sum), which is refused
    • a missing or malformed line, and a checksum mismatch
    • 404 and 503 responses (503 is retried) and an unreachable server
    • an http base URL and a redirect to http
    • size caps
    • symlinks, hard links, path traversal, absolute and duplicate entries, a missing binary, and a corrupt archive (tar and zip)
    • asset names per platform, tag checking, and latest resolution
    • the go install fallback (v1 and v2 paths, both methods failing)
    • the opt-out: no download, no command and nothing installed for all four tools
    • InstallCommand
  • New internal/checks/gotools/install_test.go checks each check's message, suggestion and output with installs off and after a failed install.
  • Tests never reach the network: fake releases are served from httptest into temp GOBIN/GOPATH, the tools package's TestMain makes any other download fail, and makeToolsUnavailable now turns installs off.
  • magex format:fix, magex lint (0 issues), magex test:race, and go-pre-commit run --all-files pass. go test -race -shuffle=on -count=3 passes for internal/tools, internal/checks/gotools, internal/integration, and internal/config.
  • Manual check on darwin/arm64 with the built binary in a throwaway repository and a temp GOBIN. With GO_PRE_COMMIT_AUTO_INSTALL_TOOLS=false, lint fails with the exact command and nothing is downloaded. With installs on, golangci-lint v2.15.0 is downloaded, verified and installed, and lint passes (with GOPROXY=off, so the fallback could not have done it). gitleaks v8.30.1 also installs and runs.

Impact / Risk

  • Breaking changes: none to configuration. The new setting defaults to the current behavior (installs on).
  • Platform: taken from the go-pre-commit binary itself (runtime.GOOS/GOARCH) instead of GOOS/GOARCH environment variables and uname. A platform a tool doesn't publish now fails clearly instead of downloading the linux x64 build. 32-bit ARM uses the armv6 build. curl, sh, tar, and unzip are no longer needed; downloads use Go's HTTP client and honor HTTPS_PROXY.
  • Install location: golangci-lint now installs to $GOBIN (else $GOPATH/bin, else ~/go/bin), like gitleaks. The script used $(go env GOPATH)/bin. They differ only when GOBIN is set.
  • Fallback: a checksum mismatch also triggers golangci-lint's go install fallback, verified by the Go checksum database. The mismatched archive is never installed, and the warning shows the failure.
  • Messages: the lint and gitleaks checks report a missing tool with the install error and an exact command. gitleaks no longer reports it as command 'gitleaks' failed.
  • Unchanged: a value of GO_PRE_COMMIT_AUTO_INSTALL_TOOLS that is not a boolean keeps installs on, like other boolean settings. A tool installed outside PATH still fails with tool installed but not found in PATH; that is a separate fix.

golangci-lint was installed by piping install.sh from the master branch
into sh, and gitleaks was downloaded with curl; neither download was
checked against anything. A curl | sh pipeline exits 0 when a step
fails, so a failed golangci-lint install looked like a success and the
go install fallback never ran. With golangci-lint v2.15.0 on
darwin/arm64 the script fails its own checksum step, because the
checksums file lists both the archive and its .sbom.json, and the lint
check then only reported "golangci-lint not found".

Install both tools from their GitHub release instead: download the
pinned version's archive and checksums file over https, require exactly
one checksums line for the archive's exact name, verify the SHA-256
before extracting, and extract only the binary (a regular file, size
capped, no links or path traversal) into GOBIN, as before. Each failed
step is an error naming the tool, version, and step. golangci-lint
still falls back to go install, now with the v2 module path, and the
checks pass the install error through with the exact install command.

GO_PRE_COMMIT_AUTO_INSTALL_TOOLS=false turns automatic installs off: a
missing tool then fails its check with the command that installs it.
@github-actions github-actions Bot added bug-P3 Lowest rated bug, affects nearly none or low-impact feature Any new significant addition labels Nov 10, 2026
@github-actions github-actions Bot added the size/XL Very large change (>500 lines) label Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage Analysis

🟢 Overall Coverage: 91.1%
📊 Initial coverage report - no baseline available for comparison

Coverage Metrics

Metric Value Grade Trend
Percentage 91.1% 🏆 A 📊
Statements 3.5K/3.8K 🏆 A First report
Quality Score 91.1/100 🏆 A 📈

Coverage Breakdown

█████████████░░ 91.1%

Resources


Generated via go-coverage • 2026-11-10 04:27:33 UTC

github-actions Bot added a commit that referenced this pull request Nov 10, 2026
🏷️ Generated with GoFortress
@mrz1836
mrz1836 merged commit caaa9b7 into master Nov 10, 2026
31 checks passed
@github-actions
github-actions Bot deleted the fix/verified-tool-installs branch November 10, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-P3 Lowest rated bug, affects nearly none or low-impact feature Any new significant addition size/XL Very large change (>500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant