@@ -768,90 +768,14 @@ var HelpModuleAuth = &base.Command{
768
768
UsageLine : "module-auth" ,
769
769
Short : "module authentication using go.sum" ,
770
770
Long : `
771
- The go command tries to authenticate every downloaded module,
772
- checking that the bits downloaded for a specific module version today
773
- match bits downloaded yesterday. This ensures repeatable builds
774
- and detects introduction of unexpected changes, malicious or not.
775
-
776
- In each module's root, alongside go.mod, the go command maintains
777
- a file named go.sum containing the cryptographic checksums of the
778
- module's dependencies.
779
-
780
- The form of each line in go.sum is three fields:
781
-
782
- <module> <version>[/go.mod] <hash>
783
-
784
- Each known module version results in two lines in the go.sum file.
785
- The first line gives the hash of the module version's file tree.
786
- The second line appends "/go.mod" to the version and gives the hash
787
- of only the module version's (possibly synthesized) go.mod file.
788
- The go.mod-only hash allows downloading and authenticating a
789
- module version's go.mod file, which is needed to compute the
790
- dependency graph, without also downloading all the module's source code.
791
-
792
- The hash begins with an algorithm prefix of the form "h<N>:".
793
- The only defined algorithm prefix is "h1:", which uses SHA-256.
794
-
795
- Module authentication failures
796
-
797
- The go command maintains a cache of downloaded packages and computes
798
- and records the cryptographic checksum of each package at download time.
799
- In normal operation, the go command checks the main module's go.sum file
800
- against these precomputed checksums instead of recomputing them on
801
- each command invocation. The 'go mod verify' command checks that
802
- the cached copies of module downloads still match both their recorded
803
- checksums and the entries in go.sum.
804
-
805
- In day-to-day development, the checksum of a given module version
806
- should never change. Each time a dependency is used by a given main
807
- module, the go command checks its local cached copy, freshly
808
- downloaded or not, against the main module's go.sum. If the checksums
809
- don't match, the go command reports the mismatch as a security error
810
- and refuses to run the build. When this happens, proceed with caution:
811
- code changing unexpectedly means today's build will not match
812
- yesterday's, and the unexpected change may not be beneficial.
813
-
814
- If the go command reports a mismatch in go.sum, the downloaded code
815
- for the reported module version does not match the one used in a
816
- previous build of the main module. It is important at that point
817
- to find out what the right checksum should be, to decide whether
818
- go.sum is wrong or the downloaded code is wrong. Usually go.sum is right:
819
- you want to use the same code you used yesterday.
820
-
821
- If a downloaded module is not yet included in go.sum and it is a publicly
822
- available module, the go command consults the Go checksum database to fetch
823
- the expected go.sum lines. If the downloaded code does not match those
824
- lines, the go command reports the mismatch and exits. Note that the
825
- database is not consulted for module versions already listed in go.sum.
826
-
827
- If a go.sum mismatch is reported, it is always worth investigating why
828
- the code downloaded today differs from what was downloaded yesterday.
829
-
830
- The GOSUMDB environment variable identifies the name of checksum database
831
- to use and optionally its public key and URL, as in:
832
-
833
- GOSUMDB="sum.golang.org"
834
- GOSUMDB="sum.golang.org+<publickey>"
835
- GOSUMDB="sum.golang.org+<publickey> https://sum.golang.org"
836
-
837
- The go command knows the public key of sum.golang.org, and also that the name
838
- sum.golang.google.cn (available inside mainland China) connects to the
839
- sum.golang.org checksum database; use of any other database requires giving
840
- the public key explicitly.
841
- The URL defaults to "https://" followed by the database name.
842
-
843
- GOSUMDB defaults to "sum.golang.org", the Go checksum database run by Google.
844
- See https://sum.golang.org/privacy for the service's privacy policy.
845
-
846
- If GOSUMDB is set to "off", or if "go get" is invoked with the -insecure flag,
847
- the checksum database is not consulted, and all unrecognized modules are
848
- accepted, at the cost of giving up the security guarantee of verified repeatable
849
- downloads for all modules. A better way to bypass the checksum database
850
- for specific modules is to use the GOPRIVATE or GONOSUMDB environment
851
- variables. See 'go help private' for details.
852
-
853
- The 'go env -w' command (see 'go help env') can be used to set these variables
854
- for future go command invocations.
771
+ When the go command downloads a module zip file or go.mod file into the
772
+ module cache, it computes a cryptographic hash and compares it with a known
773
+ value to verify the file hasn't changed since it was first downloaded. Known
774
+ hashes are stored in a file in the module root directory named go.sum. Hashes
775
+ may also be downloaded from the checksum database depending on the values of
776
+ GOSUMDB, GOPRIVATE, and GONOSUMDB.
777
+
778
+ For details, see https://golang.org/ref/mod#authenticating.
855
779
` ,
856
780
}
857
781
@@ -865,8 +789,8 @@ regardless of source, against the public Go checksum database at sum.golang.org.
865
789
These defaults work well for publicly available source code.
866
790
867
791
The GOPRIVATE environment variable controls which modules the go command
868
- considers to be private (not available publicly) and should therefore not use the
869
- proxy or checksum database. The variable is a comma-separated list of
792
+ considers to be private (not available publicly) and should therefore not use
793
+ the proxy or checksum database. The variable is a comma-separated list of
870
794
glob patterns (in the syntax of Go's path.Match) of module path prefixes.
871
795
For example,
872
796
@@ -876,10 +800,6 @@ causes the go command to treat as private any module with a path prefix
876
800
matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private,
877
801
and rsc.io/private/quux.
878
802
879
- The GOPRIVATE environment variable may be used by other tools as well to
880
- identify non-public modules. For example, an editor could use GOPRIVATE
881
- to decide whether to hyperlink a package import to a godoc.org page.
882
-
883
803
For fine-grained control over module download and validation, the GONOPROXY
884
804
and GONOSUMDB environment variables accept the same kind of glob list
885
805
and override GOPRIVATE for the specific decision of whether to use the proxy
@@ -892,18 +812,14 @@ users would configure go using:
892
812
GOPROXY=proxy.example.com
893
813
GONOPROXY=none
894
814
895
- This would tell the go command and other tools that modules beginning with
896
- a corp.example.com subdomain are private but that the company proxy should
897
- be used for downloading both public and private modules, because
898
- GONOPROXY has been set to a pattern that won't match any modules,
899
- overriding GOPRIVATE.
900
-
901
815
The GOPRIVATE variable is also used to define the "public" and "private"
902
816
patterns for the GOVCS variable; see 'go help vcs'. For that usage,
903
817
GOPRIVATE applies even in GOPATH mode. In that case, it matches import paths
904
818
instead of module paths.
905
819
906
820
The 'go env -w' command (see 'go help env') can be used to set these variables
907
821
for future go command invocations.
822
+
823
+ For more details, see https://golang.org/ref/mod#private-modules.
908
824
` ,
909
825
}
0 commit comments