Skip to content

Commit

Permalink
feat: 新增_客户端权限克隆ip模糊匹配未匹配任何权限时bug处理_的功能 #6476
Browse files Browse the repository at this point in the history
  • Loading branch information
fanfanyangyang committed Aug 27, 2024
1 parent d749f44 commit 2bc61ba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
26 changes: 26 additions & 0 deletions dbm-services/mysql/db-priv/service/clone_client_priv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -173,13 +186,20 @@ 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 {
AddError(&errMsg, address, err)
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)
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions dbm-services/mysql/db-priv/service/query_priv.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,23 @@ 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)
if err != nil {
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中的账号与权限相结合
Expand Down

0 comments on commit 2bc61ba

Please sign in to comment.