Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why 'go get' use https even if ssh is configured?

I have configured ssh properly and I can do git stuff with our private repo via ssh. But when I tested with go get or go test (for go modules) the cli is not using ssh but instead using https.

.gitconfig

[url "ssh://[email protected]:7999"]
    insteadOf = https://bitbucket.company.com/scm

~/.ssh/config

Host bitbucket.company.com
 User git
 Port 7999
 IdentityFile ~/.ssh/id_rsa

testing if ssh works

$ git ls-remote ssh://[email protected]:7999/project/repo.git
ab86e12ab20775a308b7d0b003ba562263fbfa23        HEAD
ab86e12ab20775a308b7d0b003ba562263fbfa23        refs/heads/master
ab86e12ab20775a308b7d0b003ba562263fbfa23        refs/tags/v0.0.1

testing go get

$ go get -v bitbucket.company.com/project/repo
go get bitbucket.company.com/project/repo: unrecognized import path "bitbucket.company.com/project/repo": https fetch: Get "https://bitbucket.company.com/project/repo?go-get=1": dial tcp 10.68.204.3:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

go version

go version go1.14.1 windows/amd64

go env

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\sailhenz\AppData\Local\go-build
set GOENV=C:\Users\sailhenz\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=none
set GONOSUMDB=*.company.com
set GOOS=windows
set GOPATH=C:\Users\sailhenz\Documents\Development\Go
set GOPRIVATE=*.company.com
set GOPROXY=https://goproxy.io,direct
set GOROOT=C:\Users\sailhenz\Documents\Software\go
set GOSUMDB=off
set GOTMPDIR=
set GOTOOLDIR=C:\Users\sailhenz\Documents\Software\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\sail~1\AppData\Local\Temp\go-build227330694=/tmp/go-build -gno-record-gcc-switches

Any setup/configuration I missed? Thanks in advance.

like image 398
sailhenz Avatar asked Apr 11 '26 17:04

sailhenz


1 Answers

Try:

[url "bitbucket.company.com:"]
    insteadOf = https://bitbucket.company.com/

That would transform any https://bitbucket.company.com/ into bitbucket.company.com: which would then:

  • be interpreted as SSH URL
  • be decoded (through ~/.ssh/config) as ssh://[email protected]:7999/...

The key is to use bitbucket.company.com alone, which is the Host entry in your ~/.ssh/config file, and means it will refer to the right private key file.


subham sarkar reports in the comments about golang/go issue 27344

The solution mentioned above does not seem to work with Go 1.13, and is in "backlog" with Go 1.14.

Check for testing if the same go get would work with Go 1.11.


The OP sailhenz mentions in the comments issue 27254

cmd/go: custom import path private repos require special configuration

adding .git in the import path resolves it

The ticket adds:

The reason the .git solution works is that it helps guide the go tool with information about where the VCS for custom import paths private.repo.net/user/package.git/... resides (namely (https|ssh)://private.repo.net/user/package.git).

Without this (i.e. with an import path like private.repo.net/user/package/a), the go tool first queries https://private.repo.net/user/package/a?go-get=1 to work out (according to https://tip.golang.org/cmd/go/#hdr-Remote_import_paths) where the VCS for that custom import path lives.

A go get -x private.repo.net/user/package is a good way to debug this.

like image 98
VonC Avatar answered Apr 13 '26 06:04

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!