# Build spec — the free home VPN (wg-easy / WireGuard)

## The ask, in the user's words

> (a reel: "How to make your own free VPN" — old laptop, wg-easy compose file, `INSECURE=true`,
> open port 51821, forward UDP 51820, scan the QR)
> "can you do:" → "how do i set up and how does it work" → "so i need to put my mac in my house?" →
> "ig i wont do it then, publish the details and stuff to my portfolio and just tick this chat"

So the deliverable moved twice: first a working server, then an explanation, then a documented
experiment that stops at a hardware/network boundary. Publishing is the final product.

## What had to be true at the end

- A real WireGuard tunnel on this Mac: container healthy, `wg0` up, a client that **completes a
  handshake and moves bytes** — not a screenshot of a UI.
- Every instruction in the reel checked against the software as it exists now (v14), with the
  divergences named.
- The admin panel never reachable off the machine, and no secret in anything published.
- An honest stop: state the three requirements a home-hosted exit needs and which ones are not met,
  instead of pretending the tunnel is unusable or that it works from outside.

## Environment established first

| fact | value |
|---|---|
| host | macOS 26.6, aarch64, Docker 29.5.3 inside colima (Ubuntu 6.8.0-117-generic, 2 vCPU / 2 GB) |
| image | `ghcr.io/wg-easy/wg-easy:latest`, 258 MB |
| compose plugin | absent; `brew install docker-compose` fell back to a source build → released `v5.8.1` `darwin-aarch64` binary into `~/.docker/cli-plugins`, `chmod +x`, ad-hoc `codesign` |
| LAN | `10.45.36.25/16`, gateway `10.45.0.1` |
| public egress | `203.198.53.125` — **not** a router the user administers |
| UDP probe | STUN `stun.l.google.com:19302` answered 32 B in 133 ms; `stun.cloudflare.com:3478` timed out |

The LAN/public mismatch is the finding that ends the project: the box can be given a public
hostname, but no port can be forwarded to it.

## The three divergences from the reel

1. `PASSWORD=` aborts the container. v14 requires `PASSWORD_HASH`, a bcrypt digest generated with
   the image's own `bcryptjs` (`hashSync(pw,12)`).
2. compose **does** interpolate `env_file` values, so a bcrypt hash (`$2a$12$…`) arrives mangled.
   Every `$` must be written `$$`. Silence here is dangerous: a missing hash makes the app report
   `requiresPassword:false` and serve an **unauthenticated** admin panel — the opposite of failing
   closed.
3. Port 51821 is the admin UI, not part of the tunnel. Bind `127.0.0.1:51821:51821`; forward only
   `51820/udp`.

## Failure ladder (all hit, in this order)

| symptom | cause | fix |
|---|---|---|
| `unknown shorthand flag: 'd'` | no compose plugin | release binary + codesign |
| `DO NOT USE PASSWORD ENVIRONMENT VARIABLE` | plaintext password | bcrypt hash as `PASSWORD_HASH` |
| 401, then `requiresPassword:false` | `$` interpolation ate the hash | `$$` per `$` |
| 401 again with the value visible in `docker inspect` | variable named `WG_PASSWORD_HASH`; app reads `PASSWORD_HASH` | rename |
| `cat: /config/wg0.conf: Is a directory` | single-file bind mount over a directory path | `docker cp` |
| `Name does not resolve: 'wg-easy:51820'` | test container on the default bridge | `--network wg-easy_default`, address by IP |
| `sysctl … src_valid_mark: Read-only file system` | `--sysctl` not honoured for that key; `wg-quick` needs it for a default route | `--privileged` on the throwaway client |

## Verification

Client container (`10.8.0.3`, `AllowedIPs 0.0.0.0/0`, endpoint = server's compose address):

```
latest handshake: 7 seconds ago
transfer: 6156 received, 12252 sent        (after one ping + one HTTPS fetch)
ping 10.8.0.1 → 0.668 / 0.723 / 0.778 ms, 0% loss
client route: 0.0.0.0/0 dev wg0 table 51820, fwmark 0xca6c
server MTU 1420
```

The exit-IP check is **not** proof on a single machine — both ends share the host's egress, so it
reads the same address with the tunnel up or down. Counters are the evidence.

## Why it stopped

The server must be a machine that stays home and awake, and it must have a forwardable public IPv4.
The only machine available travels to school, and the WAN is behind an ISP address the user does not
control. A third uncertainty (mixed UDP filtering, plus handshake fingerprinting) makes the school
side unproven. The TLS tunnel already in use covers the one network that matters.

## Published

- `demos/wg-easy-home-vpn-analysis.html` — the build log (9 sections, evidence table, failure ladder).
- `demos/wg-easy-home-vpn-kit/` — `docker-compose.yml` (893 B, sha256 `2d0ef5db…`), `README.md`
  (2,441 B, sha256 `86dba02f…`), `index.html`.
- Card at the head of `sw` in `app.js`.
- Never published: private keys, preshared keys, `.conf` files, the admin hash.
