Skip to content

Add alios share to expose a project through a Cloudflare Tunnel - #2

Merged
michaelaguiar merged 3 commits into
mainfrom
share-cloudflare-tunnel
Oct 13, 2026
Merged

michaelaguiar merged 3 commits into
mainfrom
share-cloudflare-tunnel

Conversation

@michaelaguiar

Copy link
Copy Markdown
Member

What

alios share gives the current project a public HTTPS URL through a Cloudflare Tunnel.

  • Quick mode (default): no account needed. One alios_share_<project> container per share, with a random trycloudflare.com URL.
  • Named mode: set ALIOS_SHARE_TUNNEL_TOKEN and ALIOS_SHARE_DOMAIN for stable <project>.<domain> URLs from one shared alios_share container.
  • alios share --auth user:pass puts the share behind basic auth.
  • alios share stop and alios share list. stop, remove and pause end the project's shares.
  • status shows the share. doctor flags a share whose tunnel is gone, and a half-configured named tunnel.

Each share is one <project>.share.caddyfile vhost in the alios_vhosts volume, and that file is the only record of it. There are no new labels and no config files. The design is in docs/SHARING.md.

Testing

  • Quick mode: verified end to end on a Laravel project (helix-crm), including --auth.
  • go build ./... and go vet ./... pass. The repo has no test suite.

Known gaps

`alios share` gives the current project a public HTTPS URL. A cloudflared
container on alios_internal forwards to Caddy over plain HTTP, and a
<project>.share.caddyfile vhost matching the public host proxies on to the
project. That vhost file is the only record of a share.

- Quick mode (default): one alios_share_<project> container per share,
  random trycloudflare.com URL, no account needed.
- Named mode (ALIOS_SHARE_TUNNEL_TOKEN + ALIOS_SHARE_DOMAIN): one shared
  alios_share container, stable <project>.<domain> URLs.
- `--auth user:pass` puts the share behind basic auth.
- `share stop` / `share list`; `stop`, `remove` and `pause` end the
  project's shares; `status` and `doctor` report them, and doctor flags a
  share whose tunnel is gone or a half-configured named tunnel.
- Caddy adds X-Alios-Share: 1 to shared requests so an image or app can
  tell them apart.

Quick mode is verified end to end on a Laravel project. Named mode is
untested, and WordPress isn't supported yet (siteurl/home in the database
redirect visitors back to the .test host); docs/SHARING.md says so.
- `alios global restart` restarted quick-tunnel containers, which gave
  them a new public URL while the vhost kept the old one, so status/doctor
  showed a dead URL as live. Share tunnels are no longer treated as
  global services.
- Offline, cloudflared logs api.trycloudflare.com in its error, which
  the URL regex took for the share's URL and reported as a success. That
  host is now skipped (regression test included).
- `alios restart` (and a server-root change) ended the share. The tunnel
  points at Caddy, not the container, so restart now keeps it.
- `share stop` ignored a failed Caddy reload, so with a named tunnel still
  up for other shares the project stayed public while the command
  reported success. It now reports the failure.
- The --auth password went to `caddy hash-password` as an argument,
  visible in `ps`; it's sent on stdin now.
- Named mode reused an existing tunnel container even after the token was
  rotated; the container now carries a token fingerprint and is replaced
  when it differs. A restarted container is also checked for a clean
  start.
- Two projects whose names map to the same public label (my_app, my.app)
  are refused with a clear error instead of a failed Caddy reload; empty
  or over-long labels too.
- ALIOS_SHARE_DOMAIN accepts the pasted forms "*.acme-dev.com" and
  "https://acme-dev.com/", and doctor flags a value that isn't a domain.
- Docs: restart keeps a share; the token comment and CLAUDE.md no longer
  claim things the code doesn't do.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 1 (fresh-context reviewer, code-review at high effort)

Fixed in baee3b1:

  1. P2: global restart restarted quick-tunnel containers, so they came back on a new URL while alios still showed the old one as live. Share tunnels are no longer treated as global services.
  2. P2: offline, the api.trycloudflare.com host from cloudflared's error message was taken as the share URL and reported as a success. That host is now skipped, with a regression test that fails without the fix.
  3. P2: alios restart (and a server-root change) ended the share. A restart now keeps it, and the docs say so.
  4. P2: share stop ignored a failed Caddy reload, so the project could stay public in named mode while the command reported success. It now reports the failure.
  5. P3: the --auth password was visible in ps. It's now sent to caddy hash-password on stdin, which I checked works against the live Caddy 2.10 container.
  6. P3: the comment claiming the tunnel token was hidden from ps is corrected.
  7. P3: named mode reused a tunnel container even after the token was rotated. The container now carries a token fingerprint label and is replaced when it differs.
  8. P3: project names that map to the same public label are refused with a clear error. Empty labels and labels over 63 characters are refused too.
  9. P3: ALIOS_SHARE_DOMAIN now accepts the forms people paste (*.acme-dev.com, https://…/), with a test. doctor fails on a value that isn't a domain.
  10. P3: CLAUDE.md's "no labels" wording is corrected, and CLAUDE.md now mentions the tests.

Declined:
5. P3, foo.share vs a share of foo. This needs both a foo and a foo.share project. Fixing it means moving share vhosts into a subdirectory with a second import, which isn't worth it for that combination.
12. P3, a throwaway alpine container per check. That's about 300ms on status/stop/remove, and the N² cost only matters with many shares, which nobody has. Keeping the vhost file as the only record was a deliberate choice.

The reviewer confirmed these hold: there's no Caddyfile injection (Docker restricts container names), auth is hashed before any tunnel starts, the forwarded headers can't be forged, named-mode teardown is correct, and pause runs before the shares are stopped.

- `share.StopAll` returned on the first share that failed to stop,
  skipping the rest and the tunnel-container sweep. Since `share stop` now
  reports a failed Caddy reload, one broken vhost during `alios pause`
  could leave another share's tunnel running, and it came back live after
  `resume`. StopAll now carries on, always sweeps the tunnel containers,
  and returns every error.
- Share tunnels stopped being global services in the previous commit, so
  `global stop` and `uninstall` no longer stopped them. Both now end every
  share: with Caddy down nothing can be served, and after an uninstall
  the named tunnel would otherwise restart with Docker indefinitely.
- A restart whose start step fails now ends the share it had kept for the
  project coming back.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 2

The reviewer confirmed all nine round-1 fixes hold, and checked every caller of the changed container listing. It found three new issues, all fixed in 2b67cf9:

  • P2: share.StopAll stopped at the first failing share. Combined with round 1's fail-closed share stop, one broken vhost during pause could leave another share's tunnel running and live again after resume. StopAll now carries on past errors, always removes every tunnel container, and returns all the errors.
  • P3: because share tunnels are no longer global services, global stop and uninstall stopped leaving them stopped. Both now end every share. (Installer.Uninstall in installer.go has no callers, so I left it alone.)
  • P3: when a restart's start step fails, the share it had kept is now ended.

@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 3: clean

A focused review of 2b67cf9 found no issues. All three round-2 fixes hold: StopAll continues past errors and always removes the tunnel containers (including the named one), global stop and uninstall end shares while Caddy is still up so the reload works, and a failed restart ends the share. Build, vet and tests pass. There's no CI on this repo.

Still untested: named-tunnel mode, and the new paths against a live stack. WordPress is still unsupported, as the docs say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant