在使用docker容器啟動netcore3.x的項目連接 mysql5.7 時遇到如下錯誤
An excepetion has been rasied that is likely due to a transient failure.
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> Interop+OpenSsl+SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
---> Interop+Crypto+OpenSslCryptographicException: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small
報錯信息大致如下。
這是由於在netcore 3.x的鏡像中,該版本的S配置要求 ssl 協議最小版本高於 mysqlserver 主機中的 ssl 版本
[system_default_sect] MinProtocol = TLSv1.2 //需要改成 TLSv1.0 CipherString = DEFAULT@SECLEVEL=2 //需要改成 DEFAULT@SECLEVEL=2
這樣你的ssl鏈接就可以成功了。
但是容器啟動后直接修改並不能直接生效。或許應當重啟某個服務,我現在還沒有查到。
我暫時把配置文件拷貝出來修改后,通過 docker compose 中配置 volume 來map到容器中,覆蓋原本的配置來解決。
version: '3.4' services: maomaochatrobot: build: context: . dockerfile: ./Dockerfile volumes: - ./openssl.cnf:/etc/ssl/openssl.cnf #修改后的cnf文件map到容器中
這樣就暫時解決了mysqlserver和netcore容器ssl版本不匹配的問題。
這應該不是一個很好的方法。權當拋磚引玉,希望有讀者分享更好的解決方法。