-
-
Notifications
You must be signed in to change notification settings - Fork 885
Encryption Key Rotation
TREK encrypts sensitive settings at rest using AES-256-GCM. The following values are stored encrypted in the database:
- Google Maps API key (per user)
- Mapbox access token (per user)
- OpenWeather API key (per user)
- Immich API key (per user)
- Synology Photos password, session ID, and device ID (per user)
- Per-user webhook URL and ntfy notification token (in
settingstable) - OIDC client secret (global, in
app_settings) - SMTP password (global, in
app_settings) - Admin webhook URL and admin ntfy token (global, in
app_settings) - MFA (TOTP) secrets for all users
- Photo passphrases for Synology shared-link photos (in
trek_photos)
The encryption derives a key from ENCRYPTION_KEY using SHA-256 (with a domain suffix per secret type), so the raw ENCRYPTION_KEY value is never stored in the database.
On startup, TREK resolves the encryption key in this order:
-
ENCRYPTION_KEYenvironment variable — explicit, always takes priority. When set, the value is also written to./data/.encryption_keyso it survives container restarts if the env var is later removed. -
./data/.encryption_keyfile — present on any install that has started at least once. -
./data/.jwt_secretfile — one-time fallback for older installs that pre-date the dedicated encryption key. The value is immediately persisted to./data/.encryption_keyso future JWT rotations cannot break decryption. -
Auto-generated — fresh install with none of the above. A random 32-byte hex key is generated and written to
./data/.encryption_key.
All encrypted settings (API keys, SMTP password, OIDC secret, MFA secrets, notification tokens, etc.) become unreadable — TREK cannot decrypt them. They must be re-entered manually after the key is restored or replaced. Unencrypted data (trips, places, users, etc.) is unaffected.
Your backup ZIP does not include the encryption key. Store the key separately from your backups — for example, in a password manager or a secrets manager. See Backups.
To find your current key: check the ENCRYPTION_KEY environment variable or read ./data/.encryption_key.
Use scripts/migrate-encryption.ts to re-encrypt all stored secrets without downtime or manual re-entry.
Docker:
docker exec -it trek node --import tsx scripts/migrate-encryption.tsHost (run from the server/ directory):
node --import tsx scripts/migrate-encryption.tsThe script:
- Prompts for the old and new encryption keys interactively (keys are never echoed to the terminal or written to shell history).
- Asks for confirmation before making any changes.
- Creates a timestamped backup of the database (e.g.
travel.db.backup-1713484800000) before modifying anything. - Re-encrypts all stored secrets across all tables:
-
app_settings:oidc_client_secret,smtp_pass,admin_webhook_url,admin_ntfy_token -
users(per user):maps_api_key,openweather_api_key,immich_api_key,synology_password,synology_sid,synology_did,mfa_secret -
settings(per user):webhook_url,ntfy_token,mapbox_access_token -
trip_album_links:passphrase -
trek_photos:passphrase
-
- Reports counts of migrated, already-migrated, skipped (empty), and errored values.
After a successful migration:
- Update
ENCRYPTION_KEYin your environment to the new value. - Restart TREK.
If any secrets could not be migrated, the script exits with a non-zero status and the original database backup is retained.
Old installs may have used ./data/.jwt_secret as the encryption source (before a dedicated ENCRYPTION_KEY was introduced). The key resolution chain above handles this automatically on startup — the JWT secret is read, immediately written to ./data/.encryption_key, and JWT rotation is then safe without breaking decryption.
- Home
- Quick Start
- Install: Docker
- Install: Docker Compose
- Install: Helm
- Install: Proxmox VE (LXC)
- Install: Unraid
- Install: Portainer
- Reverse Proxy
- Environment Variables
- Updating
- Login and Registration
- OIDC SSO
- Two-Factor Authentication
- Passkeys
- Password Reset
- User Settings
- General Settings
- Appearance Settings
- Map Settings
- Notifications
- Offline Mode and PWA
- Languages
- My Trips Dashboard
- Creating a Trip
- Trip Members and Sharing
- Trip Planner Overview
- Places and Search
- Day Plans and Notes
- Map Features
- Route Optimization
- Weather Forecasts
- Reservations and Bookings
- AI Booking Import
- Transport: Flights, Trains, Cars
- Accommodations
- Costs
- Currencies
- Packing Lists
- Packing Templates
- Todos and Tasks
- Documents and Files
- Tags and Categories
- Calendar Feeds
- Real-Time Collaboration
- Collab Chat
- Collab Notes
- Collab Polls
- What's Next Widget
- Public Share Links
- Invite Links