Secrets from files
A key that ends in _file reads a secret, such as a password, from a separate file, so the secret is not written in nvs.toml.
Several settings have this form, such as password_file in [db.<name>] and oauth_client_secret_file in [mail.<name>] and [imap.<name>]. The configuration reference lists them all. The whole content of the file is the value. Novis removes one line break at the end and changes nothing else. Set either password or password_file. Setting both is the error E0608.
Novis reads the file when the server starts and each time the configuration is applied. nvs config dump prints <secret> and the name of the file, and never the value.
Novis decrypts nothing. Tools such as SOPS, Docker Compose, Kubernetes and Vault all produce a plain file, and password_file names that file. Decrypt the file before the server starts.
Good to know: the server does not start when another account can write to the secret file. It prints a warning when another account can read it. A password is used exactly as written. A space at its start or end is kept, and Novis prints the warning W1007.
Examples
The examples below run with this configuration file.
# The mail password is not written here. It is the content of the file `secrets/mail-password`.# A relative path starts in the directory of this file.[mail.relay]host = "smtp.example.com"from = "shop@example.com"user = "shop"password_file = "secrets/mail-password"A password kept in its own file
<?nvs// Shows a password that is read from its own file, so it is never written in `nvs.toml`.
// `Core\Config::get` returns the content of the file. The newline at the end is removed.// The result is a `?secret string`, so your program cannot print it.?secret string $password = Core\Config::get('mail.relay.password');
// This prints `true`. Compare a password or pass it on.echo $password == 'correct-horse-7' ? 'true' : 'false', "\n";
// `password_file` returns the path of the file, not the password.// This prints `secrets/mail-password`.echo Core\Config::get('mail.relay.password_file'), "\n";truesecrets/mail-passwordChangelog
| Version | Change |
|---|---|
0.0.6 | A [file_transfer.<name>] block names a server, and [capabilities.file_transfer] connect lists the blocks a program may open. An sftp block needs the server's host key in host_key or known_hosts_file. An ftp block allows only an anonymous sign-in, so a password is never sent unencrypted. |
