r/kubernetes • u/mlbiam • 4h ago
Passwordless PostgreSQL on Kubernetes with CloudNativePG and workload identity
I put together a demo of PostgreSQL as a Service where applications authenticate using their Kubernetes identity instead of a database password.
CloudNativePG manages the databases. OpenUnison validates the application’s ServiceAccount token through Kubernetes’ TokenReview API and exchanges it for a short-lived JWT. A sidecar handles refresh, and PostgreSQL 18 uses Percona’s OAuth validator to validate the JWT and map its identity to a database role.
This removes the application database password and its distribution/rotation process. You still manage database roles, permissions, and issuer trust.
A couple of caveats: the demo uses an unmerged JDBC OAuth PR, and TokenReview checks the Pod binding at exchange time. Issued JWTs remain valid until expiration, and expiration doesn’t terminate existing database connections.
Full walkthrough and demo code: PostgreSQL as a Service, Without Passwords
Disclosure: I’m with Tremolo Security, the company behind OpenUnison.