Database Management
How Wiretastix uses databases to store configuration and peer data.
Wiretastix relies on a relational database to persistently store all its configuration, user, group, peer, and rule data. This ensures that all settings and states are preserved across daemon restarts and provides a centralized source of truth for the system.
Supported Databases
Wiretastix supports the following database types:
- SQLite: A self-contained, high-reliability, embedded, full-featured, public-domain, SQL database engine. Tested up to 100 users and 300 concurrent peers with no issues, and should be enough for most deployments – there’s no external database server to install, configure, or maintain.
- PostgreSQL: A powerful, open-source object-relational database system known for its reliability, feature robustness, and performance. Suited to very large installations, or when you want the database on a separate host for operational reasons (dedicated backups, existing PostgreSQL infrastructure, etc.).
Database Schema
The database schema includes tables for:
- Configurations: Stores global system settings and default values.
- API Tokens: Manages authentication tokens for accessing the Wiretastix API.
- Users: Stores user information, including their ID, name, nickname, and active status.
- Groups: Defines groups that users can belong to, allowing for shared configurations and rules.
- Peers: Stores detailed information about each WireGuard peer, including their keys, assigned IP addresses, and associated user/group IDs.
- Rules: Stores network firewall rules to be applied via
nftables.
Migrations
Migrations are handled automatically by the daemon – you don’t need to know where the SQL migration files live or run anything yourself. Every time the daemon starts, it connects to the database and applies any pending schema migrations before doing anything else. If the schema is already up to date, this is a no-op. Point the daemon at an older-schema database and it brings it up to the latest schema on that same startup, with no operator action required.
Data Persistence
All changes made through the Wiretastix CLI or API are immediately persisted to the database. This means that even if the Wiretastix daemon crashes or is restarted, all your configurations and peer data will be restored to their last known state.
Database Configuration
The database connection details (type and DSN - Data Source Name) are specified in the wiretastix.yaml configuration file. It is crucial to configure these settings correctly to ensure Wiretastix can connect to and manage its database.