Skip to content

Commit 1aba797

Browse files
Johno-ACSLivefhennig42
authored andcommitted
Include SSL Options for MySQL
1 parent 41d98d0 commit 1aba797

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

backend/db.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const generateDbConfig = () => {
2121
user: cfg.user,
2222
password: cfg.password,
2323
database: cfg.name,
24-
port: cfg.port,
24+
port: cfg.port,
25+
...(cfg.ssl ? { ssl: cfg.ssl } : {})
2526
},
2627
migrations: {
2728
tableName: "migrations",

backend/lib/config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ const configure = () => {
3131
}
3232
}
3333

34+
const toBool = v => /^(1|true|yes|on)$/i.test((v || '').trim());
35+
3436
const envMysqlHost = process.env.DB_MYSQL_HOST || null;
3537
const envMysqlUser = process.env.DB_MYSQL_USER || null;
3638
const envMysqlName = process.env.DB_MYSQL_NAME || null;
39+
const envMysqlSSL = toBool(process.env.DB_MYSQL_SSL);
40+
const envMysqlSSLRejectUnauthorized = process.env.DB_MYSQL_SSL_REJECT_UNAUTHORIZED === undefined ? true : toBool(process.env.DB_MYSQL_SSL_REJECT_UNAUTHORIZED);
41+
const envMysqlSSLVerifyIdentity = process.env.DB_MYSQL_SSL_VERIFY_IDENTITY === undefined ? true : toBool(process.env.DB_MYSQL_SSL_VERIFY_IDENTITY);
3742
if (envMysqlHost && envMysqlUser && envMysqlName) {
3843
// we have enough mysql creds to go with mysql
3944
logger.info("Using MySQL configuration");
@@ -44,7 +49,8 @@ const configure = () => {
4449
port: process.env.DB_MYSQL_PORT || 3306,
4550
user: envMysqlUser,
4651
password: process.env.DB_MYSQL_PASSWORD,
47-
name: envMysqlName,
52+
name: envMysqlName,
53+
ssl: envMysqlSSL ? { rejectUnauthorized: envMysqlSSLRejectUnauthorized, verifyIdentity: envMysqlSSLVerifyIdentity } : false,
4854
},
4955
keys: getKeys(),
5056
};

docs/src/setup/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ services:
7575
DB_MYSQL_USER: "npm"
7676
DB_MYSQL_PASSWORD: "npm"
7777
DB_MYSQL_NAME: "npm"
78+
# Optional SSL (see section below)
79+
# DB_MYSQL_SSL: 'true'
80+
# DB_MYSQL_SSL_REJECT_UNAUTHORIZED: 'true'
81+
# DB_MYSQL_SSL_VERIFY_IDENTITY: 'true'
7882
# Uncomment this if IPv6 is not enabled on your host
7983
# DISABLE_IPV6: 'true'
8084
volumes:
@@ -102,6 +106,16 @@ Please note, that `DB_MYSQL_*` environment variables will take precedent over `D
102106

103107
:::
104108

109+
### Optional: MySQL / MariaDB SSL
110+
111+
You can enable TLS for the MySQL/MariaDB connection with these environment variables:
112+
113+
- DB_MYSQL_SSL: Enable SSL when set to true. If unset or false, SSL disabled (previous default behaviour).
114+
- DB_MYSQL_SSL_REJECT_UNAUTHORIZED: (default: true) Validate the server certificate chain. Set to false to allow self‑signed/unknown CA.
115+
- DB_MYSQL_SSL_VERIFY_IDENTITY: (default: true) Performs host name / identity verification.
116+
117+
Enabling SSL using a self-signed cert (not recommended for production).
118+
105119
## Using Postgres database
106120

107121
Similar to the MySQL server setup:

0 commit comments

Comments
 (0)