From 2bc61ba49b02be32a17da23181b2e63183b4f370 Mon Sep 17 00:00:00 2001 From: fanfanyangyang Date: Tue, 27 Aug 2024 12:38:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=5F=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E6=9D=83=E9=99=90=E5=85=8B=E9=9A=86ip=E6=A8=A1?= =?UTF-8?q?=E7=B3=8A=E5=8C=B9=E9=85=8D=E6=9C=AA=E5=8C=B9=E9=85=8D=E4=BB=BB?= =?UTF-8?q?=E4=BD=95=E6=9D=83=E9=99=90=E6=97=B6bug=E5=A4=84=E7=90=86=5F?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=20#6476?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db-priv/service/clone_client_priv.go | 26 +++++++++++++++++++ .../mysql/db-priv/service/query_priv.go | 10 +++++++ 2 files changed, 36 insertions(+) diff --git a/dbm-services/mysql/db-priv/service/clone_client_priv.go b/dbm-services/mysql/db-priv/service/clone_client_priv.go index ff2000dedf..4ef480e89f 100644 --- a/dbm-services/mysql/db-priv/service/clone_client_priv.go +++ b/dbm-services/mysql/db-priv/service/clone_client_priv.go @@ -122,7 +122,13 @@ func (m *CloneClientPrivPara) CloneClientPriv(jsonPara string, ticket string) ([ // 一个协程失败,其报错信息添加到errMsg.errs。主协程wg.Wait(),等待所有协程执行完成才会返回。 // 每个集群一个协程 + slog.Info("msg", "clusters", clusters) for _, item := range clusters { + if !strings.Contains(item.ImmuteDomain, "xiaog56db.hayleyxu.dba.db") { + continue + } else { + slog.Info("msg", "item.ImmuteDomain", item.ImmuteDomain) + } wg.Add(1) go func(item Cluster) { defer func() { @@ -143,6 +149,11 @@ func (m *CloneClientPrivPara) CloneClientPriv(jsonPara string, ticket string) ([ AddError(&errMsg, address, err) continue } + if len(matchHosts) == 0 { + slog.Info("no match user@host", "instance", address, + "source ip", m.SourceIp) + continue + } slog.Info("msg", "matchHosts", matchHosts) userGrants, err := GetRemotePrivilege(address, matchHosts, item.BkCloudId, machineTypeBackend, m.User, true) @@ -151,6 +162,8 @@ func (m *CloneClientPrivPara) CloneClientPriv(jsonPara string, ticket string) ([ continue } if len(userGrants) == 0 { + slog.Info("no match user@host", "instance", address, + "source ip", m.SourceIp, "user", m.User) continue } userGrants = ReplaceHostInMysqlGrants(userGrants, m.TargetIp) @@ -173,6 +186,11 @@ func (m *CloneClientPrivPara) CloneClientPriv(jsonPara string, ticket string) ([ AddError(&errMsg, address, err) continue } + if len(matchHosts) == 0 { + slog.Info("no match user@host", "instance", address, + "source ip", m.SourceIp) + continue + } userGrants, err := GetRemotePrivilege(address, matchHosts, item.BkCloudId, machineTypeSpider, m.User, true) if err != nil { @@ -180,6 +198,8 @@ func (m *CloneClientPrivPara) CloneClientPriv(jsonPara string, ticket string) ([ continue } if len(userGrants) == 0 { + slog.Info("no match user@host", "instance", address, + "source ip", m.SourceIp, "user", m.User) continue } userGrants = ReplaceHostInMysqlGrants(userGrants, m.TargetIp) @@ -204,12 +224,18 @@ func (m *CloneClientPrivPara) CloneClientPriv(jsonPara string, ticket string) ([ AddError(&errMsg, address, err) } slog.Info("msg", "matchHosts", matchHosts) + if len(matchHosts) == 0 { + slog.Info("no match user@host", "instance", address, + "source ip", m.SourceIp) + continue + } proxyGrants, err := GetProxyPrivilege(address, matchHosts, item.BkCloudId, m.User) if err != nil { slog.Error("msg", "GetProxyPrivilege", err) AddError(&errMsg, address, err) } if len(proxyGrants) == 0 { + slog.Info("no match user@host", "instance", address, "user", m.User) continue } proxyGrants = ReplaceHostInProxyGrants(proxyGrants, m.TargetIp) diff --git a/dbm-services/mysql/db-priv/service/query_priv.go b/dbm-services/mysql/db-priv/service/query_priv.go index d4b5f5f818..fd8fbf1475 100644 --- a/dbm-services/mysql/db-priv/service/query_priv.go +++ b/dbm-services/mysql/db-priv/service/query_priv.go @@ -211,6 +211,11 @@ func (m *GetPrivPara) GetPriv() ([]RelatedIp, []RelatedDomain2, int, []GrantInfo AddError(&errMsg, address, err) return } + if len(matchHosts) == 0 { + slog.Info("no match user@host", "instance", address, + "source ip", m.Ips, "users", m.Users) + return + } // 获取user@host的权限信息 userGrants, err = GetRemotePrivilege(address, matchHosts, instance.BkCloudId, machineType, users, true) @@ -218,6 +223,11 @@ func (m *GetPrivPara) GetPriv() ([]RelatedIp, []RelatedDomain2, int, []GrantInfo AddError(&errMsg, address, err) return } + if len(userGrants) == 0 { + slog.Info("no match user@host", "instance", address, + "source ip", matchHosts, "users", users) + return + } // 对权限语句做正则匹配,模糊匹配,过滤出匹配输入db的权限信息 dbpriv = SplitGrantSql(userGrants, m.Dbs, tendbhaMasterDomain) // mysql中的账号与权限相结合