Repository navigation
The hiddenforge CLI
hiddenforge is the operator tool, introduced in 2.1.0; this page describes 3.0.2. It writes a compose fragment for you, prints your .onion, reports whether the service is reachable, audits the running container's hardening, handles key backups, and manages key encryption at rest and client authorization. Most of it is also built into the image, so it runs with docker run too.
The CLI is one file, scripts/hiddenforge in the repository. It needs Python 3.10 or later and uses only the standard library, so there is nothing to pip install. Install it where sudo also finds it, because backup needs root under Docker:
sudo install -m 0755 scripts/hiddenforge /usr/local/bin/hiddenforgeOn an older Python it refuses to start and says so, instead of crashing half-way through a command:
hiddenforge needs Python 3.10 or later; this is Python 3.9.
2.0.4 has no CLI. On a 2.0.4 image, docker run <image> version --json just starts Tor.
Every subcommand accepts --json. The list below is the commands array in manifest.json, and a test keeps it equal to what the parser registers.
| Command | What it does | Key flags (defaults in brackets) |
|---|---|---|
setup |
Writes four files into --out: compose.service.yml (the fragment), deploy.sh, README.txt and hiddenforge.json. Touches none of your files. |
--backend host:port, --name [myapp], --out / -o [./hiddenforge-deploy], --onion-port [80], --service / --services (multi-service), --image, --keys [./tor-keys], --container [tor], --runtime docker|podman [docker], --no-root, --encrypt-keys, --passphrase-file [./key-passphrase.txt], --force, --non-interactive
|
info |
Prints the machine contract (manifest.json). |
--json |
version |
Prints name, version and contract version. | --json |
show |
Prints the .onion address(es). |
--keys, --name, --container (asks the container, as the tor user, for an address the host cannot read; when ./tor-keys does not exist, it reads the key directory that container mounts) |
status |
Reports container, Tor and hidden-service readiness. |
--container [tor] (a container name or a compose service), --keys
|
doctor |
Checks the hardening of the running container. |
--container [tor] (a container name or a compose service), --keys, --keys-only (skip docker inspect, check key files only) |
vanity |
Brute-forces a vanity .onion prefix with the generator inside the image. |
--prefix (required), --name [myapp], --keys, --threads [0], --bench, --seconds [5], --force, --image
|
backup |
Encrypted offline backup of the key volume. |
--keys, --out (required), --tool age|gpg|openssl, --passphrase-file, --require-aead
|
restore |
Restores a backup. |
--keys, --input (required), --tool, --passphrase-file, --force
|
client-auth |
Opt-in client authorization (Tor's restricted discovery): add, remove or list the clients allowed to reach a service. Runs a throwaway container from the image. |
positional add|remove|list, --name [myapp], --client (required for add and remove), --keys, --image
|
unseal-keys |
Turns key encryption at rest off: puts the plaintext key back. Stop the service first. |
--name [myapp], --keys, --passphrase-file (required), --image
|
rotate |
Destructive: archives the identity and starts over. |
--keys, --confirm (must be the literal ROTATE) |
encrypt-key |
Encrypts one service's key directory at rest (offline). |
--keys, --name (required), --tool age|gpg, --passphrase-file, --delete-plaintext, --force, --require-aead
|
decrypt-key |
Restores a key directory from its archive. | same flags as encrypt-key
|
verify-image |
Verifies the signed image digest. | positional image, --sigdir [signatures], --identity [sam@sambent.com], --skip-registry, --allow-classical-only, --allow-pq-only, --allowed-signers, --mldsa-pub
|
sbom |
Generates an SPDX SBOM for an image. |
--image, --out [./hiddenforge.spdx.json], --syft-image
|
Some flag notes that the table cannot hold:
- For
--tool,ageworks only from an interactive terminal.gpgis the scriptable choice, through--passphrase-file.opensslis refused forbackupbecause it is unauthenticated. -
--require-aeadmakesbackup,encrypt-keyanddecrypt-keyrefuse an envelope that is CFB with MDC instead of authenticated encryption. -
restoreanddecrypt-keyaccept a gpg file only when gpg's own status lines confirm it was decrypted and its integrity was proven (AEAD or MDC). A file that was never encrypted, or that has no integrity protection, is refused before anything is written. For a gpg file,restorereports the mode it found (aeadorcfb). -
backupandencrypt-keyrefuse a key volume that contains a symbolic link, naming it, instead of leaving it out of the archive. -
setup --no-rootwrites a fragment that starts the container as the tor user (100:101) with no capabilities at all;deploy.shhands the key directory to 100:101 once.setup --encrypt-keysadds the passphrase file as a compose secret (deploy.shcreates a random one if it is missing) and seals the service key on the volume at the first start. See the README for what that does and does not protect. -
client-auth addprints the client's private line once and does not store it; the service keeps only the public key. Restart the container after anyclient-authchange, because Tor reads the authorized clients at start. -
unseal-keyschecks that the restored key reads back as the sealed one before it removes the sealed copy. Afterwards removeHIDDENFORGE_KEY_PASSPHRASE_FILEand the passphrase secret from the compose file, or the key is sealed again at the next start. -
vanity --benchprints how long a prefix is expected to take on this machine, using--secondsof measurement, and generates nothing.vanityruns with no network. -
sbomruns on the host. It drives a digest-pinned syft container through the Docker socket, which the HiddenForge image deliberately does not have. -
Which stack
status,showanddoctoruse.--containertakes a container name or a compose service name, and the CLI asks both Docker and Podman for it (HIDDENFORGE_ENGINE=dockerorpodmanpins one, and a note says when the container runs under the other engine). If several containers run that service, the one that belongs to the current directory is used: its project name (fromCOMPOSE_PROJECT_NAME, the.envfile, thename:key of its compose file, or the folder's name) or its working folder, which may be a parent of the folder you are in. If that does not settle it, the command stops with exit 2, lists the candidates with their folders and says to pass--container <name>or tocdinto the stack. A script that runs these commands from another folder while two or more stacks run atorservice must pass--containerwith a container's own name. Without--keys,statusanddoctorread the host side of the key directory that container mounts and say which directory they read;showdoes the same when--containeris given and./tor-keysdoes not exist, and says tocdor pass--containeror--keyswhen./tor-keysdoes not exist. -
Errors for a person. Without
--json, a failure prints oneerror:line with the same exit code; a mistyped option prints oneerror:line that nameshiddenforge <command> --help. With--json, a failure is the one JSON document described below, and so is a mistyped option (exit code 2). -
unseal-keysandclient-authrun the image of the container that mounts the key directory (a running container first, stopped ones count), under the engine that runs it, and say which image they used.--imageandHIDDENFORGE_IMAGEwin over that, and the published:latestis used only when no container mounts the directory.vanityruns in the engine that holds the key directory. -
setupwarns on stderr when the backend host islocalhost,127.x.x.xor::1: that is the Tor container itself, not your app. The files are still written. -
rotatekeeps the key directory's mode, so a container started as root can still enter a key volume owned by the host user (0751). -
verify-imagechecks against pinned keys, never against keys found beside the signatures. It refuses when either half of the hybrid signature is missing;--allow-classical-onlyaccepts a missing ML-DSA half and--allow-pq-onlya missing SSH-FIDO2 half, both reported ascomplete: false, and an image with neither signature verified is refused even with both. From 3.0.2 it checks every ML-DSA signature in the set (ML-DSA-87 and ML-DSA-65) against its pinned key, requires the ML-DSA-87 one for any release after 3.0.1, and accepts ML-DSA-65 alone only for the releases made before that, which are listed by digest in the CLI. It needs OpenSSL 3.5 or later for the ML-DSA checks; on an older one it printsNOT VERIFIEDand exits 1. A flag is offered in the message only when there is a verified half for it to accept. A reference pinned by digest (repo@sha256:...) is compared with the signed digest on every run, with or without--skip-registry. See Verifying the Image.
A typical first run:
hiddenforge setup --backend web:80 --name myapp --out ./deploy
docker compose -f compose.yml -f ./deploy/compose.service.yml up -d
# rootless Podman: run Docker Compose against the Podman socket (see Rootless Podman)
hiddenforge show --keys ./tor-keys --name myapp --jsonWith --json, stdout carries exactly one JSON document and nothing else. Any narration goes to stderr, so hiddenforge show --json | jq . is always safe.
| Rule | Detail |
|---|---|
| One document | One JSON document, keys sorted; usually a single line. setup --json indents it, and info --json prints the manifest itself, indented, without ok or exit_code. |
| Always present |
ok (true only when the exit code is 0) and exit_code, on every command except info. |
| Nulls kept | A field with no value is null, not omitted. A script polling for an address can tell "no address yet" (onion: null) from "field missing". |
| Errors | A failure puts the reason in an error field and still exits non-zero. |
| No hanging off a TTY | Off a terminal nothing prompts: setup exits 2 if a required value such as --backend is missing, and backup, restore, encrypt-key and decrypt-key exit 2 unless given --passphrase-file, and so does unseal-keys. Exit 130 is only an interactive prompt answered with nothing, end of input, or Ctrl-C. |
To poll, call hiddenforge status --json and publish nothing until ready is true. Then read the address with hiddenforge show --json. This is the pattern manifest.json documents.
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Refused or failed (see stderr, or the error field with --json) |
| 2 | Usage, validation or environment error |
| 3 | A key appeared at the output path while a vanity search was running |
| 4 | Not ready yet (status: the container exists but is not ready, and reason names why; show: no address published yet) |
| 130 | Aborted at a prompt |
doctor exits 1 when any check fails and 0 otherwise; doctor and status exit 2 if the container is not found or if the name matches several stacks and the current directory does not pick one. Warnings do not change the exit code.
docker run --rm <image> <cmd> runs 13 of the 16. Anything else in that position boots Tor as usual.
docker run --rm sambent.dev/sam/hiddenforge:latest version --json
docker run --rm sambent.dev/sam/hiddenforge:latest info --json| Runs in the image | Does not |
|---|---|
setup, show, doctor, version, info, vanity, encrypt-key, decrypt-key, backup, restore, rotate, client-auth, unseal-keys
|
status, verify-image, sbom: they run on the host. docker exec <container> hiddenforge status exits 2 and says so; docker run <image> status is not a command and boots Tor |
How the dispatch behaves:
-
showanddoctorread the 0700 tor-owned key directories. Run withdocker run, they switch to thetoruser themselves. Run as root withdocker exec, they read the directories directly and switch totoronly when root is refused, which is what happens under rootless Podman. The other commands run as root so they can write into a host-owned key mount. - The host CLI runs
client-auth,unseal-keysandvanityfor you in a throwaway container with no network.client-authandunseal-keysrun as the tor user (100:101) with no capabilities. -
doctorinside the image always adds--keys-only. There is no engine socket in the container, so it checks on-disk key hygiene only. The full hardening audit needs the host CLI. -
vanityruns the generator wrapper built into the image directly, so inside the image its output flag is--out(default: the key mount), not the host CLI's--keys;--prefix,--name,--threads,--bench,--secondsand--forceare the same. - The image sets
HIDDENFORGE_KEYS_DIR=/var/lib/tor/hidden_service, so the key-volume default points at the mount. -
ageandgpgare not in the image.backup,restore,encrypt-keyanddecrypt-keyneed them, so run those on the host. Inside the image they exit 2 with a message naming the missing tool or passphrase file. - The image holds only Tor, its libraries, the
hiddenforgebinary and the vanity generator, so every command in it ishiddenforge <command>. Two exist only in the image:hiddenforge healthcheck [--json], the container's health state, andhiddenforge inspect --json, the torrc Tor runs with, any dropped mappings and the service addresses. Both read as the tor user. The healthcheck that older compose files declare,su-exec tor python3 /usr/local/bin/healthcheck.py, still runs the native one; any othersu-execform is refused with exit 127 and a message pointing tohiddenforge <command>, anddocker exec <container> shfails with the engine's "executable file not found".
| Variable | Effect | Default |
|---|---|---|
HIDDENFORGE_ENGINE |
Pins the container engine for every inspect, exec and run. Accepts docker or podman. Without it, a container is looked for in Docker and in Podman, and the engine that holds it is used. |
docker if it is on PATH, otherwise podman; a container found under the other engine switches to that one |
HIDDENFORGE_IMAGE |
Image used by setup, vanity, client-auth and unseal-keys. |
sambent.dev/sam/hiddenforge:latest |
HIDDENFORGE_KEYS_DIR |
Default for every --keys flag except setup's, which always defaults to ./tor-keys. |
./tor-keys |
doctor reads the container's real state (its cgroup and capability set where it can) instead of trusting the compose file. Its checks cover capabilities, no-new-privileges, the read-only root, the seccomp profile (a container that still sets seccomp=unconfined fails), the process cap, swap, published ports, the log driver, DNS, the generated torrc and key-file modes. A container started in no-root mode (user 100 or tor) needs no capabilities at all, so doctor treats any granted capability as extra. It fails a container the engine reports unhealthy (one still starting is a warning) and a key directory the container's tor user cannot enter, and says to run chmod 751 on it. Whether AppArmor applies is asked of Podman directly (podman info) when the engine is Podman, so a stack made by setup --runtime podman passes; if Podman cannot be asked, the check warns. See Security Model for why each setting exists.
Restart policy, including systemd. A container with no engine restart policy normally fails the restart check. If the container carries the PODMAN_SYSTEMD_UNIT label, doctor checks that unit instead. Whether a unit really brings the container back depends on details doctor cannot read with confidence (its ExecStart must use podman run --replace, and RestartPreventExitStatus=, the start limits and RestartSec= must not stop it), so a unit in the right shape is reported as a warning naming what to verify: the unit's main process is the container's conmon (with RemainAfterExit=no and the default ExitType=main) and it has Restart=always. Verify it once by killing the container (podman kill <name>) and watching the unit start it again. A unit in any other shape fails, with the fix: a Type=forking unit with PIDFile= and podman run --replace --conmon-pidfile <same path> -d ..., or a quadlet unit.
| Check | Pass condition | Severity |
|---|---|---|
| Unit restarts the container | Right shape and Restart=always: warning (verify by killing the container once); anything else: fail |
warn / fail |
| Container returns after a reboot | The unit's file state is enabled (a generated quadlet unit is reported as such: it starts at boot only if its [Install] section says so) |
warn |
| User services run without a login session | linger is on (checked when the engine is Podman) | warn |
The unit is read with systemctl --user show, then without --user. If it cannot be read, the check fails and names the unit.
Host-network containers and DNS. A container on the host network uses the host's resolver and cannot be given dns:. So doctor checks something else: whether any backend in *_TOR_SERVICE_HOSTS is a hostname. A hostname raises a warning that lists the names, and the fix is to give those backends as an IP or localhost, which are never looked up and pass. Outside host networking, the check wants dns: set to a loopback address.
For the Podman-specific checks (capabilities, linger, podman-restart.service), see Rootless Podman.
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