mirror of
https://github.com/Donkie/Spoolman.git
synced 2026-10-22 10:02:17 -05:00
Adds the configuration surface for the opt-in authentication system. Nothing reads these yet beyond the startup secret-key resolution; the gates that consume them arrive in later commits. New variables, all documented in .env.example: SPOOLMAN_AUTH_ENABLED enforce authentication (default FALSE) SPOOLMAN_SECRET_KEY[_FILE] instance secret key SPOOLMAN_TRUSTED_PROXIES proxies whose forwarding headers we believe SPOOLMAN_COOKIE_SECURE AUTO/TRUE/FALSE override for the Secure flag SPOOLMAN_METRICS_PUBLIC keep /metrics open while auth is on SPOOLMAN_METRICS_TOKEN[_FILE] shared token granting /metrics access Notes: - A private _parse_bool helper covers the new booleans. The five existing boolean accessors are deliberately left inlined: each carries a bespoke error message that users quote in bug reports, and rewriting them would turn this into an unrelated refactor. - _read_env_or_file strips file contents, unlike get_password(). Key and token files are normally produced by a shell redirect, and an unstripped trailing newline would silently yield a different secret than the one the operator wrote. - The generated key file is created with an exclusive open at mode 0600 rather than a write followed by chmod, so its contents are never briefly world-readable under a permissive umask. An existing file with looser permissions warns rather than fails, since some bind mounts cannot represent 0600. - ensure_secret_key() runs in startup() after the data-directory write check and before the alembic subprocess: it needs a writable directory but no schema, so a misconfiguration fails fast with an actionable message. It is guarded by is_auth_enabled(), so an auth-disabled instance never grows the file. Phase 1 does not use the key cryptographically -- session tokens are opaque random values stored as SHA-256, and CSRF is a double-submit cookie compare. It is introduced now because phases 3 and 4 consume it, and adding it later would force every phase-1 adopter to reconfigure. Verified: generation yields mode 0600, precedence is _FILE > env > generated, trailing newlines are stripped, a missing key file raises a clear ValueError, and CSV/AUTO parsing round-trips.
138 lines
5.2 KiB
Bash
138 lines
5.2 KiB
Bash
# DB Type: sqlite, mysql, postgres, cockroachdb
|
|
# Default if not set: sqlite
|
|
#SPOOLMAN_DB_TYPE=sqlite
|
|
|
|
# DB Setup, if not using sqlite
|
|
# Database hostname
|
|
#SPOOLMAN_DB_HOST=
|
|
# Database port
|
|
#SPOOLMAN_DB_PORT=
|
|
# Database name
|
|
#SPOOLMAN_DB_NAME=
|
|
# Database login username
|
|
#SPOOLMAN_DB_USERNAME=
|
|
# Path of file which contains the database password. Can be used instead of SPOOLMAN_DB_PASSWORD if desired.
|
|
#SPOOLMAN_DB_PASSWORD_FILE=
|
|
# Database login password
|
|
#SPOOLMAN_DB_PASSWORD=
|
|
# Query parameters for the database connection, e.g. set to `unix_socket=/path/to/mysql.sock` to connect using a MySQL socket.
|
|
#SPOOLMAN_DB_QUERY=
|
|
|
|
# Logging level: DEBUG, INFO, WARNING, ERROR, CRITICAL
|
|
# Logs will only be reported if the level is higher than the level set here
|
|
# Default if not set: INFO
|
|
#SPOOLMAN_LOGGING_LEVEL=INFO
|
|
|
|
# Automatic nightly backup for SQLite databases
|
|
# Default if not set: TRUE
|
|
#SPOOLMAN_AUTOMATIC_BACKUP=TRUE
|
|
|
|
# Data directory, where the SQLite database is stored
|
|
# Default if not set: /home/<user>/.local/share/spoolman
|
|
#SPOOLMAN_DIR_DATA=/home/pi/spoolman_data
|
|
|
|
# Backup directory, where the SQLite database backups are stored
|
|
# Default if not set: /home/<user>/.local/share/spoolman/backups
|
|
#SPOOLMAN_DIR_BACKUPS=/home/pi/spoolman_data/backups
|
|
|
|
# Log directory
|
|
# Default if not set: /home/<user>/.local/share/spoolman
|
|
#SPOOLMAN_DIR_LOGS=/home/pi/spoolman_data
|
|
|
|
# Host and port to listen on
|
|
SPOOLMAN_HOST=0.0.0.0
|
|
SPOOLMAN_PORT=7912
|
|
|
|
# Change base path
|
|
# Set this if you want to host Spoolman at a sub-path
|
|
# If you want the root to be e.g. myhost.com/spoolman
|
|
# Then set this to /spoolman
|
|
#SPOOLMAN_BASE_PATH=
|
|
|
|
# Enable Collect Prometheus metrics at database
|
|
# Default: FALSE
|
|
#SPOOLMAN_METRICS_ENABLED=TRUE
|
|
|
|
# Collect items (filaments, materials, etc.) from an external database
|
|
# Set this to a URL of an external database. Set to an empty string to disable
|
|
# Default: https://donkie.github.io/SpoolmanDB/
|
|
#EXTERNAL_DB_URL=https://myhost.com/spoolmandb/
|
|
# Sync interval in seconds, set to 0 to disable automatic sync. It will only sync on start-up then.
|
|
# Default: 3600
|
|
#EXTERNAL_DB_SYNC_INTERVAL=3600
|
|
# Display name for the external database, shown in the UI.
|
|
# Set this to match your own catalog if you changed EXTERNAL_DB_URL above.
|
|
# Default: SpoolmanDB
|
|
#EXTERNAL_DB_NAME=SpoolmanDB
|
|
|
|
# Enable debug mode
|
|
# If enabled, the client will accept requests from any host
|
|
# This can be useful when developing, but is also a security risk
|
|
# Default: FALSE
|
|
#SPOOLMAN_DEBUG_MODE=TRUE
|
|
|
|
# UID and GID of the user in the docker container
|
|
# These only make sense if you are running Spoolman in a docker container
|
|
# Default if not set: 1000
|
|
#PUID=1000
|
|
#PGID=1000
|
|
|
|
# Allows CORS ORIGIN.
|
|
# Use the https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin semantics
|
|
# separated by commas
|
|
# for example to allow request from source1.domain.com on port p1 and source2.domain.com on port p2
|
|
# SPOOLMAN_CORS_ORIGIN=source1.domain.com:p1, source2.domain.com:p2
|
|
# to allow from any
|
|
# SPOOLMAN_CORS_ORIGIN=*
|
|
|
|
#
|
|
# --- Authentication (opt-in) ---
|
|
#
|
|
# Spoolman has no authentication unless you switch it on here. With
|
|
# SPOOLMAN_AUTH_ENABLED unset, every endpoint stays open to anyone who can reach
|
|
# the port, exactly as before.
|
|
#
|
|
|
|
# Enforce authentication on the API and the web UI.
|
|
# The first visitor after enabling this claims the instance and becomes the owner,
|
|
# so enable it and claim the account before exposing the port.
|
|
# Default: FALSE
|
|
#SPOOLMAN_AUTH_ENABLED=TRUE
|
|
|
|
# Secret key for this instance.
|
|
# Leave unset and Spoolman generates one in the data directory (secret.key, mode
|
|
# 0600) on first start. Set it explicitly if you would rather manage it yourself or
|
|
# need it to be identical across a rebuild.
|
|
# Use SPOOLMAN_SECRET_KEY_FILE to read it from a file instead, e.g. a docker secret.
|
|
# Trailing whitespace in the file is ignored.
|
|
#SPOOLMAN_SECRET_KEY=
|
|
#SPOOLMAN_SECRET_KEY_FILE=/run/secrets/spoolman_secret_key
|
|
|
|
# Reverse proxies whose forwarding headers Spoolman may believe.
|
|
# Comma-separated IP addresses or CIDR networks. Until a proxy is listed here,
|
|
# X-Forwarded-For and X-Forwarded-Proto are ignored, which means rate limiting sees
|
|
# your proxy's address instead of the real client's.
|
|
# Note this is separate from uvicorn's own FORWARDED_ALLOW_IPS.
|
|
# Default: empty (trust nothing)
|
|
#SPOOLMAN_TRUSTED_PROXIES=172.16.0.0/12, 10.0.0.0/8
|
|
|
|
# Force the Secure flag on session cookies.
|
|
# AUTO derives it from the request scheme, which is almost always right. Set TRUE if
|
|
# you terminate TLS on a proxy that does not send X-Forwarded-Proto. Setting it TRUE
|
|
# on a plain-HTTP deployment makes the browser discard the cookie and login will
|
|
# fail silently.
|
|
# Default: AUTO
|
|
#SPOOLMAN_COOKIE_SECURE=AUTO
|
|
|
|
# Keep the /metrics endpoint reachable without credentials while auth is enabled.
|
|
# Only consulted when SPOOLMAN_AUTH_ENABLED is set; metrics are public otherwise.
|
|
# Default: FALSE
|
|
#SPOOLMAN_METRICS_PUBLIC=TRUE
|
|
|
|
# Shared token granting access to /metrics, sent as "Authorization: Bearer <token>"
|
|
# or "X-Api-Key: <token>". Use SPOOLMAN_METRICS_TOKEN_FILE to read it from a file.
|
|
# With auth enabled and neither this nor SPOOLMAN_METRICS_PUBLIC set, /metrics
|
|
# returns 401 to everyone.
|
|
#SPOOLMAN_METRICS_TOKEN=
|
|
#SPOOLMAN_METRICS_TOKEN_FILE=/run/secrets/spoolman_metrics_token
|