mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
feat(db): present a Postgres client certificate from sslcert and sslkey in TREK_DB_URL
A Postgres server that authenticates clients by certificate could not be used: TREK read only sslmode and sslrootcert from TREK_DB_URL, so neither the connection pool nor pg_dump, pg_restore and psql ever offered a client certificate (discussion #3215). TREK_DB_URL now also takes libpq's sslcert and sslkey. Both must be given together and only with a verifying sslmode, and each file must be readable, or the boot refuses with the same kind of message as for sslrootcert. The pool gets them as its TLS cert and key, the tools as PGSSLCERT and PGSSLKEY. The Postgres wiki page shows the URL, how to mount the files with Compose or the chart's extraVolumes, and libpq's rule for the key file's permissions, which the backup tools enforce.
This commit is contained in:
@@ -63,7 +63,8 @@ export function resolvePgTool(tool: PgTool, binDir: string | undefined): string
|
||||
* read. An sslmode that asks for SSL verifies the server's certificate, as the
|
||||
* app's own pool does (`postgres-engine.ts`): against the URL's sslrootcert,
|
||||
* else the system's trusted CAs (`system`, which `run` accepts only from a
|
||||
* client that understands it).
|
||||
* client that understands it), and presents the URL's client certificate
|
||||
* (sslcert and sslkey) when it names one.
|
||||
*/
|
||||
export function pgConnectionEnv(url: string): Record<string, string> {
|
||||
const parsed = new URL(url);
|
||||
@@ -81,6 +82,10 @@ export function pgConnectionEnv(url: string): Record<string, string> {
|
||||
else if (sslmode) {
|
||||
env.PGSSLMODE = 'verify-full';
|
||||
env.PGSSLROOTCERT = parsed.searchParams.get('sslrootcert') ?? 'system';
|
||||
const clientCert = parsed.searchParams.get('sslcert');
|
||||
const clientKey = parsed.searchParams.get('sslkey');
|
||||
if (clientCert) env.PGSSLCERT = clientCert;
|
||||
if (clientKey) env.PGSSLKEY = clientKey;
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user