89 lines
2.8 KiB
Markdown
89 lines
2.8 KiB
Markdown
# Authentication
|
|
|
|
The current server has a starter authentication layer:
|
|
|
|
- persistent local users in a JSON file
|
|
- form login at `/login`
|
|
- logout at `/logout`
|
|
- HTTP-only session cookie
|
|
- protected dashboard, API, and printer proxy routes
|
|
- self-service account page at `/account`
|
|
- admin audit trail at `/audit`
|
|
- admin-only user management at `/users`
|
|
- per-user printer grants with read or control access
|
|
|
|
For local development, Docker Compose uses:
|
|
|
|
```text
|
|
username: admin
|
|
password: admin
|
|
```
|
|
|
|
Run the server with different credentials:
|
|
|
|
```powershell
|
|
$env:KA_AGENT_TOKEN = "replace-agent-token"
|
|
$env:KA_ADMIN_USER = "your-user"
|
|
$env:KA_ADMIN_PASSWORD = "your-password"
|
|
klipperanywhere-server -listen :8080
|
|
```
|
|
|
|
When serving over HTTPS, enable secure cookies:
|
|
|
|
```powershell
|
|
$env:KA_COOKIE_SECURE = "true"
|
|
klipperanywhere-server -listen :8080
|
|
```
|
|
|
|
CLI flags still exist for local overrides, but environment variables are preferred
|
|
for secrets.
|
|
|
|
The users file defaults to `data/users.json` in the server working directory.
|
|
Set `KA_USERS_FILE` if you want it stored elsewhere.
|
|
|
|
## Current Protections
|
|
|
|
- `/login` is rate limited by client IP.
|
|
- Session cookies are HTTP-only and expire after 12 hours.
|
|
- `/logout` requires POST plus a per-session CSRF token.
|
|
- `/dashboard`, `/users`, `/api/users*`, `/api/printers*`,
|
|
`/account`, `/audit`, `/printers/{printer_id}/ui/*`, and `/p/*` require a session.
|
|
- printer routes also enforce per-user grants, so users only see printers they
|
|
have been assigned.
|
|
- `/api/account` lets the signed-in user change their own password after
|
|
confirming the current password.
|
|
- `/api/audit` returns recent audit events for admins.
|
|
- Moonraker browser proxy traffic defaults to read-only mode. Set
|
|
`KA_CONTROL_MODE=full` or `-control-mode full` only when authenticated users
|
|
should be allowed to send normal Mainsail/Fluidd control commands.
|
|
- The server warns when default credentials, default agent token, or insecure
|
|
cookies are used.
|
|
|
|
## Printer Control Mode
|
|
|
|
The server supports two control modes:
|
|
|
|
```text
|
|
readonly
|
|
full
|
|
```
|
|
|
|
`readonly` is the default. It allows health, info, camera, UI asset, and common
|
|
Moonraker read paths, but blocks representative risky HTTP and WebSocket control
|
|
traffic such as G-code scripts, print pause/resume/cancel, emergency stop, machine
|
|
commands, and file mutation routes.
|
|
|
|
`full` forwards authenticated browser traffic to Moonraker without that starter
|
|
policy block. Use it only behind HTTPS with non-default credentials.
|
|
|
|
## Public Exposure Notes
|
|
|
|
This is still a lightweight self-hosted auth layer. Before recommending public
|
|
internet deployment, the project still needs:
|
|
|
|
- durable session storage and explicit session secret configuration
|
|
- CSRF protection for all state-changing browser requests
|
|
- rate limiting on login
|
|
- TLS deployment guide
|
|
- audit logging tied to user identity
|