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: go mod not using sshcommand configured in ~/.gitconfig #71482

Open
SOF3 opened this issue Jan 30, 2025 · 5 comments
Open

cmd/go: go mod not using sshcommand configured in ~/.gitconfig #71482

SOF3 opened this issue Jan 30, 2025 · 5 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@SOF3
Copy link

SOF3 commented Jan 30, 2025

Go version

go version go1.23.4 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/root/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4127018846=/tmp/go-build -gno-record-gcc-switches'

What did you do?

This is exactly the same as #65041 with thedifference that this issue concerns the global gitconfig ~/.gitconfig instead of the local .git/config, recreated as #65041 was closed due to the particular decision to ignore the local configuration.

I use a custom core.sshcommand configured at scope/origin global file:/root/.gitconfig, but Go (on docker run golang:1.23-alpine3.20, with apk add git 2.45.2) ignores the command I configured. I have to do GIT_SSH_COMMAND=$(git config core.sshcommand) go mod download to workaround this.

What did you see happen?

$ docker run --rm -it golang:1.23.4-alpine3.20
/go # apk add git
fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/community/x86_64/APKINDEX.tar.gz
(1/12) Installing brotli-libs (1.1.0-r2)
(2/12) Installing c-ares (1.33.1-r0)
(3/12) Installing libunistring (1.2-r0)
(4/12) Installing libidn2 (2.3.7-r0)
(5/12) Installing nghttp2-libs (1.62.1-r0)
(6/12) Installing libpsl (0.21.5-r1)
(7/12) Installing zstd-libs (1.5.6-r0)
(8/12) Installing libcurl (8.11.1-r0)
(9/12) Installing libexpat (2.6.4-r0)
(10/12) Installing pcre2 (10.43-r0)
(11/12) Installing git (2.45.3-r0)
(12/12) Installing git-init-template (2.45.3-r0)
Executing busybox-1.36.1-r29.trigger
OK: 20 MiB in 27 packages
/go # cd /root
~ # git config --global core.sshcommand 'echo fail ssh && false'
~ # git config --global url."git@github.com:".insteadOf "https://github.com/"
~ # (echo 'package main'; echo 'import "github.com/nosuchrepo/nosuchrepo"'; echo 'func main() {}') >main.go
~ # (echo 'module example.com/xyz'; echo 'go 1.23'; echo 'require github.com/nosuchrepo/nosuchrepo v0.0.0') > go.mod
~ # go mod tidy # This unexpectedly uses the `ssh` command
go: downloading github.com/nosuchrepo/nosuchrepo v0.0.0
go: example.com/xyz imports
        github.com/nosuchrepo/nosuchrepo: reading github.com/nosuchrepo/nosuchrepo/go.mod at revision v0.0.0: git ls-remote -q origin in /go/pkg/mod/cache/vcs/143f0bf38aa7670106f73ee5a75f1adb6d53f020b35c7e8b0dbf2c9d311f7766: exit status 128:
        ssh -o ControlMaster=no -o BatchMode=yes: line 0: ssh: not found
        fatal: Could not read from remote repository.

        Please make sure you have the correct access rights
        and the repository exists.
~ # GIT_SSH_COMMAND=$(git config core.sshcommand) go mod tidy This uses the configured `core.sshcommand` as expected
go: downloading github.com/nosuchrepo/nosuchrepo v0.0.0
go: example.com/xyz imports
        github.com/nosuchrepo/nosuchrepo: reading github.com/nosuchrepo/nosuchrepo/go.mod at revision v0.0.0: git ls-remote -q origin in /go/pkg/mod/cache/vcs/143f0bf38aa7670106f73ee5a75f1adb6d53f020b35c7e8b0dbf2c9d311f7766: exit status 128:
        fatal: protocol error: bad line length character: fail

What did you expect to see?

The global gitconfig should be directly read by the Go command instead of separately configuring individual commands.

@seankhliao
Copy link
Member

please show a complete reproducer.

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 30, 2025
@gabyhelp gabyhelp added the ToolProposal Issues describing a requested change to a Go tool or command-line program. label Jan 30, 2025
@seankhliao seankhliao removed the ToolProposal Issues describing a requested change to a Go tool or command-line program. label Jan 30, 2025
@SOF3 SOF3 changed the title cmd/go: go mod not using ~/.gitconfig settings cmd/go: go mod not using sshcommand configured in ~/.gitconfig Feb 4, 2025
@SOF3
Copy link
Author

SOF3 commented Feb 4, 2025

Description has been updated to provide full reproducing steps in the latest docker image.

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Feb 4, 2025
@seankhliao
Copy link
Member

cmd/go sets GIT_SSH_COMMAND because of #13453
maybe it's been long enough since ssh has been fixed that we can revert it?

@matloob
Copy link
Contributor

matloob commented Feb 5, 2025

@seankhliao I think that's something we should try.

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

No branches or pull requests

4 participants