Hey all! For the longest time I’ve had a server that hosts some things (eg Syncthing), but is only available via SSH tunneling.
I’ve been thinking of self-hosting more things like Nextcloud and Vaultwarden. I can keep my SSH tunneling setup but it might make it difficult to do SSL.
How do you manage the security of having public-facing servers?
You should be concerned, because there is always a risk, but there is also a risk when you are just using internet even without selfhosting. It is good to remember some rules:
- Keep apps up to date
- Open only that ports, that you need (80, 443, maybe 22 for ssh)
- If you open ssh port, use keys authentication and cut possibility logging with password
- Do not expose apps, that you are not need in this form, for example Yunohost allows to hide apps behind Yunohost SSO logging page
- Using cloudflare or/and Fail2Ban is cool
- Maybe I am a little bit paranoic, but I do not expose apps, that can be used anonymously by everyone, for example link shorters or pastebin alternatives.
It is not all of course.
I would add to this, disable icmp response on any internet facing server that does not aboluetly require it, it make it whitelisted to your know IPs when it is. If your server does not appear online then you will only really be vulernable to targeted attacks where your ip is already known.
Isolate your programs, keep the critical stuff away from the public using tailscale or a VPN, hell, even an SSH tunnel could work in your case, make sure to keep different password for each software for your database. If possible virtualize each software to keep them from communicating to other softwares. This is how i manage my infrastructure (or should be, i haven’t gotten yet to use tailscale for admin only websites).
Password protect your services, set up your web server correctly, use cloudflare for some extra security against stuff like DDoS/DoS attacks. Also less is more, do not expose what you don’t need to expose.
There is always inherent risk with opening up your stuff to the world wide web.
Some stuff you can’t even secure yourself; some services just have bad security practices. The only way to fix them would be to wait for an update or submit a pull request.
Here is my setup:
Cloudflare fronts all of my webserver traffic, and I have firewall rules in Cloudflare.
Then I have an OPNsense firewall that blocks a list of suspicious ips that updates automatically, and only allows port 80/443 connections from Cloudflare’s servers. The only other port I have open is for Wireguard to access all of my internal services. This does not go through Cloudflare obviously, and I use a different domain for my actual IP. I keep Vaultwarden internal for extra safety.
Next I run every internet facing service in k3s in a separate namespace. This namespace has its own traefik reverse proxy separate from my internal services. This is what port 80/443 forwards to. The namespace has network policies that prevent any egress traffic to my local network. Every container in the WAN facing namespace runs as a user with no login permission to the host. I am also picky about what storage I mount in them.
If you can get through that you deserve my data I think.
I need to learn more about cloudflare. Do you have the guide for this setup!
Unfortunately no guide, just things I’ve pieced together myself over the years.
Cloudflare is probably the easiest and most intuitive part of the setup though, you can setup dns/proxy/firewall rules very intuitively, and I’m sure there are plenty of guides out there.
Becarefull not everything is allowed true clousflare. I believe officialy only web content is. So having nextcloud behind it for example to upload and download files. Is as far as i am aware against the TOS.
To clarify, that is only the Cloudflare Tunnel service that has the “only do web traffic” ToS rule. Tunnel is their service that eliminates the need for port forwarding from your home network.
My understanding is that cloudflare DNS can also be a reverse proxy for you and still provide some benefit your security (though, unlike the tunnel service, you do need to expose ports from your home network to the internet).