golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.69k stars 17.62k forks source link

cmd/go: get can't auth via ssh for private repo on non-standard port #70026

Closed sedyh closed 3 hours ago

sedyh commented 3 hours ago

Go version

go version go1.23.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/sedyh/.cache/go-build'
GOENV='/home/sedyh/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/sedyh/.local/share/go/path/go1.23.1/pkg/mod'
GOPRIVATE='gitlab.private.com'
GONOPROXY='gitlab.private.com'
GONOSUMDB='gitlab.private.com'
GOOS='linux'
GOPATH='/home/sedyh/.local/share/go/path/go1.23.1'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/sedyh/.local/share/go/root/go1.23.1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/sedyh/.local/share/go/root/go1.23.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/sedyh/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/sedyh/Documents/go/aboba/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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4210291150=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Add ssh key to gitlab and check ssh server address:

ssh://git@gitlab.private.com:2224/gamedev/commons.git

Add a new ~/.gitconfig entry:

git config --global url."git@gitlab.private.com:".insteadOf "https://gitlab.private.com/"

Export GOPRIVATE in ~/.zshrc (also could export GONOSUMDB and GONOPROXY, but not necessary).

export GOPRIVATE="gitlab.private.com"

Trying to get package:

go get gitlab.private.com/gamedev/commons

What did you see happen?

go: module gitlab.private.com/gamedev/commons: git ls-remote -q origin in /home/sedyh/.local/share/go/path/go1.23.1/pkg/mod/cache/vcs/b58bd48d22cffaaf92db9d87a71861290aa006affbdfbefce917125ccddb3f60: exit status 128:
        git@gitlab.private.com: Permission denied (publickey,password).
        fatal: Could not read from remote repository.

        Please make sure you have the correct access rights
        and the repository exists.

What did you expect to see?

Working download. The key is 100% right, I've rechecked it several times. It should work because gamedev is userspace, not the subgroup. I guess its related with ssh server is being on 2224 port and not 22, because it worked on a different gitlab instance with a standard port. I think : in insteadof config should be able to use any port? Also, adding :2224 in exported variables and ~/.gitconfig does not help so I don't know what else can I try to make it work.

Related: https://github.com/golang/go/issues/36666 https://github.com/golang/go/issues/26232

gabyhelp commented 3 hours ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

sedyh commented 3 hours ago

go get -v -x gitlab.private.com/gamedev/commons

# get https://gitlab.private.com/?go-get=1
# get https://gitlab.private.com/gamedev/commons?go-get=1
# get https://gitlab.private.com/gamedev?go-get=1
# get https://gitlab.private.com/gamedev/commons?go-get=1: 200 OK (0.819s)
get "gitlab.private.com/gamedev/commons": found meta tag vcs.metaImport{Prefix:"gitlab.private.com/gamedev/commons", VCS:"git", RepoRoot:"https://gitlab.private.com/gamedev/commons.git"} at //gitlab.private.com/gamedev/commons?go-get=1
mkdir -p /home/sedyh/.local/share/go/path/go1.23.1/pkg/mod/cache/vcs # git3 https://gitlab.private.com/gamedev/commons.git
# lock /home/sedyh/.local/share/go/path/go1.23.1/pkg/mod/cache/vcs/b58bd48d22cffaaf92db9d87a71861290aa006affbdfbefce917125ccddb3f60.lock
# /home/sedyh/.local/share/go/path/go1.23.1/pkg/mod/cache/vcs/b58bd48d22cffaaf92db9d87a71861290aa006affbdfbefce917125ccddb3f60 for git3 https://gitlab.private.com/gamedev/commons.git
cd /home/sedyh/.local/share/go/path/go1.23.1/pkg/mod/cache/vcs/b58bd48d22cffaaf92db9d87a71861290aa006affbdfbefce917125ccddb3f60; git ls-remote -q origin
# get https://gitlab.private.com/gamedev?go-get=1: 200 OK (0.955s)
# get https://gitlab.private.com/?go-get=1: 200 OK (1.024s)
0.866s # cd /home/sedyh/.local/share/go/path/go1.23.1/pkg/mod/cache/vcs/b58bd48d22cffaaf92db9d87a71861290aa006affbdfbefce917125ccddb3f60; git ls-remote -q origin
# get https://gitlab.private.com/gamedev/commons.git
# get https://gitlab.private.com/gamedev/commons.git: 200 OK (0.213s)
go: module gitlab.private.com/gamedev/commons: git ls-remote -q origin in /home/sedyh/.local/share/go/path/go1.23.1/pkg/mod/cache/vcs/b58bd48d22cffaaf92db9d87a71861290aa006affbdfbefce917125ccddb3f60: exit status 128:
        git@gitlab.private.com: Permission denied (publickey,password).
        fatal: Could not read from remote repository.

        Please make sure you have the correct access rights
        and the repository exists.
sedyh commented 3 hours ago

This does not help and not changing the output of go get -x -v: https://github.com/golang/go/issues/52942#issuecomment-1129799918

seankhliao commented 3 hours ago

you also need ssh config

seankhliao commented 3 hours ago

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

sedyh commented 3 hours ago

You also need ssh config.

@seankhliao, I think the key is in ssh config, it was added via ssh-add. So it may be a bug.

ssh-add -l
3072 SHA256:t7gDkBCuViQVz1k2OG33BwcO3JTlm+Rgot848F/QKa0 sedyh@sedyh-pc (RSA)
sedyh commented 2 hours ago

Well, that was happening because there was two servers on my machine and git was looking on 22 which is tty, and not gitlab ssh server ._.

So I need to specify the port manually:

cat ~/.gitconfig
[user]
        email = sedyh.moto@gmail.com
        name = Artem Sedykh
[url "ssh://git@gitlab.private.com:2224/"]
        insteadOf = https://gitlab.private.com/