MariaDB SSL 配置 - 使用 Let's Encrypt 证书

MariaDB SSL 配置 - 使用 Let's Encrypt 证书

我无法强制 MariaDB 在 Debian 8 上使用我的 SSL 证书文件。

Apache2 在 /etc/letsencrypt/* 中的当前文件权限下运行良好,唯一在当前证书方面有问题的服务是 MariaDB。

我尝试对 /etc/letsencrypt/live/domain/*.pem 中的文件使用 ACL:

setfacl -m "u:mysql:r--" /etc/letsencrypt/live/domain/*.pem

它不起作用。以 mysql 用户身份运行 bash 后,我发现 mysql 用户无法访问 /etc/letsencrypt/live。因此,我在 live 和域目录上运行了 setfacl。

MariaDB 仍然无法访问这些证书。

因此... 将 .pem 文件复制到 /etc/mysql 并将其所有权更改为 mysql:mysql 后,它有点奏效了。现在我得到:

mysqld[4131]: 180211  0:27:54 [Warning] Failed to setup SSL
mysqld[4131]: 180211  0:27:54 [Warning] SSL error: Unable to get private key
mysqld[4131]: 180211  0:27:54 [Note] Server socket created on IP: 'x.x.x.x'.
mysqld[4131]: 180211  0:27:54 [Note] /usr/sbin/mysqld: ready for connections.

效果如下:

mysql --ssl -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 137
Server version: 10.0.32-MariaDB-0+deb8u1 (Debian)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW STATUS LIKE 'Ssl_cipher';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Ssl_cipher    |       |
+---------------+-------+
1 row in set (0.01 sec)

MariaDB [(none)]> 

我当前的 /etc/mysql/my.cnf 的 SSL 部分:

ssl-ca=/etc/mysql/chain.pem
ssl-cert=/etc/mysql/cert.pem
ssl-key=/etc/mysql/privkey.pem

我做错了什么?我要怎么做才能让 MariaDB 使用该 SSL?为什么其他服务在默认权限下完全没有问题?

答案1

根据此评论的建议:MariaDB SSL 配置 - 使用 Let's Encrypt 证书

我的密钥格式错误,我尝试使用 openssl 将此密钥转换为不同的格式。

openssl rsa -in ./privkey.pem -out ./privkeyrsa.pem

在调整权限(0400)和该文件的所有权(mysql:mysql)后,SSL 开始按预期工作。(当然,配置行指向正确的证书)

我仍然不知道 SSL 证书的权限是否应该保持原样,或者我是否应该更改它们,并潜在地修复 /etc/letsencrypt/live 无法被 mysql 访问而其他所有内容都无法访问的问题(即使 mysql 用户具有适当的 ACL)。

但如果它有效并且只有 mysql 可以访问这些文件,那么一切都应该没问题。

相关内容