Secrets
How a value wrapped in Secret stays out of configuration reports, Debug output and logs.
ulo::Secret<T> wraps a value whose text must not appear in an error, a Debug print or a log line. Secret<T> implements Deserialize, and ulo-config turns on the serde feature of ulo for that. It has no Serialize.
use serde::Deserialize;
use ulo::Secret;
#[derive(Clone, Debug, Deserialize)]
pub struct Database {
pub url: Secret<DbUrl>,
pub pool_size: u32,
pub timeout_secs: u32,
}Debug prints Secret([redacted]). expose() returns the inner value for the one place that needs it.
What a report never prints
ConfigModule and every section read register each secret they hold, so the application's redaction replaces the value in every error, Debug print and log line that mentions it.
A type or value problem is rendered from the kind of the value found and never from the value, as in "expected an integer, found a string". This holds under #[serde(flatten)] and #[serde(untagged)] too. A leaf type's own Error::custom message is printed as that type wrote it, with one exception: under a secret's path only the path and kind are printed.
examples/33-config shows the exception. DbUrl quotes its input when it refuses it, as Url and IpAddr do, and the Secret around it keeps the quotation out of the report:
impl TryFrom<String> for DbUrl {
type Error = String;
fn try_from(text: String) -> Result<Self, String> {
if text.starts_with("postgres://") { Ok(DbUrl(text)) } else { Err(format!("`{text}` is not a postgres:// url")) }
}
}The test feeds it mysql://app:hunter2-sentinel@db/app and asserts that neither the sentinel nor mysql:// reaches the report.
Panic messages
Rust runs the process's panic hook on the panicking thread before ulo catches the panic. The default hook prints the raw message to stderr. A registered secret or a connection string's password in a panic message therefore reaches stderr unredacted, although every report ulo writes of that panic is redacted.
ulo::panic::install_redacting_hook() replaces the default hook with one that prints the message after the same redaction. Call it at the start of main, before anything can panic:
ulo::panic::install_redacting_hook();A panic carrying connecting to postgres://app:hunter2@db/main then prints connecting to postgres://[redacted]@db/main after panicked at <file>:<line>:<column>:. The hook replaces every registered secret of the process's applications with [redacted] and strips the userinfo of anything shaped like a URL. A panic before any secret is registered, such as one while a configuration loads outside collect_secrets, gets the userinfo strip alone.
The hook is the process's, so ulo never installs it. The hook it replaces is not called, and an application with a hook of its own, a crash reporter for instance, installs that one instead and ulo redacts nothing it prints. The redacting hook leaves the thread's name out of its output.
Limits
- Under
flattenoruntagged, serde hands the secret's inner type buffered content without its path. A message that inner type raises is checked afterwards against the text of every secret the section collected, and a message containing one is replaced byinvalid value. This covers a secret whose inner type read its input as a scalar before it failed. A secret whose inner type fails before reading any scalar has no text for a message to quote. - A secret shorter than four characters is registered, and the application's redaction replaces it. It is not matched against messages, because text that short is contained in most of them.
- Failure messages of sources go through the same pass. None of the shipped parsers quotes file content in its message.
DebugonConfigand its value tree prints no value.