Skip to content

Commit 6cf3b2c

Browse files
author
Gregoire Salingue
committed
fix: allow postgresql to use sslmode
1 parent f5e53c6 commit 6cf3b2c

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

backend/lib/config.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,25 @@ const configure = () => {
6868
const envPostgresName = process.env.DB_POSTGRES_NAME || null;
6969
const envPostgresSslMode = process.env.DB_POSTGRES_SSL_MODE || null;
7070
if (envPostgresHost && envPostgresUser && envPostgresName) {
71-
// we have enough postgres creds to go with postgres
72-
logger.info("Using Postgres configuration");
73-
74-
// knex does not handle ssl enablement other than in the connectionString, so let's use it
75-
// this prevents the serivce from starting on databases with self signed certificates
76-
// cf https://knexjs.org/guide/#configuration-options
77-
port = process.env.DB_POSTGRES_PORT || 5432
78-
connectionString = `postgresql://${envPostgresUser}:${process.env.DB_POSTGRES_PASSWORD}@${port}/${envPostgresName}`
79-
if (envPostgresSslMode) {
80-
connectionString = connectionString + `?ssl=true&sslmode=${envPostgresSslMode}`
81-
}
82-
instance = {
83-
database: {
84-
connectionString: connectionString,
85-
engine: postgresEngine,
86-
host: envPostgresHost,
87-
port: port,
88-
user: envPostgresUser,
89-
password: process.env.DB_POSTGRES_PASSWORD,
90-
name: envPostgresName,
91-
ssl: envPostgresSslMode ? { rejectUnauthorized: false } : false
92-
},
93-
keys: getKeys(),
94-
};
95-
return;
96-
}
71+
// we have enough postgres creds to go with postgres
72+
logger.info("Using Postgres configuration");
73+
instance = {
74+
database: {
75+
engine: postgresEngine,
76+
host: envPostgresHost,
77+
port: port,
78+
user: envPostgresUser,
79+
password: process.env.DB_POSTGRES_PASSWORD,
80+
name: envPostgresName,
81+
ssl: envPostgresSslMode ? {
82+
sslmode: envPostgresSslMode,
83+
rejectUnauthorized: envPostgresSslMode === "verify-full" ? true : false,
84+
}: false
85+
},
86+
keys: getKeys(),
87+
};
88+
return;
89+
}
9790

9891
const envSqliteFile = process.env.DB_SQLITE_FILE || "/data/database.sqlite";
9992
logger.info(`Using Sqlite: ${envSqliteFile}`);

docs/src/setup/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ services:
163163
Custom Postgres schema is not supported, as such `public` will be used.
164164

165165
:::
166+
### Optional: PostgreSQL SSL
167+
168+
You can enable TLS for the PostgreSQL connection with this environment variable:
169+
- DB_POSTGRES_SSL_MODE: (default: not set, can accept verify and verify-full)
166170

167171
## Running on Raspberry PI / ARM devices
168172

0 commit comments

Comments
 (0)