Repository navigation
Description
Problem
The nginx deployment (docs/nginx.md) runs a second service next to camex: camex-nginx-sync --follow, 633 lines of sh run as root. It:
- asks
camex --status --format nginx-map, writes/etc/nginx/camex-map.conf, checks it withnginx -tand runsnginx -s reloadwhenever the clients change; - asks
camex --status --format nginx-indexevery 10 seconds and writes/var/lib/camex-nginx/index.html; - keeps its own state next to the map:
.applied,.lock,.warnings,.warnings-index,.tmp.$$,.prev.$$.
Both the page and the map already come from camex itself (src/nginxmap.c), so the script only moves them into files. Each reload leaves the old nginx workers alive for up to proxy_read_timeout (300 s) while streams are open, and a server without nginx cannot show its page at all.
Proposal
camex serves the page and the lookup itself; nginx stays the proxy, TLS and authorization in front of it.
camex: web_listen= in [server]
Off by default. Default address when given without one: 127.0.0.1:5801.
| Path | What | Who |
|---|---|---|
GET / |
the start page, HTML built into the binary (nginx_index_format()) |
anyone allowed |
GET /status.json |
the data the page refreshes itself from | anyone allowed |
GET /resolve |
204 with X-Camex-Upstream: <ip>:<port>, empty when no such device |
127.0.0.1 only (else 404) |
- GET only, request head up to 8 KB, no keep-alive, strict parsing. Control stays on the unix socket: the web side changes nothing.
X-Forwarded-Host/X-Forwarded-Protoare trusted only from 127.0.0.1: behind nginx the page links tohttps://<name>.<domain>/; without nginx it links to the devices' tunnel addresses (http://10.200.0.5:8085/).- A build flag leaves the web server out (for cameras, where camex is a client); on by default.
Password without nginx
web_listen |
Password |
|---|---|
127.0.0.1:... (behind nginx) |
none: nginx asks for it (auth_basic) |
a LAN address or 0.0.0.0 |
required: camex does not start without web_password= |
| the same, page open on purpose | web_password=none written out, with a warning at start |
web_password=holds an argon2 hash fromcamex --hash-password, never the password.- A checked
Authorizationheader is remembered in memory and compared in constant time, so the page's refresh does not run argon2 every 10 seconds. - Failed attempts are limited per IP.
- Plain HTTP: the docs say this mode is for a LAN; a page on the internet goes through nginx with TLS.
Several servers on one host
Today --status and the script put the clients of every server on the host on one page and one map. Kept:
- the server with
web_listenasks the others through their control sockets (as--statusdoes) and shows them all; web_scope=self: only its own clients, for a server with its own domain and its ownweb_listen;- two servers with
web_listenfor one domain: a warning at start.
With named networks and --transport both (5.0.0) one daemon covers what used to take several, so this is mostly for existing setups.
nginx: auth_request instead of the map
location / {
auth_request /_camex;
auth_request_set $camex_upstream $upstream_http_x_camex_upstream;
if ($camex_upstream = "") { return 503; } # -> @offline
proxy_pass http://$camex_upstream; # straight to the device, as today
# WebSocket, timeouts, client_max_body_size 0, @offline: unchanged
}
location = /_camex {
internal;
proxy_pass http://127.0.0.1:5801/resolve;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Camex-Host $host;
}- Traffic does not go through camex; per-client ports (
web_port) keep working; a device that comes or goes is seen at once, without a reload. auth_requesttakes any code other than 2xx, 401 and 403 for an error (500), so/resolvealways answers 204.- The start page server block proxies
/and/status.jsonto camex instead ofroot /var/lib/camex-nginx. ngx_http_auth_request_moduleis in the nginx packages of Debian and Ubuntu; other builds need a check.- Later, not in this issue: per-device access through
/resolve.
Moving to it
install.sh installs the new nginx file and stops installing the script. What an existing server removes by hand is listed in the docs:
/usr/local/bin/camex-nginx-sync,/etc/systemd/system/camex-nginx-sync.service(systemctl disable --now camex-nginx-syncfirst)/etc/nginx/camex-map.confandcamex-map.conf.applied,.lock,.warnings,.warnings-index/var/lib/camex-nginx/
Versions
- 5.1.0 (after 5.0.0):
web_listen,web_password,web_scope,--hash-password,/resolve, the new nginx example and docs; the sync script and--format nginx-map/nginx-indexdeprecated but still there. - 6.0.0: the script and the two formats removed.
Files
| Now | After |
|---|---|
examples/camex-nginx-sync.sh, .service |
deprecated in 5.1.0, removed in 6.0.0 |
examples/nginx-camex.conf |
auth_request, no map include, page proxied to camex |
install.sh |
no script, no page directory |
docs/nginx.md |
"Sync script" replaced by web_listen; the removal list |
docker/test-e2e-nginx-map.sh |
a new e2e test with nginx and auth_request |
--format nginx-map / nginx-index |
deprecated in 5.1.0, removed in 6.0.0 |
Activity