From 6e4c9efbfc52874bae7bcb0c7b7385311382d035 Mon Sep 17 00:00:00 2001 From: fupeng29 Date: Tue, 7 Nov 2023 09:02:01 +0800 Subject: [PATCH] support specific accounts to access all databases Signed-off-by: fupeng29 --- config/user.json | 2 +- go/mysql/auth_server_config.go | 2 +- go/vt/vtgate/executor.go | 6 +++++- go/vt/vtgate/plugin_mysql_server.go | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config/user.json b/config/user.json index ed727ad87e3..28fba88b3c9 100644 --- a/config/user.json +++ b/config/user.json @@ -38,7 +38,7 @@ "MysqlNativePassword": "*E361D58BFE0A57E237D51CE49E8E395E65538AA9", "UserData": "", "KeySpaces": [ - {"Name":"customer", "WhiteIPs": []} + {"Name":"*", "WhiteIPs": []} ], "Privilege": 1, "ReadRole": 1 diff --git a/go/mysql/auth_server_config.go b/go/mysql/auth_server_config.go index f99f4cd5117..ec2edb28a44 100644 --- a/go/mysql/auth_server_config.go +++ b/go/mysql/auth_server_config.go @@ -70,7 +70,7 @@ func (asc *AuthServerConfig) ValidClient(user, keyspace, ip string) bool { return entry.KeySpaces[0].IPFilter.FilterIPString(ip) } for _, ks := range entry.KeySpaces { - if ks.Name == keyspace { + if ks.Name == keyspace || ks.Name == "*" { if len(ks.WhiteIPs) == 0 { return true } diff --git a/go/vt/vtgate/executor.go b/go/vt/vtgate/executor.go index 17319154cfa..577e1738731 100644 --- a/go/vt/vtgate/executor.go +++ b/go/vt/vtgate/executor.go @@ -1808,7 +1808,11 @@ func (e *Executor) handleShow(ctx context.Context, sql string) (*sqltypes.Result var destKeyspaces []string if len(userKeyspace) > 0 { - destKeyspaces = intersect(userKeyspace, allKeyspace) + if len(userKeyspace) == 1 && userKeyspace[0] == "*" { + destKeyspaces = allKeyspace + } else { + destKeyspaces = intersect(userKeyspace, allKeyspace) + } } else { destKeyspaces = allKeyspace } diff --git a/go/vt/vtgate/plugin_mysql_server.go b/go/vt/vtgate/plugin_mysql_server.go index 4ca83ab7670..9ada4aa6050 100644 --- a/go/vt/vtgate/plugin_mysql_server.go +++ b/go/vt/vtgate/plugin_mysql_server.go @@ -916,7 +916,7 @@ func (vh *vtgateHandler) ValidUseDB(c *mysql.Conn, usedb string, authServer mysq usedb = strings.Split(usedb, ":")[0] for _, usks := range userkss { - if strings.EqualFold(usks, usedb) { + if strings.EqualFold(usks, usedb) || usks == "*" { return nil } }