Search code examples
gogitlabgo-modules

importing a go project from a private gilab repo using ssh: unknown revision


I am trying to import a go project from a private and self hosted gitlab repo using ssh. When i try to do so, i get the following error.

output

kbacon@kbacons-MacBook-Pro bbz % go get -x gitlab.wtf.notworking/bbq/tools@latest
# get https://gitlab.wtf.notworking/bbq/tools?go-get=1
# get https://gitlab.wtf.notworking/bbq/tools?go-get=1: 200 OK (0.413s)
mkdir -p /Users/kbacon/go/pkg/mod/cache/vcs # git3 https://gitlab.wtf.notworking/bbq/tools.git
# lock /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179.lock# /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179 for git3 https://gitlab.wtf.notworking/bbq/tools.git
cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l
0.013s # cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l
cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git ls-remote -q origin
0.020s # cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git ls-remote -q origin
# get https://gitlab.wtf.notworking/bbq/tools.git
# get https://gitlab.wtf.notworking/bbq/tools.git: 200 OK (0.186s)
go: gitlab.wtf.notworking/bbq/[email protected]: reading gitlab.wtf.notworking/bbq/tools/go.mod at revision v1.0.0: unknown revision v1.0.0

.gitconfig

[user]
        name = kbacon
        email = [email protected]
[url "[email protected]/"]
        insteadof = https://gitlab.wtf.notworking/

go mod file

module bbz
go 1.14
require (
    gitlab.wtf.notworking/bbq/tools v1.0.0
)

gitlab repo

the gitlab repo has a project with a release tag v1.0.0

The address i use to clone

ssh://[email protected]:2224/bbq/tools.git

ssh config file

Host gitlab.wtf.notworking
    User [email protected]
    Hostname gitlab.wtf.notworking
    IdentityFile ~/.ssh/company_gitlab # path to private key
    AddKeysToAgent yes

With this .gitconfig: .gitconfig

[user]
        name = kbacon
        email = [email protected]
[url "[email protected]:2224/"]
        insteadof = https://gitlab.wtf.notworking/

The go get command then requests my password, but it is supposed to be using ssh. Why is it asking for my password?

kbacon@kbacons-MacBook-Pro bbz % go get -x gitlab.wtf.notworking/bbq/tools@latest
# get https://gitlab.wtf.notworking/bbq/tools?go-get=1
# get https://gitlab.wtf.notworking/bbq/tools?go-get=1: 200 OK (0.424s)
mkdir -p /Users/kbacon/go/pkg/mod/cache/vcs # git3 https://gitlab.wtf.notworking/bbq/tools.git
# lock /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179.lock# /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179 for git3 https://gitlab.wtf.notworking/bbq/tools.git
cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l
0.030s # cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l
cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git ls-remote -q origin
[email protected]'s password:

Solution

  • If you are using an SSH URL with / instead of :, your .gitconfig should be:

    [url "ssh://[email protected]:2224/"]
            insteadof = https://gitlab.wtf.notworking/
    

    With ":"

    [url "[email protected]:2224:"]
            insteadof = https://gitlab.wtf.notworking/
    

    In your ssh config file, make sure to use the service account git, not your login, with the port, and a custom Host entry:

    Host gitlab-wtf
        User git
        Hostname gitlab.wtf.notworking
        IdentityFile ~/.ssh/company_gitlab # path to private key
        AddKeysToAgent yes
        Port 2224
    

    That way, you can use:

    [url "ssh://gitlab-wtf/"]
            insteadof = https://gitlab.wtf.notworking/
    

    No more git@ or :2224.