githubEdit

Exposing to the Internet

Why do we want to expose things?

We want to expose services to the internet for people to use! For example, a gitlab instance such as https://git.yadunut.dev/arrow-up-right should be publicly available!

However, Yadunand might not want to expose his TopSecretService running on port 8080 to the internet, so we have to be careful of how we are exposing these services.

Cloudflare Tunnels

How does it work?

Cloudflare Tunnel uses an outbound-only connection model to enable bidirectional communication. When you install and run cloudflared, cloudflared initiates an outbound connection through your firewall from the origin to the Cloudflare global network.

Most firewalls (and ours!) allow outbound traffic. cloudflared takes advantage of this standard by connecting out to the Cloudflare network from the server you installed cloudflared on. You can then configure your firewall to allow only these outbound connections and block all inbound traffic, effectively blocking access to your origin from anything other than Cloudflare.

All traffic will then be securely routed through the tunnel.


We will not be setting up via the Cloudflare Dashboard

For some reason, it requires us to add a card, even though it is a free service :<

But no fear, we can do it on the cli for free! WAHOOo

1

Installation On Ubuntu 24.04

For other Linux Distros: https://pkg.cloudflare.com/index.htmlarrow-up-right

2

For the rest of the setup, we are following:

If you did not manage to register a domain, you can skip the next few steps, instead just expose your services now with Cloudflare Temporary Tunnels

3

Login

It will then launch a window on cloudflare dashboard, where you can select a domain to authorize.

4

Create a Tunnel

This will create a tunnel with a unique UUID, and generate a tunnel credential file.

Take note of this UUID, as we will be using it later.

You can view your existing tunnels using: cloudflared tunnel list

chevron-rightIf you need to delete a tunnelhashtag

If the tunnel is still running, you need to run these to kill the process:

5

Creating Tunnel Configuration file

The configuration file should be created at /etc/cloudflared/config.yml

This is what the file can look like:

In our case, let's set up a config which points the docker subdomain to https://localhost:9443

Note that we had to add an additional config of noTLSVerify. This is because

Full Configuration File Docs (Cloudflare)arrow-up-right

6

Configure DNS

In our example, since we have configured cloudflared to tunnel traffic from: docker.<domain-name>.tld -> https://localhost:9443 , we need to configure out cloudflare DNS to also match this

7

Start running Cloudflared

Install

Start service

Check service

8

How to add new routes

1) Edit the config and add the new domain and which localhost its pointed to

2) Add new DNS route

3) Reload cloudflared

4) Check the status after

We should be able to view portainer now!

Nothing shows up? This might be the Portainer instance timed out for security purposes, to re-enable your Portainer instance, you will need to restart Portainer.

chevron-rightTo do this, we can run: hashtag

This might not work if the container is not named portainer. In that case, you should run:

We can also troubleshoot other problems on the Cloudflare Dashboard. Common culprits are DNS as well. (Are you sure you set that up?)


Quickly exposing services to the internet

Cloudflare provides a service called Quick Tunnelsarrow-up-right. This is usually meant for development environments, so it is not a good permanent solution!

It will generate a domain that you can use, which is pointed towards your ip address:

You will however, probably need to run these in separate tmux windows.. (It really isn't ideal!)

To tunnel to portainer specifically, you can run:

Additional Docs:

What are some other ways to do this?

This will not be covered in the scope of this workshop, but there are many other ways to do this as well.

VPNs: Wireguard/ Tailscale

Usually, VPNs are used when we only want our services exposed to authenticated users with a VPN client. This is the same principle that SoC uses, for us to connect into SoC internal network via SoC VPN.

Reverse Proxies: Traefik/ Caddy

Additional Readings

Last updated