Repository navigation
How It Works
This page explains what HiddenForge does, from the moment the container starts to a live .onion address. You don't need to know any of this to use it, but if you're going to trust it, you should be able to see inside it.
A normal website has an IP address, and anyone who connects learns that address. An onion service works differently. Instead of accepting connections directly, your Tor daemon reaches out and picks a handful of relays in the Tor network to act as introduction points. It publishes a signed record saying "to reach me, go through these relays." Your .onion address is really the public half of a cryptographic key, and that record is signed with the private half.
When a visitor opens your .onion, their Tor client and your Tor daemon each build circuits to a shared rendezvous point and connect through it. Neither side ever learns the other's IP address, and no one in the middle learns where your server is. That is the property HiddenForge is built to protect: the network can't see where you are.
The container's entrypoint runs as root just long enough to set things up, then hands off to an unprivileged tor user. Step by step:
-
It reads your settings. It scans the environment for any variable ending in
_TOR_SERVICE_HOSTSand turns each one into a hidden service. It processes them in a fixed order so the generated config is always identical for the same input. -
It resolves your backend. For a mapping like
80:web:80, it looks up the namewebon the container network and records its current IP address. Tor only ever gets an IP, never a name, so this lookup is re-checked later (step 7). A name that doesn't resolve yet, for example because the backend is still starting after a reboot, leaves that service out for now rather than failing the whole container. -
It writes the Tor config. It generates a
torrcfrom scratch with the hardening baked in (the full list is on the Security Model page), then sets the ownership and permissions Tor insists on. The data directory has to be private (mode0700) or Tor refuses to start. -
It drops privileges and starts Tor. It uses
su-execto switch from root to thetoruser and launches Tor. From here on, Tor is not running as root. -
It waits for Tor to be ready. It watches for Tor's control socket to appear, checking as the
toruser because the data directory is locked down. If Tor exits while it waits, the container stops within a second, with a failing exit code, instead of waiting out the clock. -
It starts Vanguards. Once Tor is up, it launches the Vanguards addon, which connects to Tor over that control socket and adds guard-protection defenses. If Vanguards can't start yet, the container keeps running and keeps trying; your service still works, with slightly less protection meanwhile.
-
It supervises. From then on it watches three things:
- Tor. If Tor exits, the container exits, because Tor is the whole point, and the restart policy brings it back.
- Vanguards. If it crashes it's restarted; if it keeps crashing it's paused for ten minutes and then tried again. It is never given up on for good.
- Your backends' names. Every 30 seconds it looks them up again. If a backend now answers at a different IP (it was recreated), or a name that didn't resolve at startup now does, and two lookups in a row agree, the container restarts so Tor gets the new address. A lookup that fails is never a reason to restart.
-
It publishes your address. Once Tor has established introduction points for a service and uploaded its descriptor, the address is written to
<name>.onionnext to the service folder, readable by your host user. It is not written earlier, so the file never names an address nobody can reach yet.
Your .onion address is a key file on disk, kept in the folder you mounted at /var/lib/tor/hidden_service. On every start, HiddenForge creates that folder only if it's missing, and never regenerates or overwrites an existing key; it only makes sure the folder and key belong to the tor user with private permissions. So restarting the container, or upgrading to a new image, keeps the same address, as long as you keep that folder. Lose the folder and the address is gone permanently. See Backing Up Your Onion Address.
Docker's health check doesn't just ask "is Tor running?" A running-but-stuck Tor (say, a censored network) would pass that and lie to you. Instead, HiddenForge asks Tor over the control socket, and reports healthy only when all of these hold:
- at least one onion service is configured;
- Tor has bootstrapped to 100% and built a circuit;
- every service has an address and established introduction points, the relays clients use to reach it (a service without them is unreachable, whatever its address file says);
- Tor has uploaded each service's descriptor to the network (clients find a service through it; without the upload a client cannot reach it, even with introduction points up);
- the Vanguards addon is running.
That's why "healthy" can take a few minutes on first boot, and why it means something real when it arrives. hiddenforge status reports the same verdict, with the reason when it's not ready.
- Tor is the daemon that runs your onion service. Its version is pinned in the image.
- Vanguards is an addon that watches the relays your service uses and defends against attacks that try to map its path back toward the server. See The Security Model for what it does and doesn't cover.
-
The control socket is a private Unix socket Tor exposes so Vanguards and the health check can talk to it. It's protected by file permissions, not a password, and only the
toruser can reach it. - Your backend is your actual app, on an internal network with no way out to the internet and no way in from it.
That's the whole machine. Nothing reaches your backend except Tor, nothing reaches Tor's control except the tor user, and nothing learns where any of it lives.
Start here
Older releases
Going deeper
- The Security Model
- Verifying the Image
- Reproducing the Build
- The hiddenforge CLI
- Rootless Podman
- Backing Up Your Onion Address
- Upgrading Safely
- Running Multiple Services
Help