Skip to content

Commit 621679c

Browse files
authored
Makefile: Verify golangci-lint integrity before using it (#70)
The makefile now verifies the SHA-256 checksums of the installation script for golangci-lint and the binary we're expecting to see in GOBIN afterwards. This makes it a bit more tedious to upgrade golangci-lint but reduces surprises.
1 parent bfb9db6 commit 621679c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Makefile

+12-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ GOVVV = $(GOBIN)/govvv
1414
MOCKGEN = $(GOBIN)/mockgen
1515
PIGEON = $(GOBIN)/pigeon
1616

17-
GOLANGCI_LINT_VERSION = v1.43.0
17+
GOLANGCI_LINT_VERSION := v1.43.0
18+
GOLANGCI_LINT_INSTALLATION_SHA256 := 294771225087ee48c8e0a45a99ac82ed8f9c6e9d384e692ab201986479c8594f
19+
GOLANGCI_LINT_BINARY_SHA256 := c6f662fd533a7bff89c2d554dbe0708b6d3925f4b305d3522591d6bca0b48469
1820

1921
.PHONY: all
2022
all: test build start
@@ -79,11 +81,17 @@ $(COMPILEDAEMON):
7981
mkdir -p $(dir $@)
8082
go install github.com/githubnemo/[email protected]
8183

84+
# Download the installation script for golangci-lint, verify its SHA-256 digest,
85+
# run it if everything checks out, and verify the resulting binary.
8286
$(GOLANGCI_LINT):
8387
mkdir -p $(dir $@)
84-
curl -sfL \
85-
https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
86-
| sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VERSION)
88+
curl -sSfL \
89+
https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_LINT_VERSION)/install.sh \
90+
> $@.install-script-unverified
91+
echo "$(GOLANGCI_LINT_INSTALLATION_SHA256) $@.install-script-unverified" | sha256sum -c --quiet -
92+
sh -s -- -b $(dir $@) $(GOLANGCI_LINT_VERSION) < $@.install-script-unverified
93+
rm -f $@.install-script-unverified
94+
echo "$(GOLANGCI_LINT_BINARY_SHA256) $@" | sha256sum -c --quiet - || ( rm $@ ; exit 1 )
8795

8896
$(GOVVV):
8997
mkdir -p $(dir $@)

0 commit comments

Comments
 (0)