Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: support both .netrc and _netrc under windows #66832

Open
hauserx opened this issue Apr 15, 2024 · 5 comments · May be fixed by #67647
Open

cmd/go: support both .netrc and _netrc under windows #66832

hauserx opened this issue Apr 15, 2024 · 5 comments · May be fixed by #67647
Assignees
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@hauserx
Copy link

hauserx commented Apr 15, 2024

Go version

go version go1.22.1 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\xxx\AppData\Local\go-build
set GOENV=C:\Users\xxx\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\xxx\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\aep2rh\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\xxx\AppData\Local\Temp\go-build3364902034=/tmp/go-build -gno-record-gcc-switches

What did you do?

I have %USERPROFILE%\.netrc with proper credentials, and then:

set GOPROXY=https://<my_proxy>
go clean -modcache
go mod download -json gopkg.in/[email protected]

What did you see happen?

... gopkg.in/yaml.v3/@v/v3.0.1.info: 401 Unauthorized

What did you expect to see?

Download succeeds. It works if I copy:

%USERPROFILE%\.netrc
to
%USERPROFILE%\_netrc

Code in go expects _netrc:

base = "_netrc"

While e.g. curl library (used by e.g. git and other tools) reads first .netrc file and fallbacks to _netc if not found:
https://github.com/curl/curl/blob/49f83c30e43749752072c65a43d553eb015453d1/docs/cmdline-opts/netrc.md?plain=1#L28
This functionality was added in curl/curl@f9c7ba9

Found issue when adding go support to some tooling, everything else was working but not go.
There seem to be no one convention how those files should be named (e.g. bazel seems to look only for .netrc - code), but probably being compatible with curl way is most appropriate.

For reference, issue on go that lead to adding support of _netrc under windows: #24606

@cherrymui cherrymui added GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed NeedsFix The path to resolution is known, but the work has not been done. labels Apr 15, 2024
@cherrymui
Copy link
Member

cc @matloob @samthanawalla

@matloob matloob added this to the Go1.23 milestone May 23, 2024
@matloob matloob added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 23, 2024
khndhkx123 added a commit to khndhkx123/go that referenced this issue May 25, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/587997 mentions this issue: cmd/go: support both .netrc and _netrc under windows

@matloob matloob removed this from the Go1.23 milestone May 28, 2024
@matloob matloob added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed NeedsFix The path to resolution is known, but the work has not been done. labels May 28, 2024
@matloob
Copy link
Contributor

matloob commented May 28, 2024

Hi, looking at this again, it seems like the standard on Windows is to call the file _netrc, and doing a quick search I couldn't find cases where the file was called .netrc other than for curl. So I'm not totally sure if we should accept .netrc if almost all other tools accept only `_netrc.

@nightlyone
Copy link
Contributor

Maybe @bagder remembers why curl does it this way.

Is that legacy support for an early programming mistake when doing the windows port?

What happens if both files exist and contradict each other?

@bagder
Copy link

bagder commented May 28, 2024

curl supports .netrc on Windows as well (since 2019) simply because that's the standard name and we only ever supported _netrc to begin with because it used to be tricky to create files on Windows starting with a dot but there is no particular reason to stick with the underscore version anymore. For backwards compatibility curl still checks for the underscore version if there is no dot version.

.netrc is unfortunately really bad in general for cross-tool use since there is no defined syntax and tools and libraries treat it differently, making detection of it the same way across tools actually being less important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants