Dovecot 無法讀取 TLS 憑證

Dovecot 無法讀取 TLS 憑證

在我的 CentOS 7 系統上,我嘗試執行需要 TLS 的 dovecot。為此,我在中創建了我的私鑰和證書

[root@homeserver /]# ls -lZ indernet/cert/homeserver.*
-r--r--r--. root certuser system_u:object_r:default_t:s0   indernet/cert/homeserver.crt
-r--r-----. root certuser system_u:object_r:default_t:s0   indernet/cert/homeserver.key
[root@homeserver /]#

為了使 dovecot 實際加載文件,我確保 /etc/dovecot/conf.d/10-ssl.conf 包含以下行:

ssl=required
ssl_key=</indernet/cert/homeserver.key
ssl_cert=</indernet/cert/homeserver.crt

有問題的部分:Dovecot 無法啟動,失敗並出現此錯誤

dovecot: doveconf: Fatal: Error in configuration file /etc/dovecot/conf.d/10-ssl.conf line 14: ssl_key: Can't open file /indernet/cert/homeserver.key: Permission denied

我嘗試修改憑證和金鑰的檔案權限(根據https://doc.dovecot.org/configuration_manual/dovecot_ssl_configuration/),甚至到 777 也沒有任何變化。有人建議我可能是 SELinux 阻止了訪問,我配置了 unconfined_u:object_r:default_t:s0 以及 system_u:object_r:default_t:s0,如上面所示。不用找了。

現在令人驚訝的部分:我很好奇並編輯了 /usr/lib/systemd/system/dovecot.service 以包含

ExecStart=/bin/strace /usr/sbin/dovecot

然後在 /var/log/messages 中我可以看到憑證和金鑰被存取和載入。鴿舍有效。但是當我再次刪除 strace 時,我遇到了同樣的問題。

這裡可能發生了什麼事?

答案1

無法讀取金鑰,因為 SELinux 拒絕存取它們。

為了解決這個問題,複製(使用cpmv -Z)SELinux 期望儲存 TLS 金鑰和憑證的目錄(即/etc/pki/tls及其子目錄)的金鑰。如果您使用cp或 ,新檔案將具有正確的 SELinux 上下文mv -Z。然後更新 Dovecot 設定中的檔案位置。

相關內容