postgres_secrets - Load Postgres credentials securely
postgres_secrets allows you to load credentials from a file in standard ways that
are compatible with the Postgres tooling ecosystem.
Currently, only the pgpass
format is supported. Support for connection service files
may be implemented in the future.
Use cases
- Command line tools.
postgres_secretsuses the same pgpass format aspsql. This gives command-line users a seamless experience betweenpsqland tools written withpostgres_secrets. - In container environments.
postgres_secretsmakes it easy to pass credentials to a container using tools like Docker secrets.
Key features
Simple, ergonomic API
- The API uses well-known Rust design patterns, and integrates with the
postgrescrate - This is all it takes to connect to a database:
let pgpass = load?; // Looks for the pgpass file in it's default location
let creds = pgpass.query
.hostname?
.find?
.unwrap;
let config: Config = creds.into;
let db = config.connect?;
Rock solid and well tested
- The test suite includes property tests, meaning the library has been tested against many randomly-generated pathological inputs.
- While it's possible the library has bugs, you are unlikely to encounter them in normal usage.
Small, easily auditable codebase
- For those concerned about supply-chain attacks,
postgres_secretscan be audited in an afternoon. - All of it's dependencies are canonical, well-known crates.
- The license is public domain, making it easy to fork or vendor.
Caveats
- This does not behave precisely the same as the parser in
libpq. While unlikely, this could lead to bugs or confusing behavior in some circumstances. libpqis more permissive than this implementation.libpqwill tolerate invalid escape sequences and extra columns. Because this behavior could cause bugs and confusing behavior, this implementation returns errors in these circumstances.libpqhas special behavior whenlocalhostis supplied as the hostname. This library does not support this.libpqperforms a permissions check on the pgpass file, and will not open a file which is too permissive. This library does not perform this check.
Documentation
The documentation is hosted on docs.rs.