Skip to content

Commit 6459494

Browse files
rscgopherbot
authored andcommitted
cmd/go: disable sumdb less often for toolchain downloads
There is a chicken and egg problem with always requiring the checksum database for toolchain module downloads, since the checksum database populates its entry by doing its own module download. Don't require the checksum database for GOPROXY=file:/// (for local testing) and when running on the Go module mirror. For #60847. Change-Id: I5d67d585169ae0fa73109df233baae8ba5fe5dd3 Reviewed-on: https://go-review.googlesource.com/c/go/+/503978 Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Russ Cox <[email protected]> Run-TryBot: Russ Cox <[email protected]>
1 parent 0278981 commit 6459494

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/cmd/go/internal/modfetch/sumdb.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,34 @@ import (
3434
// useSumDB reports whether to use the Go checksum database for the given module.
3535
func useSumDB(mod module.Version) bool {
3636
if mod.Path == "golang.org/toolchain" {
37+
must := true
3738
// Downloaded toolchains cannot be listed in go.sum,
3839
// so we require checksum database lookups even if
3940
// GOSUMDB=off or GONOSUMDB matches the pattern.
4041
// If GOSUMDB=off, then the eventual lookup will fail
4142
// with a good error message.
42-
return true
43+
44+
// Exception #1: using GOPROXY=file:// to test a distpack.
45+
if strings.HasPrefix(cfg.GOPROXY, "file://") && !strings.ContainsAny(cfg.GOPROXY, ",|") {
46+
must = false
47+
}
48+
// Exception #2: the Go proxy+checksum database cannot check itself
49+
// while doing the initial download.
50+
if strings.Contains(os.Getenv("GIT_HTTP_USER_AGENT"), "proxy.golang.org") {
51+
must = false
52+
}
53+
54+
// Another potential exception would be GOPROXY=direct,
55+
// but that would make toolchain downloads only as secure
56+
// as HTTPS, and in particular they'd be susceptible to MITM
57+
// attacks on systems with less-than-trustworthy root certificates.
58+
// The checksum database provides a stronger guarantee,
59+
// so we don't make that exception.
60+
61+
// Otherwise, require the checksum database.
62+
if must {
63+
return true
64+
}
4365
}
4466
return cfg.GOSUMDB != "off" && !module.MatchPrefixPatterns(cfg.GONOSUMDB, mod.Path)
4567
}

0 commit comments

Comments
 (0)