Skip to content
dme86Public

Repository files navigation

Onion Lab 🧅

A deliberately small Docker Compose lab showing two Tor v3 Onion Services:

  • a web site reachable only as http://<56-char>.onion/
  • an SSH service reachable only as <different-56-char>.onion:22

No HTTP or SSH port is published on the Docker host. The only published port is 127.0.0.1:19050, a host-loopback-only Tor SOCKS proxy used by the demo client scripts. Nothing is opened on your router.

What this demonstrates

web and ssh use network_mode: service:tor-server, so they have no independent Docker network interface. They share the exact network namespace of tor-server.

The tor-server container installs fail-closed OUTPUT rules:

  • Tor's own UID may reach the Internet directly, because Tor itself must reach Tor relays.
  • DNS from other processes is redirected to Tor DNSPort.
  • TCP from other processes is redirected to Tor TransPort.
  • local access to Tor's redirected listener ports (9040, 5353) is explicitly allowed.
  • other UDP is blocked.
  • IPv6 is fail-closed to avoid an IPv6 escape path.

This makes the runtime network path much harder for an application to bypass than an ALL_PROXY environment variable.

Scope: Docker image builds/pulls are performed by the Docker daemon and are not torified by these runtime rules. If you want even build/update traffic forced through Tor, use a dedicated Tor gateway VM/network namespace for the Docker host itself.

Start

Requirements: Docker + Docker Compose v2 + OpenSSH client utilities.

./setup.sh

It generates a local Ed25519 SSH client key, builds the images, starts Tor, and prints both Onion addresses.

Show the addresses later:

./addresses.sh

Open the website

The most literal test is to copy the WEB address from ./addresses.sh into Tor Browser.

Or use the separate tor-client container through its loopback-only SOCKS proxy:

./curl-onion.sh

The route is:

curl on host
  -> 127.0.0.1:19050
  -> separate tor-client container
  -> Tor network
  -> web Onion Service
  -> tor-server
  -> 127.0.0.1:8080
  -> web container

SSH through the Onion address

Run:

./ssh-onion.sh

The script reads the SSH Onion address and invokes ordinary OpenSSH with an SOCKS5 ProxyCommand:

ssh on host
  -> nc SOCKS5
  -> 127.0.0.1:19050
  -> tor-client
  -> Tor network
  -> SSH Onion Service :22
  -> tor-server
  -> 127.0.0.1:2222
  -> ssh container

Authentication is still normal SSH public-key authentication. The .onion address is a routing/service identity, not a password.

The demo login is:

user: demo
password: disabled
key: ./keys/demo_ed25519

The SSH container intentionally disables root login, passwords, TCP forwarding and tunnels.

Using your own Tor client instead

If you already have a SOCKS5 Tor endpoint, point the helper at it:

TOR_SOCKS_HOST=127.0.0.1 TOR_SOCKS_PORT=9050 ./ssh-onion.sh

For some Tor Browser setups the SOCKS port may be 9150 instead. Do not assume that; use the port your local Tor setup actually exposes.

Test forced outgoing traffic

./test-egress.sh

The first test performs an ordinary Python HTTPS request from the web container. The Python process has no SOCKS configuration. Its TCP connection is intercepted by the network namespace rules and passed to Tor TransPort, so the remote service should see a Tor exit IP rather than the Docker host's public IP. In this version the local TransPort / DNSPort allowances are already baked in, so no manual post-start iptables fixups are needed.

The second test tries arbitrary UDP and should fail.

TLS / HTTPS

For a v3 Onion Service, the Tor protocol already provides encryption between the Tor client and the Onion Service and authenticates the Onion Service cryptographically through its .onion identity. For a pure Onion-only lab, plain:

http://exampleexampleexample...onion

is therefore reasonable and avoids certificate-management noise.

You can still put TLS inside the Onion Service if you want an additional TLS layer. The choices are:

  1. Self-signed certificate — easy, but browsers show a certificate warning unless you explicitly trust your CA/certificate.
  2. Private CA — good for a controlled lab where you install your own CA on clients.
  3. Public CA certificate for the exact .onion name — possible through CAs that issue Onion certificates, but much more specialized than ordinary ACME/Let's Encrypt.

For this demo the web hop after Tor is only 127.0.0.1:8080 inside the shared network namespace, so adding TLS there does not materially improve the networking demonstration.

Onion identity persistence

The Onion addresses live in the named Docker volume:

onion-lab-tor-server-state

docker compose down does not delete it, so the Onion addresses survive normal recreates.

Do not run this if you want to keep your Onion identities:

docker compose down -v

Back up the Onion identities with:

./backup-onion-identity.sh

The private keys inside that backup are effectively the identity behind your Onion addresses. Keep them secret.

Stop

docker compose down

To intentionally destroy the lab including both Onion identities and SSH host key:

docker compose down -v

Security note

This is an educational lab, not a hardened anonymity appliance. Sharing one Docker network namespace is a neat way to demonstrate transparent torification, but containers share the host kernel. For a higher-assurance design, put the Tor gateway and the Onion workload in separate VMs and give the workload VM no WAN interface at all.