I've seen a demo using Kubernetes workload identity and short-lived tokens instead of database passwords. How does that setup work, and what should I consider before using it?
How does passwordless PostgreSQL authentication work on Kubernetes?
Answers
The demo has CloudNativePG manage PostgreSQL, while an identity service validates the application's Kubernetes ServiceAccount token through the TokenReview API. It exchanges that identity for a short-lived JWT, and a sidecar refreshes the token.
PostgreSQL 18 uses Percona's OAuth validator to check the JWT and map its identity to a database role. That gets the application database password out of the distribution and rotation process, but you still have to manage roles, permissions, and trust in the token issuer.
Reply to this answer
Check the driver story before building around it. The demo uses a JDBC OAuth change that is still an unmerged pull request, so don't assume your application's driver can use the same flow today.
Also test reconnection after a database restart and token refresh with your actual driver and connection pool. JWT expiration doesn't terminate connections that are already open.
Reply to this answer
Short-lived client certificates are another option worth comparing. If you already have certificate issuance and rotation in place, TLS client authentication could reuse that machinery and avoid adding a token exchange and validator.
The tradeoff depends on the network and your issuer rules. JWT identity validation doesn't require the network layer to carry client certificate identity, which can matter where TLS is terminated along the way. Certificate issuer compliance can also be a constraint across network boundaries.
_x47+brinlet.8:
For a direct PostgreSQL connection, there may not be an intermediate TLS termination point, so that particular advantage could matter less.
Reply to this answer
There's a middle ground too: use a secrets manager to issue short-lived database credentials. You still have credentials to deliver and refresh, but it avoids relying on the same JWT support in the database driver.
That's a different job from the identity exchange in the demo. Compare the authentication and operational pieces you need rather than assuming a secrets manager and an identity service are interchangeable.
Reply to this answer
Add your answer
Answers are reviewed before publication.
_h64!wiblet.3:
TokenReview checks the Pod binding when the exchange happens. An already issued JWT can remain usable until it expires.