Authenticate WebSocket connections and bind command results to their worker
Security / JS Security (npm audit) (push) Failing after 16s
Lint / JS (eslint) (push) Successful in 18s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Test / JS Tests (jest) (push) Successful in 15s
Lint / JS (eslint) (pull_request) Successful in 13s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / JS Security (npm audit) (pull_request) Failing after 17s
Test / JS Tests (jest) (pull_request) Successful in 15s
Security / JS Security (npm audit) (push) Failing after 16s
Lint / JS (eslint) (push) Successful in 18s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Test / JS Tests (jest) (push) Successful in 15s
Lint / JS (eslint) (pull_request) Successful in 13s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / JS Security (npm audit) (pull_request) Failing after 17s
Test / JS Tests (jest) (pull_request) Successful in 15s
Any client that could reach :8080 got a WebSocket connection. Every connection started as a browser client and received every broadcast. worker_connect accepted a missing api_key, so anyone could register under an existing worker's name and receive its commands. command_result was accepted from any connection, so execution logs could be forged. - Classify each upgrade in verifyClient (lib/wsauth.js). A request is: - browser: a trusted-proxy Authelia identity in an allowed group; - worker: Authorization: Bearer <WORKER_API_KEY>; - pending: neither, allowed only while WORKER_AUTH_ENFORCE is off; - rejected (401): everything else, and always for a wrong key. - Only browser connections receive broadcasts. A pending connection may send only worker_connect and is closed after 30 s if it doesn't identify. - worker_connect requires the key. A keyless worker is allowed with a warning until WORKER_AUTH_ENFORCE=1, so existing workers keep working until they are updated. - Record which worker each command was sent to. command_result is accepted only from that worker (matched by DB id, so a reconnect mid-command still works) and only once. pong no longer trusts a client-supplied id. - Worker, heartbeat and Gandalf keys use a constant-time compare. Log an error at startup if WORKER_API_KEY is unset. - The worker sends its key at the handshake and in worker_connect. Closes #38 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b8a7b2c3b9
commit
ac6c6c72c5
5 files changed
+283
-22
No files matched your search
@@ -424,6 +424,7 @@ DB_USER=pulse_user # Database user
|
||||
DB_PASSWORD=<password> # Database password
|
||||
WORKER_API_KEY=<api-key> # Worker authentication key
|
||||
TRUSTED_PROXIES=<ip>[,<ip/cidr>] # Proxies allowed to send Authelia identity headers (required, see below)
|
||||
WORKER_AUTH_ENFORCE=1 # Refuse workers that don't send WORKER_API_KEY (see WebSocket authentication)
|
||||
EXECUTION_RETENTION_DAYS=30 # Auto-cleanup retention (default: 30)
|
||||
|
||||
# Web UI (all optional)
|
||||
@@ -448,6 +449,21 @@ anywhere else are treated as not logged in, and are logged with their source add
|
||||
closed: if `TRUSTED_PROXIES` is unset, no SSO login succeeds and a warning is printed at
|
||||
startup. Invalid entries are logged and skipped. Worker and Gandalf API-key routes don't use it.
|
||||
|
||||
### WebSocket authentication
|
||||
|
||||
Every WebSocket upgrade is authenticated. A browser connection must come through a trusted proxy
|
||||
(see above) with an Authelia identity in the `admin` or `employee` group, and only those
|
||||
connections receive the live event feed. A worker authenticates with
|
||||
`Authorization: Bearer <WORKER_API_KEY>` at the handshake, and also sends the key in its
|
||||
`worker_connect` message. A wrong key is always refused. Only a connection that identified as a
|
||||
worker can deliver command results, and only for commands the server sent to that worker.
|
||||
|
||||
Workers older than this change don't send a key. Until every worker is updated, leave
|
||||
`WORKER_AUTH_ENFORCE` unset: keyless workers are still accepted, with a `[Security]` warning
|
||||
naming the worker, and an unauthenticated connection that doesn't identify as a worker within 30 s
|
||||
is closed. Once the warnings stop, set `WORKER_AUTH_ENFORCE=1` and restart. From then on, upgrades
|
||||
with no valid credentials get a 401.
|
||||
|
||||
### Local development against a real database
|
||||
|
||||
Running a local instance against the production MariaDB is safe only with the read-only guard on:
|
||||
|
||||
Reference in new issue
Block a user