HiddenForge
Latest release: 3.0.1.
I run my own services as onion services, and I wanted one container that gets
the Tor side right and that anyone can check: pinned inputs, signed releases and
a build you can reproduce. It hardens Tor and its surroundings. It does not
protect an application that gives away where it lives; see
What HiddenForge cannot protect you from.
docker pull sambent.dev/sam/hiddenforge # the maintainer's own registry
docker pull doingfedtime/hiddenforge # Docker Hub
Both registries serve the same digest, and the same signatures verify either
one. Verify what you pulled with the
verification guide.
The full guide is in the wiki.
Upgrading from 2.1.x? Nothing to do: same compose file, same keys, same
address. Inside the container every command is now hiddenforge <command>.
See Upgrading.
From 2.0.4? Your keys carry over, but read
Upgrading from 2.0.4 first.

Quick Start (3 steps)
docker compose up pulls the image (sambent.dev/sam/hiddenforge) by itself:
# 1. Download the compose file
curl -O https://sambent.dev/sam/HiddenForge/raw/branch/master/docker-compose.yml
# 2. Make the two edits marked <-- EDIT in docker-compose.yml
# - Change MYAPP to your service name (e.g. BLOG, TIPSITE); it appears twice
# - Replace nginx:alpine with your actual backend image
# 3. Start it
mkdir -p ./tor-keys
docker compose up -d
# Your .onion address appears here once Tor bootstraps (first boot: a few minutes, up to ~6):
# Replace "myapp" with whatever you named your service in step 2
docker compose exec tor hiddenforge show --name myapp
All security flags are set in the compose file. The backend service is
network-isolated and never exposed to the internet.
The compose file pulls :latest. Run hiddenforge verify-image before you
deploy, and pin the verified digest if you want a deployment that never moves.
What it is: a hardened Tor onion service container. Tor 0.4.9.17, compiled
from Tor Project's signed source, on Docker Hardened Images' minimal static
base, with Tor's vanguards-lite pinned on and native bandguards and rendguard
attack detectors. The image holds Tor, its libraries and one small Rust binary:
no shell, no package manager, no Python. Zero known vulnerabilities at every
severity, from two scanners. It is built offline from a locked set of verified
inputs, and the build is reproducible. It is built against a state-level
adversary; the assumptions and their limits are in
docs/THREAT-MODEL.md, and how it maps to NIST and CIS
guidance is in docs/COMPLIANCE.md.
The compose files
| File |
What it is |
docker-compose.yml |
Docker quick start. Five capabilities, a healthcheck, restart: unless-stopped |
podman-compose.yml |
Rootless Podman quick start. Three capabilities, no healthcheck, restart: always |
examples/demo/app.yml |
A demo backend only, with no Tor service. It is merged with a generated fragment |
compose.service.yml |
Generated by hiddenforge setup for your deployment. Not in this repository |
compose.yml |
Your own base file in the examples. Not in this repository |
tests/golden_setup/compose.service.yml |
Expected output of setup, used by a test. Not deployable |
The two shipped files differ on purpose; the differences are listed in
docs/INTEGRATION.md.
Adopt it programmatically (CLI + machine contract)
You do not have to edit a compose file by hand or build mkp224o yourself. The
hiddenforge CLI emits a merge fragment, and the vanity generator ships
inside the image.
# 1. Emit a ready-to-merge fragment (does not touch your files)
hiddenforge setup --backend web:80 --name myapp --out ./deploy
# 2. Merge and start: your app needs no ports and no Tor code
docker compose -f compose.yml -f ./deploy/compose.service.yml up -d
# 3. Read the .onion (also written to ./tor-keys/myapp.onion)
hiddenforge show --keys ./tor-keys --name myapp --json
The CLI is a single file, scripts/hiddenforge in this repository: Python 3.10
or later, standard library only, nothing to pip install. Install it where
sudo also finds it (backup needs root under Docker):
sudo install -m 0755 scripts/hiddenforge /usr/local/bin/hiddenforge.
Subcommands: setup, info, version, show, status, doctor, vanity,
backup, restore, rotate, encrypt-key, decrypt-key, client-auth,
unseal-keys, verify-image, sbom. Every one supports --json, never prompts off a TTY, and uses stable
exit codes. vanity --bench prints the time estimate for a prefix on your
machine before you start.
→ Full integrator guide: docs/INTEGRATION.md
The image carries its own manifest and CLI:
docker run --rm sambent.dev/sam/hiddenforge:latest version --json
docker run --rm sambent.dev/sam/hiddenforge:latest info --json # the machine contract
What the Compose File Does
The included docker-compose.yml is ready to use as it is:
| What |
How |
| Drops all Linux capabilities |
cap_drop: ALL |
| Prevents privilege escalation |
security_opt: no-new-privileges:true |
| Two stacked seccomp filters |
runtime default profile + Tor's Sandbox 1 |
| Read-only container filesystem |
read_only: true |
| No host-side log file |
logging: driver: none |
| Network-isolated backend |
internal: true network, no ports: on backend |
| No DNS query leaves the tor container |
dns: 127.0.0.1 (backend names still resolve internally) |
| Key persistence |
./tor-keys volume mount |
The only two edits you need to make are flagged with <-- EDIT.
Environment Variables
{NAME}_TOR_SERVICE_HOSTS sets the hidden service port mappings.
- Three-part
"80:web:80" routes onion port 80 to Docker service web on port 80.
- Two-part
"80:8080" routes onion port 80 to 127.0.0.1:8080 (same-container only).
- Multiple ports:
"80:web:80,443:web:443"
NAME is lowercased and used as the service directory name (underscores become hyphens).
- Docker service names resolve to IP addresses at startup, so no static IPs are required.
TOR_SANDBOX set to 0 disables Sandbox 1 (default: 1)
HIDDENFORGE_VANGUARDS set to full pins layer-2 and layer-3 guards (the
full Vanguards defence) instead of Tor's vanguards-lite; it needs
TOR_SANDBOX=0. See Full vanguards.
HIDDENFORGE_KEY_PASSPHRASE_FILE turns on key encryption at rest (written for
you by hiddenforge setup --encrypt-keys)
{NAME}_TOR_EXPORT_CIRCUIT_ID set to haproxy gives that service's backend a
way to tell visitors apart (default: off). Tor then starts every connection to
the backend with a PROXY protocol v1 header whose source address carries the
Tor circuit ID (fc00:dead:beef:4dad::<id>), so the backend can rate-limit or
block one circuit without blocking every visitor. The backend must expect the
header, or every request to it fails: for nginx, listen 80 proxy_protocol;
and use $proxy_protocol_addr as the visitor's key.
Tor keeps its entry guards across restarts. Tor records the entry guards
it has chosen in its state file, and the DataDirectory is in memory, so each
restart used to make Tor choose new ones. Every new choice is another chance of
picking a hostile relay, and HiddenForge restarts itself on purpose (a moved
backend, Tor exiting, a host reboot). The state file is now saved as
tor-state (mode 0600, owned by the tor user) in the key directory of the
service whose name sorts first, every 10 minutes and at shutdown, and restored
before Tor starts. It is not encrypted by --encrypt-keys. backup and
restore carry it with the keys, and rotate moves it out with the old key,
so a new address never inherits the old one's guards. Deleting it only means
Tor chooses guards once more.
A recreated backend is followed automatically. Tor accepts only IPs, so the
service name is resolved at startup and the IP is written into the torrc. The
supervisor re-resolves every 30 seconds. When two successful lookups in a row
no longer include the old IP, it exits and the restart policy starts the
container again with a fresh lookup. The .onion address does not change.
Measured on 3.0.1: after the backend moved to a new IP the container restarted
61 seconds later and served the same address again at 77 seconds, and a backend
that was simply down for two and a half minutes caused no restart at all. A
backend whose name does not resolve when the container starts (after a host
reboot the runtime starts containers in no particular order) is watched the same
way. Its service is left out, and once the name resolves the container restarts
and configures it: 46 seconds after the backend came up in that measurement.
Until then hiddenforge status lists the mapping in dropped_mappings. ready
means every service Tor is configured with is reachable, and a dropped mapping
is not configured. With other services up, the container can be ready while
one is missing, so check that dropped_mappings is empty as well.
This relies on a restart policy, which both shipped compose files set
(restart: unless-stopped; always in the Podman file).
Upgrading
From any 2.1.x or 3.0.x release: pull the new image and recreate the
container. The compose files, the key volume, the *_TOR_SERVICE_HOSTS lines
and the onion address stay as they are, and the healthcheck your compose file
already declares keeps working. Upgrading a 2.1.6 volume and rolling it back
were both tested with the same key.
Inside the container every command is hiddenforge <command>; the image has
no shell, no Python and no cat. Read the address with
hiddenforge show --name myapp, or from ./tor-keys/myapp.onion on the host.
The full list is in the CHANGELOG.
Four hardening options are new in 3.0, all off by default:
| Option |
What it does |
How |
| No-root mode |
The container starts as the tor user with no capabilities at all; nothing ever runs as root |
hiddenforge setup --no-root |
| Full vanguards |
Pins 3 layer-2 and 8 layer-3 guards, rotated as the Vanguards addon does, against guard discovery on a long-lived service. Costs Tor's own seccomp sandbox |
HIDDENFORGE_VANGUARDS: full and TOR_SANDBOX: "0" in the tor service's environment |
| Client authorization |
Only clients you give a key to can reach the service; to anyone else the address leads nowhere |
hiddenforge client-auth add --name myapp --client alice, then restart the container |
| Key encryption at rest |
The service key is kept on the volume only encrypted (AES-256-GCM, scrypt), and decrypted into RAM at every start |
hiddenforge setup --encrypt-keys. The generated deploy.sh creates a random passphrase in ./key-passphrase.txt if there is none |
Key encryption protects a volume, disk or backup taken while the service is
stopped. It does not protect a running host, and it protects nothing if the
passphrase file sits on the same disk. Back the passphrase up separately: without
it the address is gone. To turn it off (or before rolling back to 2.1.6, which
cannot read a sealed key), stop the service and run
hiddenforge unseal-keys --keys ./tor-keys --name myapp --passphrase-file ./key-passphrase.txt,
then remove the passphrase lines from the compose file.
Full vanguards
Tor's built-in vanguards-lite pins four layer-2 guards and nothing at layer 3.
Tor's own proposal 333 says a long-lived, high-risk onion service relying on
that alone "might provide those services with a false sense of security" and
should run the full Vanguards defence. HIDDENFORGE_VANGUARDS: full does that
natively: 3 layer-2 guards (each kept 1 to 45 days) and 8 layer-3 guards (1 to
48 hours), chosen bandwidth-weighted the way the Vanguards addon chooses them,
replaced when they expire or leave the consensus, and kept across restarts in
<first service>/vanguards-full.state on the key volume.
The cost: the pins are applied with SETCONF, and Tor's Sandbox 1 rejects every
SETCONF, so this mode needs TOR_SANDBOX: "0". The container still runs under
the engine's seccomp profile, Landlock and the capability drop; what goes is the
second, Tor-specific filter. The container refuses to start with full