pub struct FileSource { /* private fields */ }Expand description
A Source that retrieves secrets from the local filesystem.
Two construction modes are available:
-
FileSource::new()— resolves relative paths against the process’s current working directory at the timegetis called. Simple, but the result is non-deterministic if any code callsstd::env::set_current_dirconcurrently. -
FileSource::with_base(dir)— captures an absolute base directory at construction time and resolves all relative paths against it. The resolved path is stable regardless of later CWD changes. Absolute paths in the URN name are still used as-is.
The primary use case is loading keys and certificates, e.g.:
urn:secrets-rs:file:/etc/ssl/private/server.key // absolute — same in both modes
urn:secrets-rs:file:certs/ca.crt // relative — stable only with with_base§Security
Because the URN name is used as a filesystem path without further
validation, binding a FileSource secret with an attacker-controlled URN
is an arbitrary file-read vulnerability. Only bind URNs that come from
trusted configuration (static code, operator-supplied config files with
restricted write permissions, etc.). Never construct or accept
urn:secrets-rs:file:... URNs from untrusted input such as API requests,
user-supplied data, or deserialized network payloads.
with_base anchors relative resolution to a known
directory but does not prevent path-traversal sequences (../) in the
URN name from escaping that directory; the trusted-configuration requirement
still applies.
Implementations§
Source§impl FileSource
impl FileSource
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a FileSource that resolves relative paths against the
process’s current working directory at call time.
Sourcepub fn with_base(base: impl Into<PathBuf>) -> Self
pub fn with_base(base: impl Into<PathBuf>) -> Self
Creates a FileSource that resolves relative paths against base.
base is captured at construction time, so subsequent calls to
std::env::set_current_dir do not affect resolution. For stable
behaviour base should be an absolute path; if it is relative it is
stored as-is and still subject to CWD changes.
Absolute paths in the URN name are used as-is regardless of base.