Home > Net >  Tunnel git request from server trough user's computer
Tunnel git request from server trough user's computer

Time:09-06

the company I work for is using a self-hosted gitlab at gitlab.company.net. The gitlab is only accessible from within the company network. I also have a company server which is not in the company network.
I would like to be able to work with git on the server, as manually copying files back and forth during development is very cumbersome. Ideally the solution would also work for different users, i.e. depending on who is working on the server the connection gets tunneled through their computer. So far I tried to make it work with SSH tunneling, but I am not sure if it is possible or if I am doing something wrong.

On the server I configured the git to use localhost as proxy for gitlab.company.net:

git config --global http.https://gitlab.company.net.proxy localhost:4443

I login with ssh using:

ssh -R 4443:gitlab.company.net:443 -i keyfile user@server-ip

So my hope was that with the proxy setting the request gets redirected to localhost and from there to my computer because of the -R option, which then redirects it to gitlab.company.net.
It seems to do something as I get different responses when trying to clone depending on whether I am logged into the company network:

fatal: unable to access 'https://gitlab.company.net/...': Received HTTP code 400 from proxy after CONNECT

or not:

fatal: unable to access 'https://gitlab.company.net/...': Failed to connect to localhost port 4443 after 0 ms: Connection refused

Any help is appreciated. Thank you.

CodePudding user response:

I could not make it work with https cloning but I found the solution for ssh here.

You need to connect to the server with -R port:gitlab.company.net:22, e.g.:

ssh -R 2020:gitlab.company.net:22 -i keyfile user@server-ip

And on the server you can then clone by replacing gitlab.company.net with localhost and also specifying the port number, e.g.:

git clone ssh://git@localhost:2020/....
  • Related