Advanced setup
First sign-in
A new installation has no default account. Complete the onboarding page with the setup token from the server log, as described in Quick start.
Docker Deployment
Endurain provides a Docker image for simplified deployment. To get started, check out the docker-compose.yml.example file in the project repository and adjust it according to your setup. Supported tags are:
- latest: contains the latest released version;
- major.minor version, example "v0.18": latest patch release within the v0.18.x train;
- version, example "v0.3.0": contains the app state available at the time of the version specified;
- development version, example "dev-
": contains a development build of the commit specified. This is not a stable release and may contain issues and bugs. Please do not open issues if using a version like this unless asked by me.
Supported Environment Variables
Table below shows supported environment variables. Variables marked with optional "No" must be set, or Endurain does not start.
| Environment variable | Default value | Optional | Notes |
|---|---|---|---|
| LOCAL_PATH | /var/opt/endurain | Yes | Root directory for Docker volume mounts. Controls where activity files, images, logs, and database data are stored on the host. |
| TZ | UTC | Yes | Timezone definition. Useful for TZ calculation for activities that do not have coordinates associated, like indoor swim or weight training. If not specified UTC will be used. List of available time zones here. Format Europe/Lisbon expected |
| FRONTEND_DIR | /app/frontend/dist |
Yes | You will only need to change this value if installing using bare metal method |
| BACKEND_DIR | /app/backend |
Yes | You will only need to change this value if installing using bare metal method |
| DATA_DIR | /app/backend/data |
Yes | You will only need to change this value if installing using bare metal method |
| LOGS_DIR | /app/backend/logs |
Yes | You will only need to change this value if installing using bare metal method |
| FILES_DIR | $DATA_DIR/activity_files |
Yes | Directory for activity files (processed, bulk import, upload staging). You will only need to change this value if installing using bare metal method |
| ENDURAIN_HOST | No default set | No |
Required for internal communication and Strava. For Strava https must be used. Host or local ip (example: http://192.168.1.10:8080 or https://endurain.com). Must be only scheme://host[:port]: no user info, path, trailing slash, query or fragment, or Endurain refuses to start. Endurain lower-cases the scheme and host and drops the default port (:443 for https, :80 for http), so HTTPS://Endurain.Example.com:443 is used as https://endurain.example.com; that form is the token issuer and audience and the allowed browser origin. Plain http logs a warning at startup except for localhost, 127.0.0.1 and ::1 |
| DB_HOST | postgres | Yes | postgres |
| DB_PORT | 5432 | Yes | PostgreSQL port |
| DB_USER | endurain | Yes | N/A |
| DB_PASSWORD | No default set | No |
Database password. Alternatively, use DB_PASSWORD_FILE for Docker secrets |
| DB_DATABASE | endurain | Yes | N/A |
| DB_SSLMODE | (empty) | Yes | Optional TLS mode for the PostgreSQL connection. Leave empty to disable (default — keeps local Postgres without SSL working). Accepted values match libpq: disable, allow, prefer, require, verify-ca, verify-full. Recommended for any deployed environment: require. Most secure (validates CA + hostname): verify-full |
| DB_POOL_SIZE | 20 | Yes | Connections each Endurain process keeps open to PostgreSQL. Must be at least 1; an unusable value falls back to the default. See Sizing |
| DB_MAX_OVERFLOW | 40 | Yes | Extra connections each process may open under load, on top of DB_POOL_SIZE. 0 or more; an unusable value falls back to the default. See Sizing |
| DB_STATEMENT_TIMEOUT_SECONDS | 0 | Yes | Longest a single SQL statement may run before PostgreSQL cancels it, in seconds. 0 (default) disables the limit. Database migrations run on the same connection settings, so leave it unset for the start that upgrades the schema if a migration may run long |
| DB_POOL_TIMEOUT_SECONDS | 30 | Yes | Longest a request waits for a free pooled connection before it fails, in seconds. Must be at least 1; an unusable value falls back to the default. See Sizing |
| DB_LOCK_TIMEOUT_SECONDS | 30 | Yes | Longest a statement waits for a row lock before PostgreSQL fails it, in seconds. Must be at least 1, so a lock can never be waited on forever; an unusable value falls back to the default |
| SECRET_KEY | No default set | No |
Run openssl rand -hex 32 on a terminal or use the Secret Generators tool. Example output is 69b85208190c96821050d4ba980a8a95d928ab7e0ebf1a40b8ef6d09fd8367d3. A key shorter than 32 characters, or with fewer than 10 distinct characters, stops the start. Alternatively, use SECRET_KEY_FILE for Docker secrets. To rotate the key, list several separated by commas: the first signs and all of them verify. See Rotating the signing key |
| FERNET_KEY | No default set | No |
Run openssl rand -base64 32 on a terminal or use the base64 tool in the Secret Generators. Example output is 7NfMMRSCWcoNDSjqBX8WoYH9nTFk1VdQOdZY13po53Y=. Alternatively, use FERNET_KEY_FILE for Docker secrets. To rotate the key, list several separated by commas: the first encrypts and all of them decrypt. See Rotating the encryption key |
| BEHIND_PROXY | false | Yes | Change to true if behind reverse proxy. Requires TRUSTED_PROXIES: the container refuses to start without a usable entry (a FORWARDED_ALLOW_IPS override also counts). |
| ENVIRONMENT | production | Yes | production, demo and development allowed. development allows connections from localhost:8080, localhost:5173 and localhost:5174 at the CORS level and does not enforce a consistent deployment profile (see Scaling and background jobs). demo equals to production except it does not return user sessions. demo and development also serve the API documentation pages and the OpenAPI schema. production and demo set the Secure flag on all authentication cookies (refresh token, OAuth/SSO session and device id), so Endurain must be served over HTTPS (directly or via a reverse proxy terminating TLS) for login, session refresh, and SSO to work |
| LOG_LEVEL | info | Yes | Supported levels: critical, error, warning, info, debug, trace |
| LOG_ACCESS | false | Yes | Set to true to log every API request (Uvicorn access log). Hidden by default. Applies when the container starts through the bundled start.sh |
| LOG_WEBSOCKET_FRAMES | false | Yes | Set to true to log the websocket PING/PONG keepalive frames shown at LOG_LEVEL=debug. Hidden by default |
| ALLOWED_REDIRECT_URIS | com.endurain.endurain:/auth/sso/callback |
Yes | An app listed here receives tokens with every scope the signing-in user holds, administrator scopes included, so list only apps you trust with the whole account. Comma-separated list of the exact redirect addresses mobile apps may use after SSO (e.g., com.endurain.endurain:/auth/sso/callback,nodomain.freeyourgadget.gadgetbridge://endurain/oauth/callback). It is the only redirect allow-list: a redirect with a scheme must equal a listed address, and relative paths need no entry. The default is the callback of the Endurain mobile app. Setting the variable replaces the default, so keep com.endurain.endurain:/auth/sso/callback in the list. The scheme is matched case-insensitively and the rest exactly, so the same scheme with another path, or with a query string or fragment, is refused. Each entry is scheme:target, the // after the scheme optional (org.endurain.app:/callback and org.endurain.app://callback both work), or an exact https://host/path address for an Android App Link or iOS Universal Link, which needs a host, no user info and a valid port. Startup fails on an entry with a control character, without a target, with http, javascript, data, file, vbscript or blob, or with a malformed https address. See Mobile SSO with PKCE |
| TRUSTED_PROXIES | No default set | Yes (required when BEHIND_PROXY is true) |
Comma-separated list of trusted proxy IPs, CIDR ranges, or hostnames for correct client IP detection. Endurain reads X-Forwarded-For only from a connecting peer that matches an entry. BEHIND_PROXY is read only by the container entrypoint, which requires this variable when it is true. Defaults to [] (no proxy trusted) in every environment. * trusts every peer and lets a client forge its address with X-Forwarded-For, so use it only when nothing but the proxy can reach Endurain. Endurain joins repeated X-Forwarded-For lines into one list, reads it from the right, and takes the first address that is not a trusted proxy as the client; a hop is an IP address with an optional port, and a hop that is not one makes Endurain use the address of the connecting peer instead. Hostname support: You can use hostnames (e.g., proxy.internal or Docker container names like caddy) which are resolved to IPs at application startup and refreshed every minute in memory. This is useful in Docker deployments where container IPs may change on restart. If a hostname cannot be resolved, a warning is logged and the entry is skipped (graceful degradation). |
| SSRF_ALLOWED_HOSTS | No default set | Yes | Comma-separated allowlist of exact hostnames (case-insensitive) and/or explicit IP CIDR ranges that may resolve to private/internal or other non-public addresses (including shared address space such as Tailscale, 100.64.0.0/10) for admin-configured outbound calls (identity provider discovery, signing keys, token, userinfo and revocation calls, and the sign-in redirect). A listed host may also use plain http:// for these; any other identity provider URL must use https://. Enables self-hosted identity providers (Authentik, Pocket ID, Keycloak, ...) reachable only over a private network. Example: auth.internal.example.com,10.10.0.0/24,fd00::/64. Wildcards (*) are rejected; CIDRs must be at least /8 for IPv4 and /32 for IPv6. Also covers the reverse-geocoding host and the map tile server used for activity thumbnails. Every allowlisted outbound call is audit-logged at INFO. |
| CSP_ADDITIONAL_CONNECT_SRC | No default set | Yes | Comma-separated list of extra origins appended to the Content-Security-Policy connect-src directive. Set this when Endurain is behind a forward-auth reverse proxy (e.g. Pangolin) that redirects API calls to its own domain for session validation; without its origin here the browser blocks the redirect with a CSP error and the app fails to load. Example: https://auth.example.com. Use specific origins: overly broad values that would defeat connect-src are ignored with a warning at startup — the bare wildcard * and scheme-only sources like https: (host wildcards such as https://*.example.com are fine). Entries containing whitespace or ; are also ignored (to prevent header injection). Default: empty (connect-src stays 'self' plus https://api.github.com for the update check). |
| HSTS_PRELOAD | false | Yes | Adds preload to the Strict-Transport-Security header (max-age=31536000; includeSubDomains; preload). The header is sent only in deployed environments. preload has an effect only after you submit your domain to hstspreload.org; browsers then force HTTPS for the domain and all its subdomains, and removal from the list takes months, so enable it only when every subdomain serves HTTPS permanently. |
| RATE_LIMIT_ENABLED | true | Yes | Enable or disable API rate limiting. Set to false to disable for development or testing. Accepted values are true and false |
| DEPLOYMENT_PROFILE | local | Yes | Deployment shape selecting the backend for all shared state. local (default) uses in-process memory; distributed requires Redis and JOBS_ENABLED=true; custom has no defaults and every capability must be set (see Scaling and background jobs). A distributed or multi-worker deployment wired to memory is rejected at startup. |
| WEB_WORKERS | 1 | Yes | Number of web-server worker processes. When > 1, shared state (Redis) is required even under the local profile. |
| STATE_URI | No default set | Yes | Explicit override for the shared ephemeral-state backend (rate-limit counters, login/step-up lockout, pending-MFA, MFA setup secrets, Garmin MFA codes, websocket tickets). Takes precedence over REDIS_URL. memory:// or redis://…. |
| REDIS_URL | No default set | Yes | Shared Redis DSN for every Redis capability with no explicit URI. Required for distributed or WEB_WORKERS > 1. |
| EVENT_LOG_RETENTION_DAYS | 90 | Yes | Age in days after which event-log observability rows are pruned by a scheduled cleanup (runs daily and once at startup). The jasil_event_log table records every background event's lifecycle for diagnostics; it is best-effort and safe to lose, so every row older than this is removed. Accepts up to 36500. Set to 0 (or negative) to disable pruning and keep rows forever. |
| EVENT_LOG_ENABLED | true | Yes | Record every background event's lifecycle in the jasil_event_log table. Set to false to skip those writes. See Troubleshooting. |
| AUDIT_SIGNING_KEY | No default set | Yes | Optional Ed25519 private key that signs the audit trail's checkpoints, so a changed row can be told from a resealed one. See Audit trail to generate one. Alternatively, use AUDIT_SIGNING_KEY_FILE for Docker secrets |
| AUDIT_EXTERNAL_SINK_URI | No default set | Yes | Optional write-once copy of every audit checkpoint, kept outside the database: file:///absolute/directory or s3://bucket/prefix. See Audit trail |
| STORAGE_URI, EVENTS_URI, LOCK_URI, JOBS_ENABLED, JOBS_*, APP_ROLE | see page | Yes | Blob storage, event bus, coordination lock and the durable job queue. Documented in Scaling and background jobs. |
| JOBS_RETENTION_DAYS | 90 | Yes | Age in days after which completed durable-job bookkeeping is pruned by the same scheduled cleanup: relayed outbox rows and completed background-job rows. In-flight work (pending/running jobs, unrelayed outbox rows) and dead-lettered jobs (kept for review) are never pruned. The durable-job part is only relevant when the durable job queue is enabled. The same age also prunes ingestion job records and the failed bulk-import files in bulk_import_errors, with or without the queue. Accepts up to 36500; set to 0 (or a negative value) to disable pruning. |
| ALLOW_API_KEY_QUERY_PARAM | false | Yes | Allow API keys to be passed as a ?api_key= query parameter. Disabled by default because query-string credentials appear in server access logs, reverse-proxy logs, and browser history. Enable only for integrations that cannot set custom request headers (e.g. some webhook senders). The X-API-Key header is always preferred. When enabled, every request that uses the query parameter emits a warning in the application log. |
TRUSTED_PROXIES Examples
When running Endurain behind a reverse proxy (e.g., Caddy, Nginx) with BEHIND_PROXY=true, configure TRUSTED_PROXIES to ensure correct client IP detection:
Docker Compose with Hostname (Recommended for Docker):
services:
endurain:
environment:
BEHIND_PROXY: "true"
TRUSTED_PROXIES: "caddy" # Use the service name of your reverse proxy
caddy will be resolved to its IP address at startup and refreshed periodically. This is useful because Docker container IPs can change on restart.
With Static IPs:
environment:
BEHIND_PROXY: "true"
TRUSTED_PROXIES: "10.0.0.5"
With CIDR Ranges:
environment:
BEHIND_PROXY: "true"
TRUSTED_PROXIES: "192.168.0.0/16"
Mixed Format:
environment:
BEHIND_PROXY: "true"
TRUSTED_PROXIES: "caddy,192.168.1.0/24,reverse-proxy.local"
Debug Output: When the application starts, it logs resolved hostnames at startup:
INFO: Resolved TRUSTED_PROXIES hostname 'caddy' to ['10.0.0.5']
INFO: Allowed trusted proxies: ['caddy', '192.168.1.0/24']
INFO: Resolved trusted proxy IPs: ['10.0.0.5']
If a hostname cannot be resolved, a warning is logged but the application continues:
WARNING: Failed to resolve TRUSTED_PROXIES hostname 'nonexistent': [Errno -3] Temporary failure in name resolution
Uvicorn forwarded headers: with BEHIND_PROXY=true the container entrypoint also translates TRUSTED_PROXIES into uvicorn's FORWARDED_ALLOW_IPS, which is what makes request.client and the uvicorn access log (visible in docker logs) show the real client address instead of the proxy. Hostnames are resolved once at container start for this list, so a proxy that changes IP afterwards is only picked up on the next Endurain restart — the application's own client IP detection (rate limiting, sessions, audit logs) keeps working because it re-resolves hostnames every minute. With BEHIND_PROXY=true, the container refuses to start (exit status 1, with an error in the log) when TRUSTED_PROXIES is unset or has no usable entry, such as a list holding only a hostname that does not resolve. Setting FORWARDED_ALLOW_IPS explicitly in the container environment overrides this translation.
Abuse and DDoS protection: Endurain rate limits requests per user (or per client IP when unauthenticated, an IPv6 address by its /64) and caps upload sizes, but it does not absorb volumetric floods. Run it behind a reverse proxy or CDN that limits connections and request rates per client, caps request body size, and sets header and body timeouts so slow clients cannot hold connections open. Keep RATE_LIMIT_ENABLED at true and set TRUSTED_PROXIES correctly: a wrong value lets clients spoof their IP to evade limits, or puts every client in the proxy's single bucket.
Table below shows the obligatory environment variables for postgres container. You should set them based on what was also set for the Endurain container.
| Environemnt variable | Default value | Optional | Notes |
|---|---|---|---|
| POSTGRES_PASSWORD | changeme | No |
N/A |
| POSTGRES_DB | endurain | No |
N/A |
| POSTGRES_USER | endurain | No |
N/A |
| PGDATA | /var/lib/postgresql/data/pgdata | No |
N/A |
To check Python backend dependencies used, see backend/pyproject.toml (managed with uv).
Frontend dependencies:
- To check npm dependencies used, use npm file (package.json)
- Logo created on Canva
Response compression
Endurain gzip-compresses its responses (the API's JSON and the web app's files) for clients that send Accept-Encoding: gzip. There is nothing to configure. Endurain does not compress a response that already carries a Content-Encoding. A reverse proxy that compresses on its own will normally find the response already compressed and pass it through.
Session Timeout Configuration (Optional)
By default, a session ends 720 hours (30 days) after sign-in, and after 72 hours of inactivity. An unused session also ends after the refresh token lifetime (7 days by default). These defaults meet NIST SP 800-63B AAL1. For AAL2, or a shorter exposure on shared devices, shorten the absolute and idle timeouts. See Sessions in the server settings.
These settings are edited in Settings > Server settings > Access & security.
Docker Secrets Support
Endurain supports Docker secrets for securely managing sensitive environment variables. For the following environment variables, you can use _FILE variants that read the secret from a file instead of storing it directly in environment variables:
DB_PASSWORD→DB_PASSWORD_FILESECRET_KEY→SECRET_KEY_FILEFERNET_KEY→FERNET_KEY_FILEAUDIT_SIGNING_KEY→AUDIT_SIGNING_KEY_FILE
Using File-Based Secrets
Use file-based secrets to securely manage sensitive environment variables:
- Create a secrets directory with proper permissions:
mkdir -p secrets
chmod 700 secrets
- Create secret files with strong passwords:
# Use randomly generated passwords, not hardcoded ones
echo "$(openssl rand -base64 32)" > secrets/db_password.txt
echo "$(openssl rand -hex 32)" > secrets/secret_key.txt
echo "$(python3 -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())")" > secrets/fernet_key.txt
# Set secure file permissions
chmod 600 secrets/*.txt
chown $(id -u):$(id -g) secrets/*.txt
- Configure docker-compose.yml:
services:
endurain:
environment:
- DB_PASSWORD_FILE=/run/secrets/db_password
- SECRET_KEY_FILE=/run/secrets/secret_key
- FERNET_KEY_FILE=/run/secrets/fernet_key
secrets:
- db_password
- secret_key
- fernet_key
secrets:
db_password:
file: ./secrets/db_password.txt
secret_key:
file: ./secrets/secret_key.txt
fernet_key:
file: ./secrets/fernet_key.txt
Note: When using _FILE variants, the original environment variables (e.g., DB_PASSWORD) are not needed. The application will automatically read from the file specified by the _FILE environment variable. The file must be in /run/secrets, /var/run/secrets or /secrets, and at most 64 KB. A set variable takes precedence over its _FILE variant.
Audit trail
Endurain keeps an append-only record of security-relevant actions in the jasil_audit_log table:
- sign-ins, successful and refused, whether from a new device, sign-outs, lockouts, and refused session refreshes and API keys;
- password changes and reset requests, two-step verification, backup codes issued and used, API key changes, and sessions signed out by the user or an administrator;
- sign-in providers linked, refused or unlinked, and providers an administrator creates, changes or deletes;
- failed identity confirmations before a sensitive action, and requests refused for a missing permission;
- accounts created (by an administrator, by sign-up, by a sign-in provider or at first-run setup), sign-ups confirmed, accounts changed or approved by an administrator, and accounts deleted;
- your own profile, privacy and email address changes;
- server and mail settings, the login photo, and server logs cleared or downloaded;
- Strava and Garmin Connect accounts linked, unlinked, or disconnected because the service rejected their token, and the Strava client stored;
- data leaving or entering: profile exports and their downloads, profile imports, bulk activity imports and Strava gear imports;
- who can see your data: activity visibility changes, single or bulk, and followers accepted or removed.
Health entries, gear, goals, notifications, media, single activity uploads and deletes, and routine syncs are not recorded.
Each row says who acted, from which address, on what, and how it ended. Work that runs in the background names the system as the actor, with the id of the request that started it. A row never holds a password, token, code, key or email address: only ids, counts, reasons and the names of the fields that changed. A row is written in the same transaction as the change it describes, so a change is never saved without its row. Endurain has no screen for the trail; query the table directly.
Retention. The trail is kept for 90 days and this is not configurable. The database refuses to drop anything younger than 30 days. A maintenance job runs at startup and every 5 minutes. It creates the table's daily partitions a week ahead and drops those older than 90 days, a whole day at a time.
Tamper evidence. The same job seals the trail every 15 minutes into a hash chain of checkpoints (jasil_audit_checkpoints). Updating, deleting or truncating rows is refused by the database. To sign the checkpoints, generate a key pair and set AUDIT_SIGNING_KEY to the private key:
openssl genpkey -algorithm ed25519 -out audit_key.pem
openssl pkey -in audit_key.pem -outform DER | tail -c 32 | base64 # AUDIT_SIGNING_KEY
openssl pkey -in audit_key.pem -pubout -outform DER | tail -c 32 | base64 # public key, for verifying
Keep the public key for whoever verifies the trail, and the private key with your other secrets, not in the database.
AUDIT_EXTERNAL_SINK_URI adds a copy of every checkpoint outside the database. Use file:///absolute/directory on a mount the container can write but not rewrite (refused under the distributed profile, whose replicas share no disk), or s3://bucket/prefix on a separate bucket with Object Lock in compliance mode and a default retention period.
What the audit trail does not prevent
Endurain connects to PostgreSQL with one role, which owns the audit table. Anyone with that role or superuser access can disable the protection and rewrite rows. The signature and, above all, the external copy are what reveal it. Restoring a database backup also rolls the trail back to the backup.
Volumes
Docker image runs as a non-root user (appuser, UID and GID 1000 by default). For named Docker volumes, permissions are handled automatically. For host bind mounts, ensure target directories on the host are writable by the container's UID (default 1000). Use user: in docker-compose to run as a custom UID/GID, and ensure host bind mounts are writable by that user. It is recommended to configure the following volumes for data persistence:
| Volume | Notes |
|---|---|
${LOCAL_PATH:-/var/opt/endurain}/backend/logs:/app/backend/logs |
Log files for the backend |
${LOCAL_PATH:-/var/opt/endurain}/backend/data:/app/backend/data |
Necessary for image and activity files persistence on docker image update |
Image personalization
It is possible to personalize the login image in the login page. To do that, map the data/server_images directory for image persistence on container updates (with local storage; with object storage the image is kept there) and:
- Set the image in the server settings zone of the settings page
- A square image is expected. Default one uses 1000px vs 1000px
- Up to 5 MB. The settings page accepts PNG; the API also accepts JPEG and WebP
Map tile server
Administrators choose the map tiles in the server settings page, under the maps section: a preset, or a custom tile URL with its attribution. A custom URL must use https:// (http:// is accepted only for localhost and 127.0.0.1) and contain the {z}, {x} and {y} placeholders.
Two parts of Endurain request tiles, and they treat the URL and the API key differently:
- Maps in the browser use the tile URL as it is saved. The URL is part of the public server settings, which can be read without signing in, and the browser sends it to the tile provider. Anything written in the URL, including a key, is therefore visible to anyone who can reach the server.
- Map thumbnails are rendered by the backend. It uses the tile URL and, if set, the Tile server API key field. The key is stored encrypted and is never sent to the browser, not even to the settings page: the field stays empty after saving, and leaving it empty keeps the stored key.
How the backend sends the key for thumbnails:
| Tile URL | Key sent as |
|---|---|
stadiamaps.com |
Authorization: Stadia-Auth <key> header. Without a key, thumbnails are skipped. |
| Any other host | api_key=<key> query parameter, added to the tile URL. Thumbnails are skipped if the URL is not https://. |
Only Stadia Maps is sent the key in a header. For any other provider the parameter name is always api_key. Many providers document a different name for their key, for example key, apikey, apiKey, access_token or access-token, so a key entered in the field may not be accepted. For those providers, leave the Tile server API key field empty and write the key into the tile URL with the parameter name the provider documents, for example https://tiles.example.com/{z}/{x}/{y}.png?key=YOUR_KEY. Check your provider's documentation for the exact name.
Putting a key in the URL has a cost: the key is stored unencrypted in the server settings and is exposed as described above. Keys in a URL query string can also appear in the provider's access logs and in the logs of proxies between Endurain and the provider. Use a key that can only read tiles, if your provider offers one. Endurain does not write the tile URL to its own log when a thumbnail fails, only the error type.