'above', 'below' and 'as above' pointed at sections that are now on other pages, so they become links; server/install.sh's pointer to the README now names docs/reverse-proxy.md; server.md gains the next steps that used to be the following README sections. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
7.2 KiB
Reverse proxy and access control
TLS reverse proxy
The server speaks plain HTTP on 127.0.0.1:8080. Put a TLS proxy in front of it.
The agents and your browser both connect through it.
Caddy (simplest):
kernelwatch.example.internal {
reverse_proxy 127.0.0.1:8080
}
nginx:
server {
listen 443 ssl;
server_name kernelwatch.example.internal;
# ssl_certificate / ssl_certificate_key ...
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
With either proxy, set trust_proxy_headers = true in server.toml so login
rate limiting sees real client IPs.
If you use a private CA (e.g. Caddy's tls internal), give the agents its
root cert with --ca (see Agents).
You can expose only /api/v1/report to the fleet network and keep the
dashboard on a VPN or tailnet. That's a proxy rule, not a kernelwatch setting.
CloudPanel
CloudPanel gives each site its own Linux user and a document root at
/home/<site-user>/htdocs/<domain>/. kernelwatch doesn't use that directory.
nginx forwards requests to the app; it doesn't serve kernelwatch's files. Install
with server/install.sh as in Server, so the app runs as the kernelwatch user
with its data in /var/lib/kernelwatch, outside every site user's home. Leave
the document root empty, and keep your clone of this repo out of htdocs.
-
Pick a free port. CloudPanel's Varnish setup can run an nginx backend on 8080. Check with
ss -ltnp | grep ':8080\b'. If it's taken, set another port in/etc/kernelwatch/server.tomland restart (sudo systemctl restart kernelwatch):listen_port = 8095 trust_proxy_headers = trueCheck it:
curl -s http://127.0.0.1:8095/healthzshould printok. -
Create the site as a Reverse Proxy. In CloudPanel: Add Site → Create a Reverse Proxy, with your domain and Reverse Proxy URL
http://127.0.0.1:8095. CloudPanel can't change an existing site's type. If the domain already exists as a PHP or static site, delete and recreate it. Deleting a site also removes its site user and home directory, so move anything you need out first. -
TLS. In the site's SSL/TLS tab, issue a Let's Encrypt certificate. Agents then need no
--ca. -
Check the generated vhost (the site's Vhost tab). The
locationthat proxies to the app should pass the originalHostheader and the client address:proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;Add them if they're missing. Without
Host, logins fail the origin check with "cross-origin request refused". WithoutX-Forwarded-For, every login appears to come from 127.0.0.1, so one person's failed attempts lock everyone out. Also check that the login page is styled. If/static/style.cssreturns 404, a static-filelocationin the template is looking in the empty document root instead of proxying. Make it fall through to the proxy, or remove it. -
Optionally restrict the dashboard. The site's domain is public, so the login page is reachable from the internet unless you limit it. Agents only need
/api/v1/report. In the Vhost tab, add anallow <your IP>; deny all;tolocation /and a separate unrestrictedlocation = /api/v1/report { proxy_pass http://127.0.0.1:8095; }. Changes made in the Vhost tab persist. Back them up before recreating the site. To require a login through Authelia instead of an IP allowlist, see Authelia (forward auth).
Authelia (forward auth)
If you already run Authelia, you can put it in
front of the dashboard. That adds Authelia's 2FA and single sign-on, and
kernelwatch's own login still applies behind it. You log in to both, but
Authelia's remember-me makes that rare. This uses nginx's auth_request, so
you don't need an OIDC client.
Agents must bypass Authelia. They authenticate with their bearer token and
can't follow a login redirect. If Authelia covers /api/v1/report, every
report gets a redirect instead of a 401 or 204, and the whole fleet goes stale
within 3 hours.
-
Authelia
access_control. Rules are checked in order, so put the bypass first, and keep a singlerules:list:access_control: default_policy: two_factor rules: - domain: kernelwatch.example.com resources: - '^/api/v1/report$' - '^/healthz$' policy: bypass - domain: "*.example.com" policy: two_factorFor the redirect to the login page to work, your
session.cookiesentry has to cover the dashboard's domain and setauthelia_url. Without them, browsers get a bare 401 page. Authelia reads this file only at startup, so restart it after editing (in Kubernetes:kubectl rollout restart deployment/authelia). Check the file first withauthelia validate-config. -
nginx. Add an internal location for Authelia's check, an exact-match location for the agents with no check, and the check on
location /. For CloudPanel, edit the site's Vhost tab: leave the template's@reverse_proxyblock alone and add or replace these:# Authelia's check (internal subrequest only) location = /internal/authelia/authz { internal; proxy_pass https://auth.example.com/api/authz/auth-request; proxy_http_version 1.1; proxy_ssl_server_name on; proxy_set_header Host auth.example.com; proxy_set_header X-Original-Method $request_method; proxy_set_header X-Original-URL $scheme://$http_host$request_uri; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Content-Length ""; proxy_set_header Connection ""; proxy_pass_request_body off; } # Agents: token auth only location = /api/v1/report { try_files $uri @reverse_proxy; } # Dashboard: Authelia first, then kernelwatch's login location / { auth_request /internal/authelia/authz; auth_request_set $redirection_url $upstream_http_location; error_page 401 =302 $redirection_url; try_files $uri @reverse_proxy; }Without CloudPanel, use
proxy_pass http://127.0.0.1:8095;plus theHostandX-Forwarded-Forheaders in place oftry_files ... @reverse_proxy. If Authelia runs on the same machine, point the check straight at it (e.g.http://127.0.0.1:9091/api/authz/auth-request) and drop theproxy_ssl_server_nameandHostlines. Keeplocation ^~ /.well-knownunprotected so certificate renewals still work. If something monitors/healthz, give it an exact-match location like the agents' one. -
Check it.
curl -sI https://kernelwatch.example.com/ | head -3 # 302, Location pointing at Authelia curl -si -X POST https://kernelwatch.example.com/api/v1/report | head -1 # 401 from kernelwatch (no token), not a 302Then run
sudo systemctl start kernelwatch-agenton one host and check that its Last seen updates. If the POST gets a 302, the agents' location isn't matching. Fix that before the fleet goes stale.