Skip to main content

Security Best Practices

Secure your Borg UI installation with authentication, SSH key management, and encryption.

Authentication Methods

Borg UI supports two authentication modes: JWT-based authentication (default) and Reverse Proxy authentication (for SSO/enterprise setups).

JWT Authentication (Default)

How it works:
  • Users authenticate with username/password
  • JWT tokens are issued with configurable expiration (default: 24 hours)
  • Tokens use HS256 algorithm with secret key encryption
  • Passwords are hashed using bcrypt (salt rounds: 12)
Configuration:
Implementation details (from app/core/security.py:18-39):
First User Setup:
  • Default admin account is created automatically on first run
  • Username: admin
  • Password: admin123 (or set via INITIAL_ADMIN_PASSWORD environment variable)
  • Must change password on first login (enforced by must_change_password flag)
The default admin password admin123 is insecure. Change it immediately after first login or set INITIAL_ADMIN_PASSWORD before deployment.

Reverse Proxy Authentication

Use case: Integrate with existing SSO systems (Authelia, Authentik, Keycloak, etc.) Configuration:
How it works (from app/core/security.py:97-169):
  1. Borg UI trusts the X-Forwarded-User header from reverse proxy
  2. Users are auto-created on first access (no manual setup required)
  3. Alternative headers are checked: X-Remote-User, Remote-User, X-authentik-username, X-Forwarded-User
  4. If no header is present, defaults to admin user (for direct access)
Supported headers (checked in order):
  • Configured header (PROXY_AUTH_HEADER)
  • X-Remote-User
  • Remote-User
  • X-authentik-username
  • X-Forwarded-User
Nginx example:
Security critical: When using proxy auth, Borg UI must only be accessible through the reverse proxy. Bind to 127.0.0.1 or use firewall rules to prevent direct access.
Example with Authelia:

Secret Key Management

The SECRET_KEY is used for JWT signing and data encryption (SSH keys, repository passwords). Default behavior (from app/config.py:144-162):
  1. On first run, a cryptographically secure key is auto-generated
  2. Saved to /data/.secret_key with 0600 permissions
  3. Reused across container restarts (persisted in volume)

Manual Configuration

Option 1: Environment variable
Option 2: Docker secret
Secret key length: Minimum 32 characters recommended. The system validates length in production mode (app/config.py:183-187).

Key Rotation

Warning: Rotating the secret key will:
  • Invalidate all existing JWT tokens (users must re-login)
  • Make encrypted SSH keys unreadable (requires re-importing keys)
If you must rotate:
  1. Export all SSH keys before rotation
  2. Update SECRET_KEY environment variable
  3. Restart container
  4. Re-import SSH keys
  5. Notify users to re-login

SSH Key Security

Storage and Encryption

How SSH keys are stored (from documentation analysis):
  • Private keys are encrypted using Fernet symmetric encryption
  • Encryption key derived from SECRET_KEY (first 32 bytes)
  • Stored in SQLite database (/data/borg.db)
  • Decrypted only during backup/mount operations (temporary files)
Encryption implementation (app/core/security.py:283-327):

SSH Key Types

Recommended: ED25519 (modern, smaller, faster)
Alternative: RSA 4096 (maximum compatibility)

Deployment Security

Best practice: Use UI-based deployment
  1. Go to Remote MachinesDeploy Key to Server
  2. Enter password (used once for deployment)
  3. Password is not stored - only used to install public key
  4. Future connections use passwordless SSH key authentication
Manual deployment with restrictions:
Add command restriction:
Benefits:
  • Prevents shell access with the backup key
  • Restricts borg operations to specific repository path
  • Mitigates damage if key is compromised

Repository Encryption

Borg repositories should always use encryption to protect backup data.

Encryption Modes

Recommended: repokey-blake2 (fastest, most secure)
Alternative: keyfile-blake2 (key stored separately)
For non-sensitive data: none
Always use encryption for production data. Unencrypted repositories expose all backup contents to anyone with file access.

Passphrase Management

During repository creation:
  • Borg UI prompts for passphrase
  • Passphrase is encrypted before storage in database
  • Decrypted only during backup/restore operations
Passphrase security:
  • Minimum 20 characters recommended
  • Use password manager to generate strong passphrases
  • Store passphrase separately from repository backups
Keyfile storage: For keyfile mode, export and backup the key:
Store this file separately from your backups (e.g., password manager).

Network Security

Binding and Firewall

Internal network only:
Access via reverse proxy:
Firewall rules (if exposing directly):

HTTPS/TLS

Use reverse proxy for TLS termination:
Borg UI does not include built-in TLS. Always use a reverse proxy (Nginx, Caddy, Traefik) for HTTPS.

User Management

Creating Users

Via Web Interface:
  1. Login as admin
  2. Go to SettingsUsers
  3. Click Add User
  4. Set username, password, email
  5. Assign admin privileges if needed
Password requirements:
  • Minimum 8 characters (enforced client-side)
  • Passwords are bcrypt-hashed before storage
  • Salt rounds: 12 (from app/core/security.py:21-27)

Admin Privileges

Admin users can:
  • Create/delete users
  • Modify system settings
  • Access all repositories
  • View system logs
  • Manage SSH connections
Regular users can:
  • Create their own repositories
  • Run backups on owned repositories
  • Browse and restore from owned repositories
  • Manage their own schedules
Admin accounts have full system access. Limit admin privileges to trusted users only.

User Deactivation

Disable user instead of deleting:
  1. Settings → Users → Edit User
  2. Uncheck “Active”
  3. Save
Effect:
  • User cannot login
  • Existing sessions are invalidated
  • User data (repositories, schedules) is preserved
  • Can be reactivated later

Security Hardening

Docker Security

Run as non-root user:
Read-only root filesystem (advanced):
Drop unnecessary capabilities:

File Permissions

Secure data directory:
SSH key permissions:

Database Security

Backup database regularly:
Database contains encrypted SSH keys and repository passphrases. Store backups securely and encrypt them.

Audit and Logging

Security Event Logging

Logged security events:
  • User authentication attempts (success/failure)
  • User creation/deletion
  • SSH key generation/deployment
  • Repository access
  • System setting changes
View logs:
Log level configuration:

Failed Login Monitoring

Watch for authentication failures:
Consider implementing fail2ban for automated IP blocking after multiple failures.

Security Checklist

Authentication:
  • Changed default admin password
  • Created individual user accounts (no shared credentials)
  • Disabled unused admin accounts
  • Configured SECRET_KEY (auto-generated or custom)
SSH Keys:
  • Generated ED25519 system key
  • Deployed keys with borg serve --restrict-to-path restrictions
  • Verified SSH key permissions (600 for private, 644 for public)
  • Documented key locations and backup procedures
Repositories:
  • Enabled encryption (repokey-blake2 or keyfile-blake2)
  • Set strong passphrases (20+ characters)
  • Backed up keyfiles separately
  • Tested repository recovery procedure
Network:
  • Configured HTTPS via reverse proxy
  • Bound to localhost or restricted network
  • Configured firewall rules
  • Tested access from expected networks only
System:
  • Running as non-root user (PUID/PGID configured)
  • Data directory permissions secured (700)
  • Database backups scheduled
  • Log monitoring configured
  • Updated to latest version

SSH Keys Guide

Detailed SSH key setup and management

Configuration

Environment variables and system settings

Troubleshooting

Common security-related issues and solutions

Maintenance

Database backups and system maintenance