Unable to access remote repository for Go module import

Viewed 68

I need to be able to import Go modules from my company's private Gitlab repository, but there's something I'm very obviously not getting about how it works.

The module in question looks something like this at the top of my go.mod file:

module gitlab.domain.company.com/path/to/repository

Here's my go env:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\E049839\AppData\Local\go-build
set GOENV=C:\Users\E049839\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\E049839\go\pkg\mod
set GONOPROXY=*.company.com
set GONOSUMDB=*.company.com
set GOOS=windows
set GOPATH=C:\Users\E049839\go
set GOPRIVATE=*.company.com
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\N\the_program\go.mod
set GOWORK=
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\E049839\AppData\Local\Temp\go-build416370598=/tmp/go-build -gno-record-gcc-switches

I use ssh exclusively to push and pull from the company's Gitlab, so I don't know why that would be my issue, but here's my .gitconfig anyway:

[url "ssh:/git@gitlab.domain.company.com/"]
    insteadOf = https://gitlab.domain.company.com/
[url "ssh:/git@gitlab.company.com/"]
    insteadOf = https://gitlab.company.com/

Any time I try to go build or go get for this project, I'm given this error:

go: gitlab.domain.company.com/path/to/lib: unrecognized import path "gitlab.domain.company.com/path/to/lib": https fetch: Get "https://gitlab.domain.company.com/path/to/lib?go-get=1": dial tcp xx.xx.xxx.xxx:xxx: connectex: No connection could be made because the target machine actively refused it.

Some info redacted obviously.

My version of Go is 1.19 running on Windows. I'm out of ideas trying to fool with this module, to the extent that I'm considering rewriting the entire application in a language with sensible version control.

4 Answers

Your ssh url looks a little funky. My github one used to look like ssh://. That error means it is not using ssh, so it is not reading the config correctly.

There are known issues[1] [2] with retrieving go modules from gitlab projects, particularly those that reside within subgroups.

There's a few workarounds described in that issue (one of which you are using) but this does not work in all circumstances like subgroups nested beyond top-level-group/project.

For self-hosted instances you can enable the go proxy which also eliminates the problem. Or if you have your project directly under a top-level group, this will also avoid the problem.

In your case, however, this seems to be [additionally] a misconfiguration because the error is a networking issue (despite you being able to access these services normally):

No connection could be made because the target machine actively refused it

This is a networking error not necessarily related to gitlab or go get...

It had totally slipped my mind that my ssh was configured with a password. Now that I'm past that, it's working swimmingly. Thank you to everyone who contributed. I'm leaving this up as a suggestion to anyone experiencing the same issue in the future: if you have a password configured with ssh, you will have to account for it. In my case, I was able to just remove it, which is probably not best practice, but works.

Try the same setting (with ssh://... instead of ssh:/...) in %USERPROFILE%\.gitconfig.

I am not aware of a git.config file.

Related