Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ per-user desktops, and distribution through the Omarchy plugin marketplace.
- Guest isolation on lo: tag new TCP from the guest uid in output (`ct mark set <uid>`), and in input accept only `socket cgroupv2 level 2 "user.slice/user-<uid>.slice"`. The cgroup path is resolved when the rules load, so load after `user@<uid>.service`. Unprivileged nft syntax/behavior checks: `unshare -rn nft -c -f file`.
- Guest accounts have no password: Omarchy's idle lock (quickshell, 300 s) would lock them out for good. The `~/.local/state/omarchy/indicators/stay-awake` file disables it; there is no unlock IPC.
- Tailscale SSH accepts any local user on the test machine (`ssh <user>@<tailscale-ip>`), handy for acting as a guest without sudo.
- Ollama (and Vite, Rails dev…) refuse a Host that isn't localhost: 403 through every provider. `expose --host-header localhost` rewrites it (Cloudflare ingress `originRequest.httpHostHeader`, Pangolin `setHostHeader`); `tailscale serve` can't. Off by default: apps that build absolute URLs need the real Host. The demo video used a mock model, which is why this went unnoticed.
- noVNC settings live in `$NOVNC_DIR/defaults.json`; `index.html` symlinks to `vnc.html` so `/` opens the desktop.

## Roadmap
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ omarchy-remote expose app 3000
# -> https://<machine>.<tailnet>.ts.net:3000 (default: Tailscale, only your own devices)
omarchy-remote expose app 3000 --auth login --allow friend@example.com
# -> https://app.example.com (public; browser login, your friend gets an email code)
omarchy-remote expose ai 11434 --auth bearer
# -> https://ai.example.com (public; OpenAI-style clients send "Authorization: Bearer <key>")
omarchy-remote expose ai 11434 --auth bearer --host-header localhost
# -> https://ai.example.com (public; e.g. Ollama — OpenAI-style clients send "Authorization: Bearer <key>")
```

Private URLs go through **Tailscale** (free for personal use, no domain needed). Public URLs
Expand Down Expand Up @@ -124,6 +124,12 @@ only Pangolin is set up on this machine; with both set up, `expose` says it pick

Passwords, tokens and keys are generated for you and **printed once** — save them.

**Services that check the host name.** Ollama, Vite and some other dev servers only answer
requests addressed to `localhost`; through a URL they reply 403 even with the right
credentials. Add `--host-header localhost` and the provider sends that host name instead
(Cloudflare and Pangolin; Tailscale can't rewrite it, so a private URL won't work for these).
Leave it off for ordinary web apps: they need the real host name to build links and redirects.

A new Pangolin address needs about 30 seconds for its certificate (404 / connection errors until
then). On Cloudflare, `expose` with `bearer`, `login` or `token` waits until requests without
credentials are refused before it reports success (usually 10–30 s). After `unexpose`, an address may keep answering for a few seconds.
Expand Down
6 changes: 4 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ omarchy-remote expose app 3000
# -> https://<机器名>.<tailnet>.ts.net:3000(默认走 Tailscale,只有你自己的设备能访问)
omarchy-remote expose app 3000 --auth login --allow friend@example.com
# -> https://app.example.com (公网;浏览器登录,朋友用邮箱验证码进入)
omarchy-remote expose ai 11434 --auth bearer
# -> https://ai.example.com (公网;OpenAI 风格的客户端用 "Authorization: Bearer <key>" 调用)
omarchy-remote expose ai 11434 --auth bearer --host-header localhost
# -> https://ai.example.com (公网;比如 Ollama,OpenAI 风格的客户端用 "Authorization: Bearer <key>" 调用)
```

私有地址走 **Tailscale**(个人使用免费,不需要域名)。公网地址走你选的提供方:**Cloudflare**(通过 Cloudflare Access 做浏览器登录和服务令牌,还能在 Cloudflare 边缘校验 API key,兼容 OpenAI 风格的客户端和 SDK,包括流式输出),或者 **Pangolin**(浏览器登录、访问令牌、密码)。两个都配或只配一个都行。
Expand Down Expand Up @@ -90,6 +90,8 @@ omarchy-remote unexpose <名字>

密码、令牌和 key 都由工具自动生成,**只显示一次**,请自己保存好。

**会检查域名的服务。** Ollama、Vite 等一些开发服务只接受发给 `localhost` 的请求;通过外部地址访问时,即使凭据正确也会返回 403。加上 `--host-header localhost`,提供方就会改用这个域名转发(Cloudflare 和 Pangolin 支持;Tailscale 改不了,所以这类服务用不了私有地址)。普通网页应用不要加:它们需要真实的域名来生成链接和跳转。

Pangolin 的新地址需要大约 30 秒签发证书,在此之前出现 404 或连不上是正常的。在 Cloudflare 上,`bearer`、`login`、`token` 三种方式的 `expose` 都会等到不带凭据的请求确实被拒绝后才报告成功(通常 10~30 秒)。`unexpose` 之后,地址可能还会响应几秒。

> 在 Cloudflare 上,每个 `login` 或 `token` 服务会建一个 Access 应用和一条策略(`token` 还会建一个服务令牌),名字都是 `omarchy-remote:<名字>`,`unexpose` 时一并删除。每个 `bearer` 服务占用一条 Cloudflare WAF 自定义规则。免费版每个域名最多 5 条,跟你自己建的规则共用。能打开你 Cloudflare 后台的人,都能看到这些规则里的 key。
Expand Down
33 changes: 22 additions & 11 deletions bin/omarchy-remote
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

set -euo pipefail

VERSION="0.7.0"
VERSION="0.7.1"

# ---- settings (override in ~/.config/omarchy-remote/config) -----------------
CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/omarchy-remote/config"
Expand Down Expand Up @@ -322,7 +322,7 @@ pg_resource_id() { # pg_resource_id FQDN -> resourceId (empty if none)
rand_secret() { python3 -c 'import secrets; print(secrets.token_urlsafe(18))'; }

cmd_expose() {
local name="" port="" via="" auth="" allow="" user="omarchy" yes_public=0
local name="" port="" via="" auth="" allow="" user="omarchy" yes_public=0 host_header=""
while (($#)); do
case "$1" in
--via) via="${2:-}"; shift 2 ;;
Expand All @@ -333,6 +333,8 @@ cmd_expose() {
--allow) allow="${2:-}"; shift 2 ;;
--allow=*) allow="${1#*=}"; shift ;;
--user) user="${2:-}"; shift 2 ;;
--host-header) host_header="${2:-}"; shift 2 ;;
--host-header=*) host_header="${1#*=}"; shift ;;
--yes-public) yes_public=1; shift ;;
-*) die "Unknown option: $1" ;;
*) if [[ -z "$name" ]]; then name="$1"; elif [[ -z "$port" ]]; then port="$1"; else die "Unexpected argument: $1"; fi; shift ;;
Expand All @@ -341,6 +343,7 @@ cmd_expose() {
[[ -n "$name" && -n "$port" ]] || die "usage: omarchy-remote expose <name> <port> [--via tailscale|pangolin|cloudflare] [--auth login|token|password|bearer|none]"
valid_name "$name" || die "Name must be lowercase letters, digits and dashes (it becomes the subdomain)."
if ! [[ "$port" =~ ^[0-9]+$ ]] || ((port < 1 || port > 65535)); then die "Invalid port: $port"; fi
[[ -z "$host_header" || "$host_header" =~ ^[A-Za-z0-9.-]+(:[0-9]+)?$ ]] || die "--host-header takes a host name, e.g. localhost or localhost:$port"

# No --via: private by default; asking for an auth mode means a public URL.
# bearer exists only on Cloudflare and password only on Pangolin, so they pick their provider.
Expand All @@ -359,6 +362,7 @@ cmd_expose() {
case "$via" in
tailscale)
[[ -z "$auth" ]] || die "Tailscale URLs are private to your tailnet and take no --auth. For a public URL with a login use --via pangolin (or cloudflare)."
[[ -z "$host_header" ]] || die "Tailscale can't rewrite the Host header. Use --via cloudflare or --via pangolin with --auth (a service that checks Host, like Ollama, answers 403 through Tailscale)."
;;
pangolin|cloudflare)
case "$auth" in
Expand All @@ -385,8 +389,8 @@ cmd_expose() {

case "$via" in
tailscale) ts_expose "$name" "$port" ;;
pangolin) pg_expose "$name" "$port" "$auth" "$allow" "$user" ;;
cloudflare) cf_expose "$name" "$port" "$auth" "$allow" ;;
pangolin) pg_expose "$name" "$port" "$auth" "$allow" "$user" "$host_header" ;;
cloudflare) cf_expose "$name" "$port" "$auth" "$allow" "$host_header" ;;
esac
}

Expand Down Expand Up @@ -431,7 +435,7 @@ ts_unexpose() {

# ---- Pangolin (public) ------------------------------------------------------
pg_expose() {
local name="$1" port="$2" auth="$3" allow="$4" user="$5"
local name="$1" port="$2" auth="$3" allow="$4" user="$5" host_header="${6:-}"
pg_load
local fqdn="$name.$PG_BASE_DOMAIN" r id
[[ -z "$(pg_resource_id "$fqdn")" ]] || die "$fqdn is already exposed. Run: omarchy-remote unexpose $name"
Expand All @@ -445,6 +449,7 @@ pg_expose() {

pg_api PUT "/public-resource/$id/target" \
"{\"siteId\":$PG_SITE_ID,\"ip\":\"127.0.0.1\",\"port\":$port,\"method\":\"http\",\"enabled\":true}" >/dev/null
[[ -z "$host_header" ]] || pg_api POST "/public-resource/$id" "{\"setHostHeader\":\"$host_header\"}" >/dev/null

local pass emails tok
case "$auth" in
Expand Down Expand Up @@ -593,17 +598,20 @@ EOF
systemctl --user enable --now "$CF_UNIT" >/dev/null 2>&1 || systemctl --user start "$CF_UNIT"
}

# cf_ingress add FQDN PORT | del FQDN — edit the tunnel's remotely-managed ingress list.
# cf_ingress add FQDN PORT [HOST_HEADER] | del FQDN — edit the tunnel's remotely-managed ingress list.
cf_ingress() {
local r new
r="$(cf_api GET "/accounts/$CF_ACCOUNT/cfd_tunnel/$CF_TUNNEL_ID/configurations")"
new="$(python3 - "$r" "$1" "$2" "${3:-}" <<'PY'
new="$(python3 - "$r" "$1" "$2" "${3:-}" "${4:-}" <<'PY'
import json, sys
d = json.loads(sys.argv[1]); op, host, port = sys.argv[2], sys.argv[3], sys.argv[4]
d = json.loads(sys.argv[1]); op, host, port, host_header = sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]
rules = [x for x in (((d.get("result") or {}).get("config") or {}).get("ingress") or [])
if x.get("hostname") and x.get("hostname") != host]
if op == "add":
rules.append({"hostname": host, "service": "http://127.0.0.1:%s" % port})
rule = {"hostname": host, "service": "http://127.0.0.1:%s" % port}
if host_header:
rule["originRequest"] = {"httpHostHeader": host_header}
rules.append(rule)
rules.append({"service": "http_status:404"})
print(json.dumps({"config": {"ingress": rules}}))
PY
Expand Down Expand Up @@ -732,7 +740,7 @@ cf_probe() {
}

cf_expose() {
local name="$1" port="$2" auth="$3" allow="${4:-}" fqdn c key="" code i
local name="$1" port="$2" auth="$3" allow="${4:-}" host_header="${5:-}" fqdn c key="" code i
cf_load
fqdn="$name.$CF_ZONE"
c="$(cf_dns_comment "$fqdn")"
Expand All @@ -747,7 +755,7 @@ cf_expose() {
elif [[ "$auth" == login || "$auth" == token ]]; then
cf_access_add "$name" "$fqdn" "$auth" "$allow" # before DNS: never reachable without it
fi
cf_ingress add "$fqdn" "$port"
cf_ingress add "$fqdn" "$port" "$host_header"
cf_api POST "/zones/$CF_ZONE_ID/dns_records" \
"{\"type\":\"CNAME\",\"name\":\"$fqdn\",\"content\":\"$CF_TUNNEL_ID.cfargotunnel.com\",\"proxied\":true,\"comment\":\"$PG_TAG:$name:$auth\"}" >/dev/null

Expand Down Expand Up @@ -1339,6 +1347,9 @@ Usage: omarchy-remote <command>
Cloudflare Access; bearer = API key checked at Cloudflare's edge)
expose <name> <port> --auth login|token|password|none [--allow a@x.com,b@y.com] [--via pangolin]
public URL https://<name>.<your-domain> via Pangolin
expose ... --host-header localhost
public URLs: send this Host to the service (Ollama, Vite and others
refuse requests for other host names)
unexpose <name>
list [--json] show exposed services (--json: for scripts and the Omarchy plugin)
config set public pangolin|cloudflare
Expand Down
Loading