Skip to content

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

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

Closed
sedyh opened this issue Oct 24, 2024 · 7 comments
Closed

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

sedyh opened this issue Oct 24, 2024 · 7 comments

Comments

@sedyh
Copy link

sedyh commented Oct 24, 2024

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://[email protected]:2224/gamedev/commons.git

Add a new ~/.gitconfig entry:

git config --global url."[email protected]:".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:
        [email protected]: 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:
#36666
#26232

@sedyh
Copy link
Author

sedyh commented Oct 24, 2024

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:
        [email protected]: 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
Copy link
Author

sedyh commented Oct 24, 2024

This does not help and not changing the output of go get -x -v:
#52942 (comment)

@seankhliao
Copy link
Member

you also need ssh config

@seankhliao
Copy link
Member

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

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2024
@sedyh
Copy link
Author

sedyh commented Oct 24, 2024

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
Copy link
Author

sedyh commented Oct 24, 2024

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 = [email protected]
        name = Artem Sedykh
[url "ssh://[email protected]:2224/"]
        insteadOf = https://gitlab.private.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants