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

+2 -1
View File
@@ -10,6 +10,7 @@
* LED_SIM_HTTP_PORT web UI / API port, default 8080
* The store is the /db directory (mount a volume there to keep it).
*/
#include "auth.h"
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -98,7 +99,7 @@ static void start_webserver(void)
abort();
}
const httpd_uri_t status_uri = { .uri = "/status", .method = HTTP_GET, .handler = status_get_handler };
httpd_register_uri_handler(server, &status_uri);
auth_register_uri(server, &status_uri);
sim_rig_register(server);
web_register(server);
audio_register(server);
+10 -3
View File
@@ -22,6 +22,7 @@
* "direction" the way it runs (degrees clockwise from +y), "mac" the driver. Each bar's flash is
* <db>/sim/flash/<mac>.json, so a bar keeps its presets in every room it appears in.
*/
#include "auth.h"
#include "sim_rig.h"
#include <ctype.h>
@@ -630,6 +631,9 @@ bool sim_rig_tx(const uint8_t *frame, size_t len)
static esp_err_t ws_open(httpd_req_t *req)
{
if (auth_ws_admit(req, "sim", AUTH_VIEW) != ESP_OK) {
return ESP_FAIL;
}
int fd = httpd_req_to_sockfd(req);
xSemaphoreTake(s_tx_mu, portMAX_DELAY);
int old = page_open_locked() ? s_page_fd : -1;
@@ -686,6 +690,9 @@ static esp_err_t ws_handler(httpd_req_t *req)
}
f.payload = buf;
err = httpd_ws_recv_frame(req, &f, f.len);
if (err == ESP_OK && !auth_ws_allowed(httpd_req_to_sockfd(req), "sim", AUTH_VIEW)) {
err = ESP_FAIL; // closes the socket: the socket was not admitted at its handshake
}
if (err == ESP_OK) {
buf[f.len] = 0;
if (f.type == HTTPD_WS_TYPE_BINARY) {
@@ -981,15 +988,15 @@ esp_err_t sim_rig_register(httpd_handle_t server)
static const httpd_method_t METHODS[] = { HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_DELETE };
for (size_t i = 0; i < 4 && err == ESP_OK; i++) {
const httpd_uri_t u = { .uri = "/sim/api/*", .method = METHODS[i], .handler = api_handler };
err = httpd_register_uri_handler(server, &u);
err = auth_register_uri(server, &u);
}
const httpd_uri_t root = { .uri = "/sim", .method = HTTP_GET, .handler = page_handler };
const httpd_uri_t files = { .uri = "/sim/*", .method = HTTP_GET, .handler = page_handler };
if (err == ESP_OK) {
err = httpd_register_uri_handler(server, &root);
err = auth_register_uri(server, &root);
}
if (err == ESP_OK) {
err = httpd_register_uri_handler(server, &files);
err = auth_register_uri(server, &files);
}
if (err != ESP_OK) {
ESP_LOGE(TAG, "register: %s", esp_err_to_name(err));
+2 -1
View File
@@ -1,4 +1,5 @@
// Host build: what the board's hardware files (mic.c, ota.c, littlefs) provide, without hardware
#include "auth.h"
#include <string.h>
#include <sys/stat.h>
#include "esp_littlefs.h"
@@ -60,5 +61,5 @@ static esp_err_t ota_unsupported(httpd_req_t *req)
esp_err_t ota_register(httpd_handle_t server)
{
const httpd_uri_t u = { .uri = "/ota", .method = HTTP_POST, .handler = ota_unsupported };
return httpd_register_uri_handler(server, &u);
return auth_register_uri(server, &u);
}