Security & backups
Encryption at rest
LibreDrive uses envelope encryption. Every file gets a random per-file Data Encryption Key (DEK); the file content is AES-256-GCM-encrypted under that DEK. The DEK itself is wrapped with the instance’s Key Encryption Key (KEK), which comes from LIBREDRIVE_ENCRYPTION_KEY. Only the small wrapped DEK is stored in Postgres — the KEK never touches disk, and LIBREDRIVE_ENCRYPTION_KEY is required to start the instance at all.
Generate a strong key before your first deployment:
openssl rand -base64 32Store this value somewhere safe outside the container — losing it makes existing files unrecoverable.
Rotating the encryption key
Rotation re-wraps every file’s DEK; it never re-encrypts file content, so it’s safe to run against a live instance with zero downtime.
-
Generate a new key (
openssl rand -base64 32) and set it asLIBREDRIVE_ENCRYPTION_KEY_NEW, alongside the existingLIBREDRIVE_ENCRYPTION_KEY, then restart the stack. -
Run the rotation:
Terminal window docker compose exec libredrive libredrive-cli rotate-key -
Once it reports
Rewrapped N file key(s)with nothing left to do, promote the new key: setLIBREDRIVE_ENCRYPTION_KEYto the value ofLIBREDRIVE_ENCRYPTION_KEY_NEW, removeLIBREDRIVE_ENCRYPTION_KEY_NEW, and restart.
Backups
Set LIBREDRIVE_BACKUP_TARGET to s3 or local, and LIBREDRIVE_BACKUP_SCHEDULE to a cron expression, to enable automatic backups on a schedule:
LIBREDRIVE_BACKUP_TARGET=s3LIBREDRIVE_BACKUP_S3_BUCKET=libredrive-backupsLIBREDRIVE_BACKUP_SCHEDULE=0 3 * * *A backup is a pg_dump of the database plus the local file store (when using the local storage driver), packed into one tar.gz. Scheduled and on-demand backups call the same backup service, so they can’t drift apart.
Manual backup
docker compose exec libredrive libredrive-cli backup --output /data/backups/manual-$(date +%F).tar.gzRestoring
docker compose exec libredrive libredrive-cli restore --input /data/backups/manual-2026-09-10.tar.gzAlways restore into a fresh instance with the same LIBREDRIVE_ENCRYPTION_KEY used to create the backup — restoring with a different key will leave files unreadable.
Network and access hardening
- Always run LibreDrive behind a reverse proxy with TLS in production (see installation) — the container only binds to
127.0.0.1:8080and does not terminate TLS itself. - Set a long, random
LIBREDRIVE_SECRET_KEY; never reuse it across environments. - Restrict direct access to the
dbcontainer — only thelibredriveservice should reach port 5432; the bundleddocker-compose.ymldoesn’t publish it externally by default. - Keep
LIBREDRIVE_ENCRYPTION_KEYand your.envfile out of version control and off any backup that isn’t itself encrypted.