CacheGenie Tunnels
A tunnel puts a server that cannot be reached from the internet behind the CDN.
On this page
A tunnel puts a service that cannot be reached from the internet behind the CDN. You run the connector, a small Docker container, on a machine that can reach the service; it connects out to us, so nothing on your network has to be opened, and your zone fetches from the service through it.
CacheGenie Tunnels is available on request. We switch it on for your account when you ask: until then the NOC has no Tunnels page and the API answers 403. The connector is a private Docker image, which we give you access to at the same time; it is not publicly downloadable.
How it works#
- A tunnel has one connector and one or more endpoints. An endpoint is a service the connector can reach, such as
https://192.168.1.5:443orhttp://app:8080, and a zone uses one endpoint as its origin. - The connector measures its round trip to each of our locations, connects to the nearest, and moves by itself when that location is taken out of service. Every other location reaches your service through that one, so that location, the tunnel's entry location, is the zone's Home PoP.
- A zone behind a tunnel does everything any zone does: caching, a whole website with its logins and forms, WebSockets and server-sent events, uploads of any size, signed links, blocking, maintenance mode and statistics. To let only your own people reach a private service, lock its zone with CacheGenie Sentinel.
- The connection between the connector and us is encrypted (WireGuard), and it carries only requests for your endpoints. Bandwidth is counted as for any zone, by what visitors receive.
- The connection looks after itself. Both ends send a keepalive every 25 seconds, so a firewall or NAT in between keeps it open. If our location restarts, the connector connects again by itself within about a minute; if the location stops answering altogether, it moves to the next nearest; and if the connector itself stops working, it restarts (see Health check).
Create a tunnel#
On the Tunnels page of the NOC, press New tunnel, give it a name of 1 to 64 characters, which only you see, and press Create tunnel. Its token is shown next, a value starting cgt_. Copy it now: it is shown only this once.
Run the connector#
The connector is a private Docker image, built for linux/amd64, linux/arm64 and linux/arm/v7; Docker pulls the right one for the machine. It needs no root, no kernel module and no open port, and its one setting is the token, in the environment variable CG_TUNNEL_TOKEN. Run it on a machine that can reach the services you will add as endpoints:
docker run -d --name cachegenie-tunnel --restart unless-stopped \
-e CG_TUNNEL_TOKEN=cgt_... \
{IMAGE}:latest{IMAGE} is the image we give you access to. The tunnel's page shows the same command under Connector, or, until the image is available to you, says to email us for it.
On a platform that runs Docker containers, run the same image as one replica with the token in CG_TUNNEL_TOKEN; it needs no volume or privilege. Inside a container, localhost is the container itself, so name your service by an address or a hostname the container can reach.
The token#
The connector reads the token from the first of these that is set: the --token option, the environment variable CG_TUNNEL_TOKEN, or a file named with --token-file. Whoever holds the token can connect the tunnel from anywhere, so keep it secret; the connector never writes it to its log. A token is shown only when it is made. If it is lost, or may have been seen by someone else, press Make a new token under Connector on the tunnel's page: the old token stops working at once, the connector using it is cut off, and the tunnel's zones answer visitors with an error page until a connector runs with the new one.
What the connector needs#
- Outbound HTTPS (TCP 443) to
api.cachegenie.com, which it reports to every 30 seconds. - Outbound TCP to port 443 of our servers, to find the nearest: a connection that opens and closes, with nothing sent.
- Outbound UDP to port 42819 of the server it connects to.
- Whatever it takes to reach your services.
Nothing inbound: no port is opened or forwarded to the connector.
Health check#
The connector answers two addresses on port 42820 inside its container, for a platform's probe or your monitoring, each with a short JSON body that carries no token, key or address:
/healthanswers 200 while the connector is working, and 503 when it is not: it has been stuck for 10 minutes (an unreachable API alone does not count: it keeps the tunnel up and asks again), or its tunnel has been down for 15 minutes while it should be up. Point a liveness probe or a restart rule here: a restart is the cure for both./readyanswers 200 while the tunnel is connected, and 503 otherwise, with the reason, such asbusywhile another connector runs with the same token. Use it for monitoring and alerts, not to restart: a connector waiting its turn is working as it should.
The image checks itself with Docker's own health check, so docker ps shows it healthy. On a platform that runs Docker containers, set the probe to an HTTP GET of /health on port 42820; nothing else needs the port. The image sets that address for you; elsewhere, the option --health 0.0.0.0:42820 or the environment variable CG_TUNNEL_HEALTH turns the two addresses on.
The connector watches itself as well, whether or not anything probes it: when /health would fail twice in a row, half a minute apart, it stops with exit code 1, so Docker's restart policy or your platform starts it afresh.
One connector per tunnel#
A second connector started with the same token waits, and its log says another connector is running. It takes over once the first has stopped: within 30 seconds when the first was stopped cleanly, otherwise once the first has been silent for 90 seconds. To connect services in two places, make a tunnel for each.
Update the connector#
The connector never updates itself. Pull the image again and start a new container:
docker pull {IMAGE}:latest
docker rm -f cachegenie-tunnel
docker run -d --name cachegenie-tunnel --restart unless-stopped \
-e CG_TUNNEL_TOKEN=cgt_... \
{IMAGE}:latestThe tunnel is down for the few seconds the connector takes to start.
Endpoints#
Under Endpoints on the tunnel's page, press New endpoint for each service a zone will fetch from:
- Name: what the service is, 1 to 64 characters. Zones show it when you choose their origin.
- Address: the protocol,
httpsorhttp, which is how the connector talks to the service; the host, the address or name of the service as seen from where the connector runs, such as192.168.1.5,app.internalorweb; and the port, 1 to 65535, or empty for 443 with https and 80 with http. Private addresses and local names are fine: the connector makes the connection, never our servers, and it resolves a name itself.
A change reaches the connector within 30 seconds, and every zone using the endpoint follows it. An endpoint that is a zone's origin cannot be deleted: choose another origin for the zone first.
Use an endpoint as a zone's origin#
When creating a zone, or in the Origin tab of its page, set Origin type to CacheGenie Tunnel, then choose the Tunnel endpoint and the Delivery:
- Full website (cookies, forms, logins), the default: the whole site behind the CDN, pages, forms, logins and APIs included, exactly as a full site origin.
- Static files: files served and cached as from a standard origin, as Zone settings describes.
A few settings are decided by the tunnel:
- Origin shield (Home PoP) and Home PoP for dynamic requests are not used: the location the connector is connected to is the zone's Home PoP, for cached files and for every other request (see Origin shield).
- Follow redirects and Add canonical headers are not used: your service's redirects go to the visitor unchanged, and its private address is not one to name as canonical.
- Send Early Hints can be switched on with the Full website delivery, as on any full site.
- Verify origin SSL certificate is switched off when a zone becomes a tunnel zone, because most services on a private network carry a certificate of their own making. Switch it back on to have an https endpoint checked: it then has to present the zone's origin certificate, or a certificate a public authority issued for the name it is asked for, which is the endpoint's host unless the Host header or Forward host header says otherwise.
- An Origin certificate works on a tunnel zone: install it on the service an https endpoint points at. The tunnel carries the connection untouched, so the TLS is between our server and your service, end to end, and with Verify origin SSL certificate on it is checked there (see Origin certificates).
- Host header is sent to your service as the Host header. Left empty, the endpoint's host is sent; with Forward host header on, each visitor's hostname.
While the tunnel is switched off, or no connector is running, the zone answers visitors with an error page (502), and the tunnel's page says why.
Disable or delete a tunnel#
The Tunnel on switch under General on the tunnel's page turns a tunnel off without changing anything else: its connector is refused and its zones answer with the error page until it is switched back on. Its endpoints and token are kept. Delete tunnel removes the tunnel and its endpoints, and is refused while one of its endpoints is a zone's origin.
Through the API, see Tunnels in the API section.