Skip to content

Commit ac55d58

Browse files
witchardBryan C. Mills
authored and
Bryan C. Mills
committed
cmd/go/internal/get: add GOINSECURE support
Adds support for the GOINSECURE environment variable to GOPATH mode. Updates #37519. Change-Id: Ibe3f52b7f30b1395edb000998905ee93abe6cada GitHub-Last-Rev: e298c00 GitHub-Pull-Request: #38628 Reviewed-on: https://go-review.googlesource.com/c/go/+/229758 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 829ca10 commit ac55d58

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

src/cmd/go/alldocs.go

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/get/get.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ The -fix flag instructs get to run the fix tool on the downloaded packages
4343
before resolving dependencies or building the code.
4444
4545
The -insecure flag permits fetching from repositories and resolving
46-
custom domains using insecure schemes such as HTTP. Use with caution.
46+
custom domains using insecure schemes such as HTTP. Use with caution. The
47+
GOINSECURE environment variable is usually a better alternative, since it
48+
provides control over which modules may be retrieved using an insecure scheme.
49+
See 'go help environment' for details.
4750
4851
The -t flag instructs get to also download the packages required to build
4952
the tests for the specified packages.
@@ -411,11 +414,6 @@ func downloadPackage(p *load.Package) error {
411414
blindRepo bool // set if the repo has unusual configuration
412415
)
413416

414-
security := web.SecureOnly
415-
if Insecure {
416-
security = web.Insecure
417-
}
418-
419417
// p can be either a real package, or a pseudo-package whose “import path” is
420418
// actually a wildcard pattern.
421419
// Trim the path at the element containing the first wildcard,
@@ -432,6 +430,10 @@ func downloadPackage(p *load.Package) error {
432430
if err := module.CheckImportPath(importPrefix); err != nil {
433431
return fmt.Errorf("%s: invalid import path: %v", p.ImportPath, err)
434432
}
433+
security := web.SecureOnly
434+
if Insecure || module.MatchPrefixPatterns(cfg.GOINSECURE, importPrefix) {
435+
security = web.Insecure
436+
}
435437

436438
if p.Internal.Build.SrcRoot != "" {
437439
// Directory exists. Look for checkout along path to src.
@@ -475,7 +477,7 @@ func downloadPackage(p *load.Package) error {
475477
}
476478
vcs, repo, rootPath = rr.vcs, rr.Repo, rr.Root
477479
}
478-
if !blindRepo && !vcs.isSecure(repo) && !Insecure {
480+
if !blindRepo && !vcs.isSecure(repo) && security != web.Insecure {
479481
return fmt.Errorf("cannot download, %v uses insecure protocol", repo)
480482
}
481483

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[!net] skip
2+
[!exec:git] skip
3+
4+
# GOPATH: Set up
5+
env GO111MODULE=off
6+
7+
# GOPATH: Try go get -d of HTTP-only repo (should fail).
8+
! go get -d insecure.go-get-issue-15410.appspot.com/pkg/p
9+
10+
# GOPATH: Try again with invalid GOINSECURE (should fail).
11+
env GOINSECURE=insecure.go-get-issue-15410.appspot.com/pkg/q
12+
! go get -d insecure.go-get-issue-15410.appspot.com/pkg/p
13+
14+
# GOPATH: Try with correct GOINSECURE (should succeed).
15+
env GOINSECURE=insecure.go-get-issue-15410.appspot.com/pkg/p
16+
go get -d insecure.go-get-issue-15410.appspot.com/pkg/p
17+
18+
# GOPATH: Try updating without GOINSECURE (should fail).
19+
env GOINSECURE=
20+
! go get -d -u -f insecure.go-get-issue-15410.appspot.com/pkg/p
21+
22+
# GOPATH: Try updating with GOINSECURE glob (should succeed).
23+
env GOINSECURE=*.go-get-*.appspot.com
24+
go get -d -u -f insecure.go-get-issue-15410.appspot.com/pkg/p
25+
26+
# GOPATH: Try updating with GOINSECURE base URL (should succeed).
27+
env GOINSECURE=insecure.go-get-issue-15410.appspot.com
28+
go get -d -u -f insecure.go-get-issue-15410.appspot.com/pkg/p
29+

0 commit comments

Comments
 (0)