Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions integration/db/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func TestDatabaseAccess(t *testing.T) {
WithRootConfig(func(config *servicecfg.Config) {
config.PollingPeriod = 5 * time.Second
config.RotationConnectionInterval = 2 * time.Second
config.Proxy.MySQLServerVersion = "8.0.1"
}),
)
pack.WaitForLeaf(t)
Expand Down Expand Up @@ -461,6 +462,9 @@ func (p *DatabasePack) testMySQLRootCluster(t *testing.T) {
require.Equal(t, wantRootQueryCount, p.Root.mysql.QueryCount())
require.Equal(t, wantLeafQueryCount, p.Leaf.mysql.QueryCount())

// Check if default Proxy MYSQL Engine Version was overridden the proxy settings.
require.Equal(t, "8.0.1", client.GetServerVersion())

// Disconnect.
err = client.Close()
require.NoError(t, err)
Expand Down
2 changes: 2 additions & 0 deletions integration/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ func TestALPNSNIProxyDatabaseAccess(t *testing.T) {
require.NoError(t, err)
require.Equal(t, mysql.TestQueryResponse, result)

require.Equal(t, mysql.DefaultServerVersion, client.GetServerVersion())

// Disconnect.
err = client.Close()
require.NoError(t, err)
Expand Down
4 changes: 4 additions & 0 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,10 @@ func applyProxyConfig(fc *FileConfig, cfg *servicecfg.Config) error {
cfg.Proxy.UI = webclient.UIConfig(*fc.Proxy.UI)
}

if fc.Proxy.MySQLServerVersion != "" {
cfg.Proxy.MySQLServerVersion = fc.Proxy.MySQLServerVersion
}

// This is the legacy format. Continue to support it forever, but ideally
// users now use the list format below.
if fc.Proxy.KeyFile != "" || fc.Proxy.CertFile != "" {
Expand Down
3 changes: 3 additions & 0 deletions lib/config/fileconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,9 @@ type Proxy struct {
// client connections.
MySQLPublicAddr apiutils.Strings `yaml:"mysql_public_addr,omitempty"`

// MySQLServerVersion allow to overwrite proxy default mysql engine version reported by Teleport proxy.
MySQLServerVersion string `yaml:"mysql_server_version,omitempty"`

// PostgresAddr is Postgres proxy listen address.
PostgresAddr string `yaml:"postgres_listen_addr,omitempty"`
// PostgresPublicAddr is the hostport the proxy advertises for Postgres
Expand Down
17 changes: 9 additions & 8 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4133,14 +4133,15 @@ func (process *TeleportProcess) initProxyEndpoint(conn *Connector) error {

dbProxyServer, err := db.NewProxyServer(process.ExitContext(),
db.ProxyServerConfig{
AuthClient: conn.Client,
AccessPoint: accessPoint,
Authorizer: authorizer,
Tunnel: tsrv,
TLSConfig: tlsConfig,
Limiter: connLimiter,
IngressReporter: ingressReporter,
ConnectionMonitor: connMonitor,
AuthClient: conn.Client,
AccessPoint: accessPoint,
Authorizer: authorizer,
Tunnel: tsrv,
TLSConfig: tlsConfig,
Limiter: connLimiter,
IngressReporter: ingressReporter,
ConnectionMonitor: connMonitor,
MySQLServerVersion: process.Config.Proxy.MySQLServerVersion,
})
if err != nil {
return trace.Wrap(err)
Expand Down
3 changes: 3 additions & 0 deletions lib/service/servicecfg/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ type ProxyConfig struct {
// MySQLAddr is address of MySQL proxy.
MySQLAddr utils.NetAddr

// MySQLServerVersion allows to override the default MySQL Engine Version propagated by Teleport Proxy.
MySQLServerVersion string

// PostgresAddr is address of Postgres proxy.
PostgresAddr utils.NetAddr

Expand Down
18 changes: 12 additions & 6 deletions lib/srv/db/mysql/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type Proxy struct {
Limiter *limiter.Limiter
// IngressReporter reports new and active connections.
IngressReporter *ingress.Reporter
// ServerVersion allows to overwrite the default Proxy MySQL Engine Version. Note that for TLS Routing connection
// the dynamic service version propagation by ALPN extension will take precedes over Proxy ServerVersion.
ServerVersion string
}

// HandleConnection accepts connection from a MySQL client, authenticates
Expand All @@ -69,7 +72,7 @@ func (p *Proxy) HandleConnection(ctx context.Context, clientConn net.Conn) (err
// by peeking into the first few bytes. This is needed to be able to detect
// proxy protocol which otherwise would interfere with MySQL protocol.
conn := multiplexer.NewConn(clientConn)
mysqlServerVersion := getServerVersionFromCtx(ctx)
mysqlServerVersion := getServerVersionFromCtx(ctx, p.ServerVersion)

mysqlServer := p.makeServer(conn, mysqlServerVersion)
// If any error happens, make sure to send it back to the client, so it
Expand Down Expand Up @@ -140,9 +143,12 @@ func (p *Proxy) HandleConnection(ctx context.Context, clientConn net.Conn) (err

// getServerVersionFromCtx tries to extract MySQL server version from the passed context.
// The default version is returned if context doesn't have it.
func getServerVersionFromCtx(ctx context.Context) string {
// Set default server version.
mysqlServerVersion := serverVersion
func getServerVersionFromCtx(ctx context.Context, configEngineVersion string) string {
// Set default server version or use the Proxy MySQL Engine Version if it was provided.
mysqlServerVersion := DefaultServerVersion
if configEngineVersion != "" {
mysqlServerVersion = configEngineVersion
}

if mysqlVerCtx := ctx.Value(dbutils.ContextMySQLServerVersion); mysqlVerCtx != nil {
version, ok := mysqlVerCtx.(string)
Expand Down Expand Up @@ -275,9 +281,9 @@ func (p *Proxy) waitForOK(server *server.Conn, serviceConn net.Conn) error {
}

const (
// serverVersion is advertised to MySQL clients during handshake.
// DefaultServerVersion is advertised to MySQL clients during handshake.
//
// Some clients may refuse to work with older servers (e.g. MySQL
// Workbench requires > 5.5).
serverVersion = "8.0.0-Teleport"
DefaultServerVersion = "8.0.0-Teleport"
Comment thread
russjones marked this conversation as resolved.
)
3 changes: 3 additions & 0 deletions lib/srv/db/proxyserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ type ProxyServerConfig struct {
// ConnectionMonitor monitors and closes connections if session controls
// prevent the connections.
ConnectionMonitor ConnMonitor
// MySQLServerVersion allows to override the default MySQL Engine Version propagated by Teleport Proxy.
MySQLServerVersion string
}

// ShuffleFunc defines a function that shuffles a list of database servers.
Expand Down Expand Up @@ -402,6 +404,7 @@ func (s *ProxyServer) MySQLProxy() *mysql.Proxy {
Limiter: s.cfg.Limiter,
Log: s.log,
IngressReporter: s.cfg.IngressReporter,
ServerVersion: s.cfg.MySQLServerVersion,
}
}

Expand Down