Repository navigation
Description
Context
The Torrust Tracker handles these secrets:
- API tokens
- Database passwords
You can find those secrets in the configuration in these sections:
# Database secrets
[core.database]
driver = "mysql"
path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"
# API token
[http_api.access_tokens]
admin = "MyAccessToken"When the tracker starts, it prints to the console the current configuration used (after merging all sources with Figment)
To avoid exposing these secrets, the configuration includes methods to mask them.
During the app setup:
pub fn setup() -> (Configuration, AppContainer) {
#[cfg(not(test))]
check_seed();
let configuration = initialize_configuration();
if let Err(e) = configuration.validate() {
panic!("Configuration error: {e}");
}
initialize_global_services(&configuration);
tracing::info!("Configuration:\n{}", configuration.clone().mask_secrets().to_json());
let app_container = AppContainer::initialize(&configuration);
(configuration, app_container)
}The configuration is cloned and secrets are masked (mask_secrets). That function calls the other config section to mask all the secrets in the configuration.
pub fn mask_secrets(mut self) -> Self {
self.core.database.mask_secrets();
if let Some(ref mut api) = self.http_api {
api.mask_secrets();
}
self
}Problem
Even with that functionality, secrets may leak, as happened here:
In that case, they were exposed via tracing instrumentation.
Solution
I've been considering using the newtype pattern to create a custom type for "Secret" that implements Debug and Display traits without exposing the secrets.
It would be something like:
use std::fmt;
/// Secret wrapper around a `String`
#[derive(Clone, PartialEq, Eq)]
pub struct Secret(String);
impl Secret {
pub fn new(value: impl Into<String>) -> Self {
Secret(value.into())
}
/// Access the inner value (use with care!)
pub fn expose(&self) -> &str {
&self.0
}
/// Consume the secret and extract the value
pub fn into_inner(self) -> String {
self.0
}
}
impl fmt::Debug for Secret {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "\"***\"")
}
}
impl fmt::Display for Secret {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "***")
}
}But after a preliminary research with AI, there are some crates related to this topic:
secrecy: https://docs.rs/secrecy/0.10.3/secrecy/index.htmlzeroize: https://docs.rs/zeroize/latest/zeroize/index.htmlsecrets: https://crates.io/crates/secrets
I have only read a little bit but it seems:
secrecyprovided a wrapped type for secrets.zeroizemakes sure memory is cleaned after using the secrets.
Since secrecy also ensures secrets are securely wiped from memory when dropped, I would choose it. Another advantage is that you can clearly identify all secrets in the app.
Notes
For the database password we use a URL type.
[core.database]
driver = "mysql"
path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"That means the whole value is not a secret. It's only a substring (db_user_secret_password).
We could need to split that information into multiple configuration values to isolate the secret. In fact, that's something I would do anyway. I have always thought the configuration is too coupled to the underlying database drivers. Using an URL for the DB connection string might not be a common practice. However, if we split it we can end up having config values that only make sense for some DB drivers. For example:
SQLite:
[core.database]
path = "/var/lib/torrust/tracker/database/sqlite3.db"MySQL:
[core.database]
driver = "mysql"
path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"Proposal:
[core.database]
[core.database.sqlite]
path = "/var/lib/torrust/tracker/database/sqlite3.db"
[core.database.mysql]
user = "db_user"
password = "db_user_secret_password"
host = "mysql"
port = "3306"
database = "torrust_tracker"It could be implemented as a non-breaking change if we prioritise the old field "path".
cc @da2ce7
Activity
josecelano commentedon Jun 24, 2026
Alternatively we could consider the whole URL as a secret.
Should we use the URL because it normalizes the connection config value? or should we split it into its components?
I prefer to split it because:
In the tracker deployer we have already use the split version:
https://github.com/torrust/torrust-tracker-deployer/blob/main/src/application/command_handlers/create/config/tracker/tracker_core_section.rs
cc @da2ce7
josecelano commentedon Jul 15, 2026
Spec update (2026-07-15)
This issue has been incorporated into EPIC #1978 — Configuration Overhaul (schema v3.0.0) as subissue #7 of 9. The title has also been updated to reflect the broader scope.
New title: "Decompose database config and overhaul secrets with
secrecycrate"Spec:
docs/issues/open/1490-1978-decompose-database-config-and-overhaul-secrets.mdKey design decisions
Database config: Decomposed into an enum with driver-specific variants. No backward-compatibility fallback — clean break for config schema v3.0.0:
New TOML format:
The original description proposed keeping the old
pathfield as a fallback — this is dropped since v3.0.0 is a breaking change anyway.API tokens:
AccessTokenschanges fromHashMap<String, String>toHashMap<String, Secret<String>>.Ripple effect: ~35 files total (~25 for DB decomposition + ~10 for
AccessTokens). All changes are mechanical — the compiler catches everything.EPIC position: Depends on #1640 (subissue #3) since both touch
Core. Can run in parallel with #1415, #1453, #889 after #1640 is merged.docs(configuration): address Copilot PR review comments
docs(configuration): address Copilot PR review comments
Merge #1982: docs(configuration): add Configuration Overhaul EPIC spe…
fix(configuration): address Copilot PR review suggestions
docs(configuration): convert epic to folder type and add migration guide
josecelano commentedon Aug 21, 2026
Planning update: #2079 is now the prerequisite API-token secrecy refactor. It protects API tokens in v2 and v3 while retaining legacy database URLs and their existing masking. #1490 follows: it decomposes v3 database configuration and introduces
ConnectionInfo.password: Secret<String>for the new isolated password.\n\nFor implementation, the Git-tracked specification is the source of truth:docs/issues/open/1490-1978-decompose-database-configuration.md. The GitHub issue body is informational and may be stale.[-]Overhaul Secrets: consider using `secrecy` to handle secrets[/-][+]Decompose v3 database configuration[/+]Merge #2078: docs(issues): replan database secret handling (#1490)
Merge torrust#2084: feat(configuration): decompose v3 database config…
Merge #2094: docs(issues): specify optional v3 database configuration