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 is the hiddenforge runtime, one small Rust binary that acts as PID 1 and supervisor. By default it starts as root to set things up, then starts Tor as an unprivileged tor user. (In no-root mode, hiddenforge setup --no-root, it starts as that user and nothing ever runs as root.) 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 8). 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 gives up what it no longer needs. The supervisor drops every capability except the ones it needs to publish addresses and start
tor-user processes (three with the Docker file, two with the shipped Podman file). If you turned on key encryption at rest, it now decrypts the key into memory. It then confines itself with Landlock, which limits the files it and its children can reach; helpers it starts later get a stricter set with TCP denied. -
It starts Tor as the
toruser. It switches user and group itself, between creating the process and running it, then reads the result back from the kernel before trusting Tor with the key. From here on, Tor is not running as root and holds no capabilities. -
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 the helpers. Once Tor is up, it starts an upload watcher and the guard monitors (bandguards and rendguard, native ports of the Vanguards addon's detectors). Both connect to Tor over that control socket as the
toruser. If the monitors 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.
- The guard monitors. If they crash they're restarted; if they keep crashing they're paused for 10 minutes and then tried again. They are 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 both confirm it (neither still includes the old address), 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 guard monitors (reported as Vanguards) are running.
That's why "healthy" is usually under a minute on first boot and can take several minutes on a slow network, 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 the name for the defences that watch the relays your service uses and defend against attacks that try to map its path back toward the server. HiddenForge runs its own native bandguards and rendguard monitors, plus Tor's built-in vanguards-lite; the Python Vanguards addon is no longer in the image. See The Security Model for what it does and doesn't cover.
-
The control socket is a private Unix socket Tor exposes so the guard monitors, the upload watcher 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. There is no route to your backend except through Tor, and only the tor user can reach Tor's control socket.
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