Public operation of Gitea with OPNsense

Goals

It's also nice to be able to access your own services while travelling. The operation of a publicly accessible Gitea installed in the local network can be realised ingeniously simply with a Let's Encrypt certificate and HAProxy on the OPNsense firewall.

Nevertheless: This expansion stage is now suitable for public operation, but it has to be updated and maintained regularly now. Nothing is worse than an outdated and thus vulnerable installation.

Last updated:

Requirements

  • Gitea from the first part is installed and ready to go

Diagram

This makes the setup look like this:

                                                               ┌─────────────────────────────┐
                                                               │ TrueNAS / FreeBSD           │
                  ┌──────────────────────┐                     │ ┌─────────────────────────┐ │
                  │ OPNsense             │                     │ │ jails/git               │ │
WAN: 0.0.0.0:80  ─┼─► acme.sh:80  ───────┼─ LAN: 0.0.0.0:3000 ─┼─┼─► gitea                 │ │
WAN: 0.0.0.0:443 ─┼─► HAProxy:443        │                     │ │                         │ │
                  │                      │                     │ └─────────────────────────┘ │
                  └──────────────────────┘                     └─────────────────────────────┘

Lets Encrypt Certificates

OPNsense is able to create and automatically renew Let's Encrypt certificates with the ACME client plugin (os-acme-client). The huge advantage is that we have a centralised certificate management system, do not need to laboriously manage the certificates on the internal target systems and do not have to make any NAT or other firewall settings.

The basic settings as described here with the following definitions are sufficient here:

  • EXTERNHOSTNAME = The externally accessible host name (e.g. git.bsdbox.de)
  • EMAIL = E-Mail Adresse des Let's Encrypt Kontos (e.g. marcel@bsdbox.de)

HAProxy

HAProxy receives the calls for port 443 from the outside, encrypts the connection and forwards it to the internal Gitea server on port 3000. The nice thing is that here again the administration takes place centrally, the certificates can be used without any effort from Let's Encrypt and several services can be provided at the same time on port 443. The difference is made by the called external hostname. This makes it possible that e.g. https://git.domain.de is forwarded to Gitea and https://domain.de to the actual website, although both actually require port 443 on the same external IP address.

You can also go through this article here with the following definitions:

  • EXTERNHOSTNAME = The externally accessible host name (e.g. git.bsdbox.de)
  • IP = IP address of the local Gitea server (e.g. 192.168.1.102)
  • HOSTNAME = Hostname of the local Gitea server (e.g. git.bsdbox.local)
  • PORT = Port of the local Gitea server (3000)

Then please test the following:

  • The call https://EXTERNERHOSTNAME opens the Gitea login screen - OK!
  • The call https://EXTERNEIPADRESSE gets a ‘Forbidden’ error message - OK!

Voilá