feat: users, roles and per-area permissions, production demo image

The controller checks every route against the signed-in user's role, with
levels none, view, control and edit per area. Guests get the permissions
of a built-in guest role. Auth stays off until the first user exists;
LED_ADMIN_USER and LED_ADMIN_PASSWORD create the first admin.

Sessions are cookies, passwords are PBKDF2-SHA256, and logins lock per
username after five failures. The simulator's WebSocket checks the view
permission at handshake and per frame; /ws needs devices control. The web
UI gets a sign-in button, a sign-in prompt on refused changes, and a users
and roles screen.

Also: the device build gets the bridge include path and forward type it
was missing, Dockerfile.sim runs non-root, and Dockerfile.prod with
docker-compose.prod.yml runs the controller on an internal network behind
Caddy for HTTPS.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Haiku 5.5 committed 2026-11-17 00:29:04 +13:00
1 parent 02440be55d
commit f0615dc1b7
26 files changed
+2116 -23

No files matched your search

+9 -1
View File
@@ -1,3 +1,4 @@
#include "auth.h"
#include "ws.h"
#include <stdlib.h>
@@ -49,6 +50,9 @@ static void forward(httpd_req_t *req, const char *text)
// snapshot is always empty.
static esp_err_t on_open(httpd_req_t *req)
{
if (auth_ws_admit(req, "devices", AUTH_CONTROL) != ESP_OK) {
return ESP_FAIL; // closes the socket: driving drivers needs devices control
}
send_text(req, "{\"type\":\"device_tcp_snapshot\",\"connected_ips\":[]}");
return ESP_OK;
}
@@ -80,7 +84,11 @@ static esp_err_t ws_handler(httpd_req_t *req)
err = httpd_ws_recv_frame(req, &f, f.len);
if (err == ESP_OK) {
buf[f.len] = 0;
forward(req, buf);
if (auth_ws_allowed(httpd_req_to_sockfd(req), "devices", AUTH_CONTROL)) {
forward(req, buf);
} else {
send_text(req, "{\"error\":\"not allowed\"}");
}
}
free(buf);
return err;