From 06118a1bee251d76c199166ae9d51872a6ccc595 Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 17 Oct 2026 15:24:44 -0400 Subject: [PATCH] Document putting the dashboard behind Authelia Forward auth via nginx auth_request, with /api/v1/report bypassed so agents keep reporting with their bearer tokens. Co-Authored-By: Claude Opus 5.5 --- README.md | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/README.md b/README.md index ced82d6..51db3c1 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,100 @@ the document root empty, and keep your clone of this repo out of `htdocs`. `location = /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). + +### Authelia (forward auth) + +If you already run [Authelia](https://www.authelia.com/), 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. + +1. **Authelia `access_control`.** Rules are checked in order, so put the bypass + first, and keep a single `rules:` list: + + ```yaml + access_control: + default_policy: two_factor + rules: + - domain: kernelwatch.example.com + resources: + - '^/api/v1/report$' + - '^/healthz$' + policy: bypass + - domain: "*.example.com" + policy: two_factor + ``` + + For the redirect to the login page to work, your `session.cookies` entry has + to cover the dashboard's domain and set `authelia_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 with `authelia validate-config`. + +2. **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_proxy` block alone and add or replace these: + + ```nginx + # 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 the `Host` + and `X-Forwarded-For` headers in place of `try_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 the + `proxy_ssl_server_name` and `Host` lines. Keep `location ^~ /.well-known` + unprotected so certificate renewals still work. If something monitors + `/healthz`, give it an exact-match location like the agents' one. + +3. **Check it.** + + ```sh + 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 302 + ``` + + Then run `sudo systemctl start kernelwatch-agent` on 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. ## Adding a host