Skip to content

Commit b0d0a0e

Browse files
committed
fix(mysql): 安装proxy增加dbha白名单 #7525
1 parent fb2db94 commit b0d0a0e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql_proxy/install_mysql_proxy.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ type InstallMySQLProxyComp struct {
4444
// payload param
4545
type InstallMySQLProxyParam struct {
4646
components.Medium
47-
ProxyConfigs json.RawMessage `json:"proxy_configs"`
48-
Host string `json:"host" validate:"required,ip"`
49-
Ports []int `json:"ports" validate:"required,gt=0,dive"`
47+
ProxyConfigs json.RawMessage `json:"proxy_configs"`
48+
Host string `json:"host" validate:"required,ip"`
49+
Ports []int `json:"ports" validate:"required,gt=0,dive"`
50+
DBHAAccountName string `json:"dbha_account" validate:"required"`
5051
}
5152

5253
// InitDirs 别名
@@ -373,6 +374,13 @@ func (i *InstallMySQLProxyComp) initOneProxyAdminAccount(port Port) (err error)
373374
logger.Error("add ProxyAdminAccount failed %s", err.Error())
374375
return err
375376
}
377+
378+
_, err = pc.Exec(fmt.Sprintf(`refresh_user('%s@%%', '+')`, i.Params.DBHAAccountName))
379+
if err != nil {
380+
logger.Error("add dbha account failed %s", err.Error())
381+
return err
382+
}
383+
376384
return nil
377385
}
378386

dbm-ui/backend/flow/utils/mysql/proxy_act_payload.py

+11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
from backend.components import DBConfigApi
1313
from backend.components.dbconfig.constants import FormatType, LevelName
14+
from backend.core.encrypt.constants import AsymmetricCipherConfigType
15+
from backend.core.encrypt.handlers import AsymmetricHandler
1416
from backend.db_package.models import Package
17+
from backend.db_proxy.constants import ExtensionType
18+
from backend.db_proxy.models import DBExtension
1519
from backend.flow.consts import ConfigTypeEnum, DBActuatorActionEnum, DBActuatorTypeEnum, MediumEnum, NameSpaceEnum
1620

1721
logger = logging.getLogger("flow")
@@ -22,6 +26,11 @@ class ProxyActPayload(object):
2226
定义proxy不同执行类型,拼接不同的payload参数,对应不同的dict结构体.
2327
"""
2428

29+
def __proxy_get_dbha_account_name(self, bk_cloud_id: int):
30+
bk_cloud_name = AsymmetricCipherConfigType.get_cipher_cloud_name(bk_cloud_id)
31+
dbha = DBExtension.get_latest_extension(bk_cloud_id=bk_cloud_id, extension_type=ExtensionType.DBHA)
32+
return AsymmetricHandler.decrypt(name=bk_cloud_name, content=dbha.details["user"])
33+
2534
@staticmethod
2635
def __get_proxy_account():
2736
"""
@@ -59,6 +68,7 @@ def get_install_proxy_payload(self, **kwargs) -> dict:
5968
"""
6069
拼接安装proxy的payload参数
6170
"""
71+
6272
proxy_pkg = Package.get_latest_package(version="latest", pkg_type=MediumEnum.MySQLProxy)
6373
return {
6474
"db_type": DBActuatorTypeEnum.Proxy.value,
@@ -71,6 +81,7 @@ def get_install_proxy_payload(self, **kwargs) -> dict:
7181
"pkg_md5": proxy_pkg.md5,
7282
"ports": self.ticket_data.get("proxy_ports", []),
7383
"proxy_configs": {"mysql-proxy": self.__get_proxy_config()},
84+
"dbha_account": self.__proxy_get_dbha_account_name(bk_cloud_id=kwargs["bk_cloud_id"]),
7485
},
7586
},
7687
}

0 commit comments

Comments
 (0)