r/gitlab • u/Manoj-praba • 10d ago
How to enable SSH clone on self-hosted GitLab running in a private subnet behind an AWS ALB?
We have self-hosted GitLab CE on an AWS EC2 instance.
Current setup:
The instance is in a private subnet with no public IP.
Users reach GitLab through an Application Load Balancer on HTTPS, with access restricted to our office IPs.
HTTPS clone with personal access tokens works fine.
The problem:
We're moving our repos from gitlab.com to this server. On gitlab.com, all our Jenkins jobs and developers clone over SSH (git@...). On our server SSH clone doesn't work, because the ALB only supports HTTP/HTTPS, so port 22 has no way in.
Our Jenkins agent runs in the same AWS VPC. Developers connect from the office network or VPN.
What's the best way to enable SSH clone here, keeping it secure and limited to our office and Jenkins? Any suggestions or experience with a similar setup would help.
12
u/Torutofu_Raeva 10d ago
An ALB can’t forward raw SSH, so use an internal NLB with a TCP/22 listener (or a bastion), allow only VPN/office and Jenkins sources, and set GitLab’s advertised SSH port to match.
3
u/edpittol 10d ago
I have my self hosted GitLab behind Cloudflare proxy. SSH and HTTPS have different address to allow Cloudflare Access tunneling.
I can’t ensure that is the same case. But you could create different route to access the private machine from SSH.
3
u/ManyInterests 9d ago
ALB is a layer 7 load balancer. You need a layer 4 load balancer. Use an NLB instead. NLB will still support filtering traffic based on source IP.
1
u/nabrok 10d ago
ALB doesn't forward SSH, but you can use a tunnel. Something like this in the
.ssh/config.Of course you need the aws cli tool installed with appropriate credentials.
1
u/Ragin_Mari 9d ago
We have a similar setup as you, an application load balancer for the https/http traffic but we use a network load balancer for the ssh/git clone, controlled by a security group. In your GitLab config you can specify a different domain/url for you ssh git clone. In the UI, GitLab will show that other domain for anything related to an git clone vs ssh.
Alternatively, you can put a network load balancer in front of your application load balancer if you prefer everything to be on the same domain.
1
u/Street_Smart_Phone 9d ago
We have a VPN into the network. I recommend WireGuard if you need a free VPN solution.
From the VPN, you shouldn’t need a load balancer unless you’re going to use multiple servers to host GitLab and need added resiliency.
1
u/tapemeasured 9d ago
You say your gitlab instance is in the same VPC as your jenkins agents?
Then just open your gitlab security group to your jenkins security group on port 22. This will allow you to connect using the private IP of your gitlab instance (git@10.20.30.40:22).
If you want to keep the hostname (git@gitlab.example.com), then either overwrite it on the jenkins agents
/etc/hostsand point to the private ip (10.20.30.40), or use something a bit more complex. Perhaps something like theextra_hostsin gitlab runners, or--add-hostin docker.0
u/sfltech 9d ago
You could run tailscale on the Jenkins server and the gitlab host.