Reverse proxy
Kaio streams in two ways that a default proxy configuration breaks:
- Server-sent events for the dashboard feed and for logs, on
/api/events,/api/containers/{id}/logsand/api/stacks/{name}/logs; - WebSocket for the in-container shell, on
/api/containers/{id}/shell.
The failure is silent. The page loads, the tables fill, and then logs never arrive and the terminal never opens.
location ~ ^/(api|mcp) { proxy_pass http://127.0.0.1:8080; proxy_http_version 1.1;
proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade;
proxy_buffering off; proxy_cache off; proxy_read_timeout 1h;}
location / { proxy_pass http://127.0.0.1:8080; proxy_http_version 1.1; proxy_set_header Host $host;}With this map at the http level, so that Connection is only set to upgrade
for requests that ask for it:
map $http_upgrade $connection_upgrade { default upgrade; '' close;}proxy_buffering off is the one that matters for logs: with buffering on, nginx
holds the event stream until a buffer fills, so lines arrive in bursts or not at
all. proxy_read_timeout has to outlive an idle stream, otherwise a quiet
container drops its log view after 60 seconds.
Only the streams need those three, which is why they sit in a location of their
own. The dashboard is a handful of hashed files served out of the binary, and
nginx buffers them in the plain location / the way it buffers any response.
The regex location is matched first, so the order of the two blocks does not
matter. /metrics, when you turn it on, is an ordinary scrape and belongs with
the dashboard. A browser’s own caching of the hashed assets is unaffected
either way: proxy_cache off governs nginx’s cache, not the immutable
response headers it passes through.
kaio.example.com { reverse_proxy 127.0.0.1:8080 { flush_interval -1 }}Caddy upgrades WebSocket connections on its own. flush_interval -1 disables
response buffering, which is what the event streams need.
Traefik
Section titled “Traefik”labels: - "traefik.http.routers.kaio.rule=Host(`kaio.example.com`)" - "traefik.http.services.kaio.loadbalancer.server.port=8080" - "traefik.http.services.kaio.loadbalancer.responseforwarding.flushinterval=-1"Traefik handles the WebSocket upgrade itself. flushinterval=-1 flushes
immediately, again for the event streams.
Tell Kaio about the proxy
Section titled “Tell Kaio about the proxy”A proxy in front is only half of the setup: Kaio has to know which address is
the proxy, and to be able to tell it apart from anything else at that address.
kaio-server setup proxy 127.0.0.1 does the first two steps below on the server,
secret included. By hand, three variables, whatever the proxy:
KAIO_TRUSTED_PROXIES=127.0.0.1KAIO_PROXY_SECRET_FILE=/etc/kaio/proxy-secretKAIO_GROUPS_READ=kaio-viewersKAIO_GROUPS_WRITE=kaio-devsKAIO_GROUPS_ADMIN=kaio-admins-
KAIO_TRUSTED_PROXIESis the address Kaio sees the proxy connect from: the loopback when both run on one host, the proxy container’s address on a Compose network. -
The secret is generated once and given to both sides:
Terminal window openssl rand -hex 32 | sudo tee /etc/kaio/proxy-secret >/dev/nullsudo chown kaio:kaio /etc/kaio/proxy-secret && sudo chmod 600 /etc/kaio/proxy-secretThe proxy sends it as
X-Kaio-Proxy-Secret. Without it, a request from the proxy’s address is not believed to come from the proxy. -
The group variables map the groups your identity provider sends to the levels. Leave them all out and every user the proxy lets through gets
admin.
sequenceDiagram
autonumber
participant B as Browser
participant P as Reverse proxy
participant A as Authelia, Authentik<br/>or oauth2-proxy
participant K as Kaio
B->>P: GET /api/dashboard
P->>P: drop any Remote-User the client sent
P->>A: Who is this?
alt not signed in
A-->>P: 401
P-->>B: redirect to the login page
else signed in
A-->>P: 200, Remote-User: alice, Remote-Groups: kaio-devs
P->>K: request + Remote-User + Remote-Groups + X-Kaio-Proxy-Secret
Note over K: from KAIO_TRUSTED_PROXIES, secret matches:<br/>alice, write
K-->>P: 200
P-->>B: 200
endEvery example below also does one thing on the proxy side that matters as much:
it removes any Remote-User or Remote-Groups the client sent before
setting its own, so that a user cannot name themselves. Kaio only believes those
headers from the proxy; the proxy has to make sure they are its own.
kaio-cli whoami through the proxy is the quickest check that all of it holds:
KAIO_ADDR=https://kaio.example.net kaio-cli whoamiuser: alicelevel: writevia: proxysource: 127.0.0.1groups: kaio-devsCaddy with Authelia
Section titled “Caddy with Authelia”kaio.example.net { request_header -Remote-User request_header -Remote-Groups request_header -X-Kaio-Proxy-Secret
forward_auth authelia:9091 { uri /api/authz/forward-auth copy_headers Remote-User Remote-Groups Remote-Email }
reverse_proxy 127.0.0.1:8080 { header_up X-Kaio-Proxy-Secret {$KAIO_PROXY_SECRET} flush_interval -1 }}Caddy reads KAIO_PROXY_SECRET from its own environment: put it in Caddy’s
service environment, from the same file. Authelia’s groups arrive in
Remote-Groups, comma-separated, which is Kaio’s default.
KAIO_TRUSTED_PROXIES=127.0.0.1KAIO_PROXY_SECRET_FILE=/etc/kaio/proxy-secretKAIO_GROUPS_WRITE=kaio-devsKAIO_GROUPS_ADMIN=kaio-adminsCaddy with oauth2-proxy
Section titled “Caddy with oauth2-proxy”oauth2-proxy run with --set-xauthrequest answers with X-Auth-Request-User
and X-Auth-Request-Groups; Caddy renames them on the way:
kaio.example.net { request_header -Remote-User request_header -Remote-Groups request_header -X-Kaio-Proxy-Secret
handle /oauth2/* { reverse_proxy 127.0.0.1:4180 }
handle { forward_auth 127.0.0.1:4180 { uri /oauth2/auth header_up X-Real-IP {remote_host} copy_headers X-Auth-Request-User>Remote-User X-Auth-Request-Groups>Remote-Groups @error status 401 handle_response @error { redir * /oauth2/sign_in?rd={scheme}://{host}{uri} } }
reverse_proxy 127.0.0.1:8080 { header_up X-Kaio-Proxy-Secret {$KAIO_PROXY_SECRET} flush_interval -1 } }}The Kaio side is the same as with Authelia.
Traefik with Authentik
Section titled “Traefik with Authentik”The Authentik outpost answers with X-authentik-username and
X-authentik-groups, pipe-separated, which Kaio reads as well:
services: kaio: image: ghcr.io/rgaidot/kaio:latest environment: - KAIO_ADDR=0.0.0.0:8080 - KAIO_TRUSTED_PROXIES=172.31.80.10 - KAIO_PROXY_SECRET_FILE=/run/secrets/kaio_proxy_secret - KAIO_IDENTITY_USER_HEADER=X-authentik-username - KAIO_IDENTITY_GROUPS_HEADER=X-authentik-groups - KAIO_GROUPS_READ=kaio-viewers - KAIO_GROUPS_ADMIN=authentik Admins secrets: - kaio_proxy_secret networks: kaio: ipv4_address: 172.31.80.2 labels: - "traefik.enable=true" - "traefik.http.routers.kaio.rule=Host(`kaio.example.net`)" - "traefik.http.routers.kaio.middlewares=kaio-strip,authentik,kaio-secret" - "traefik.http.services.kaio.loadbalancer.server.port=8080" - "traefik.http.services.kaio.loadbalancer.responseforwarding.flushinterval=-1" - "traefik.http.middlewares.kaio-strip.headers.customrequestheaders.X-authentik-username=" - "traefik.http.middlewares.kaio-strip.headers.customrequestheaders.X-authentik-groups=" - "traefik.http.middlewares.authentik.forwardauth.address=http://authentik-outpost:9000/outpost.goauthentik.io/auth/traefik" - "traefik.http.middlewares.authentik.forwardauth.trustForwardHeader=true" - "traefik.http.middlewares.authentik.forwardauth.authResponseHeaders=X-authentik-username,X-authentik-groups" - "traefik.http.middlewares.kaio-secret.headers.customrequestheaders.X-Kaio-Proxy-Secret=${KAIO_PROXY_SECRET}"
traefik: image: traefik:v3 networks: kaio: ipv4_address: 172.31.80.10
secrets: kaio_proxy_secret: file: ./proxy-secret
networks: kaio: ipam: config: - subnet: 172.31.80.0/24An empty value in customrequestheaders removes the header, which is what
kaio-strip does to whatever the client sent; authResponseHeaders then sets
them from Authentik’s answer. Fixing Traefik’s address on the network is what
lets KAIO_TRUSTED_PROXIES name one address rather than a range. Traefik reads
${KAIO_PROXY_SECRET} from the environment Compose is run with.
Traefik with Authelia
Section titled “Traefik with Authelia”Only the forward-auth middleware changes from the Authentik example:
- "traefik.http.routers.kaio.middlewares=kaio-strip,authelia,kaio-secret"- "traefik.http.middlewares.kaio-strip.headers.customrequestheaders.Remote-User="- "traefik.http.middlewares.kaio-strip.headers.customrequestheaders.Remote-Groups="- "traefik.http.middlewares.authelia.forwardauth.address=http://authelia:9091/api/authz/forward-auth"- "traefik.http.middlewares.authelia.forwardauth.trustForwardHeader=true"- "traefik.http.middlewares.authelia.forwardauth.authResponseHeaders=Remote-User,Remote-Groups,Remote-Email"And Kaio keeps its default header names, so only these remain:
KAIO_TRUSTED_PROXIES=172.31.80.10KAIO_PROXY_SECRET_FILE=/run/secrets/kaio_proxy_secretKAIO_GROUPS_WRITE=kaio-devsKAIO_GROUPS_ADMIN=kaio-adminsnginx with oauth2-proxy
Section titled “nginx with oauth2-proxy”server { listen 443 ssl; server_name kaio.example.net;
location /oauth2/ { proxy_pass http://127.0.0.1:4180; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }
location = /oauth2/auth { internal; proxy_pass http://127.0.0.1:4180; proxy_set_header Host $host; proxy_pass_request_body off; proxy_set_header Content-Length ""; }
location / { auth_request /oauth2/auth; error_page 401 = /oauth2/sign_in?rd=$scheme://$host$request_uri;
auth_request_set $kaio_user $upstream_http_x_auth_request_user; auth_request_set $kaio_groups $upstream_http_x_auth_request_groups;
proxy_pass http://127.0.0.1:8080; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Remote-User $kaio_user; proxy_set_header Remote-Groups $kaio_groups; include /etc/nginx/kaio-secret.conf;
proxy_buffering off; proxy_cache off; proxy_read_timeout 1h; }}proxy_set_header X-Kaio-Proxy-Secret "paste the secret here";proxy_set_header replaces whatever the client sent under the same name, and
sends nothing when the value is empty, so the client never chooses
Remote-User. Keep kaio-secret.conf mode 0600, owned by root: nginx reads it
before it drops privileges. The map for $connection_upgrade is the one in
nginx above. oauth2-proxy needs --set-xauthrequest, and
--oidc-groups-claim if your provider names the claim differently.
nginx with Authentik
Section titled “nginx with Authentik”The same server block, with the outpost in place of oauth2-proxy:
location /outpost.goauthentik.io { proxy_pass http://authentik-outpost:9000/outpost.goauthentik.io; proxy_set_header Host $host; proxy_set_header X-Original-URL $scheme://$http_host$request_uri; proxy_pass_request_body off; proxy_set_header Content-Length "";}
location / { auth_request /outpost.goauthentik.io/auth/nginx; error_page 401 = @goauthentik_proxy_signin;
auth_request_set $kaio_user $upstream_http_x_authentik_username; auth_request_set $kaio_groups $upstream_http_x_authentik_groups;
proxy_pass http://127.0.0.1:8080; proxy_set_header Remote-User $kaio_user; proxy_set_header Remote-Groups $kaio_groups; include /etc/nginx/kaio-secret.conf;}
location @goauthentik_proxy_signin { internal; return 302 /outpost.goauthentik.io/start?rd=$scheme://$http_host$request_uri;}Keep the WebSocket and buffering lines of the oauth2-proxy example in
location /. Authentik’s groups are pipe-separated, which Kaio reads as they
come.
Tailscale
Section titled “Tailscale”Two shapes, depending on whether you want names in the audit log.
A tailnet and nothing else. Bind Kaio to its tailnet address and let the tailnet be the allowlist:
KAIO_ADDR=100.84.12.7:8080KAIO_ALLOWED_NETWORKS=100.64.0.0/10,fd7a:115c:a1e0::/48KAIO_NETWORK_LEVEL=writeEvery tailnet peer your ACL lets through reaches Kaio, at write here, and the
audit log names it by its tailnet address. Leave Funnel off: it is the one
Tailscale feature that puts the port back on the public Internet.
Tailscale Serve in front. Serve terminates TLS on the tailnet name and adds
Tailscale-User-Login to every request it forwards to the loopback:
tailscale serve --bg --https=443 http://127.0.0.1:8080KAIO_ADDR=127.0.0.1:8080KAIO_TRUSTED_PROXIES=127.0.0.1KAIO_IDENTITY_USER_HEADER=Tailscale-User-LoginServe sends no groups and no shared secret. With no secret on the loopback, a
user it names is held to KAIO_LOCAL_LEVEL, since any process on the host could
send the same header: every Serve user gets that level, admin by default, and
the audit log names them by login. Set KAIO_LOCAL_LEVEL=read to keep both them
and the host’s own processes to reading.
WireGuard
Section titled “WireGuard”The same shape as a bare tailnet, with the peer list as the allowlist:
KAIO_ADDR=10.8.0.1:8080KAIO_ALLOWED_NETWORKS=10.8.0.0/24Bind to the interface address, not 0.0.0.0, so that the port is not on the
host’s public interface at all. KAIO_ALLOWED_NETWORKS is then a second lock
behind the first: if the bind ever widens, a caller off the tunnel is still
refused.
Checking it works
Section titled “Checking it works”curl -N -H "Accept: text/event-stream" https://kaio.example.com/api/eventsEvents should appear as they happen. If the command hangs with nothing, or if lines arrive in blocks after a delay, response buffering is still on somewhere.
Kaio, built by Régis Gaidot