greptimedb
greptimedb copied to clipboard
TLS support for database protocols
Both mysql and postgresql shares same port of plain-text connection and secure one. Unlike http or grpc transports, database protocols have their own tls handshake process. So we might not be able to utilize haproxy or cloud load balancer for tls termination. Tls support has to be implemented in database side. Task including:
- provide option to configure certs/key for mysql/postgresql
- load configured certs/key from file system
- start mysql/postgresql port with tls acceptor
- add session information about whether a connection is secure or not
We can provide options to restrict insecure connection access in future
@sunng87 Should TLS acceptor be added in following location? https://github.com/GreptimeTeam/greptimedb/blob/e823cde6ff7b1cbed33093306204e894c0523d01/src/servers/src/mysql/server.rs#L89 https://github.com/GreptimeTeam/greptimedb/blob/e823cde6ff7b1cbed33093306204e894c0523d01/src/servers/src/postgres/server.rs#L91
Yes, at least we need some configuration to enable TLS.
For postgres, using pgwire, TLS is already supported via this option, which is set to None
to disable. There is an example in pgwire to demo its usage.
For MySQL, I haven't got time investigate its library support for TLS, we probably need to work with upstream and upstream of upstream for the support.
When all protocol level supported finished, we need to add last-mile configuration to manage and load cert/key files.
For MySQL, looks like there is one issue about this. I will try to port https://github.com/jonhoo/msql-srv/issues/23 implementation to opensrv-mysql.
I made a PR to opensrv-mysql to support MySQL TLS https://github.com/datafuselabs/opensrv/pull/34