Skip to content

Commit

Permalink
fix: 修复禁用时错误禁用到系统账号 #3767
Browse files Browse the repository at this point in the history
  • Loading branch information
yksitu committed Mar 29, 2024
1 parent 74b3806 commit 065fcd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions dbm-ui/backend/flow/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,9 @@ class TruncateDataTypeEnum(str, StructuredEnum):
# sqlserver的用户登录admin账号名称
MSSQL_ADMIN = SQLSERVER_ADMIN_USER

# sqlserver自定义系统账号列表
SQLSERVER_CUSTOM_SYS_USER = [MSSQL_EXPORTER, MSSQL_ADMIN, "sa"]

# tbinlogdumper连接kafka的global config的定义
TBINLOGDUMPER_KAFKA_GLOBAL_CONF = {
"sasl.mechanisms": "SCRAM-SHA-512",
Expand Down
12 changes: 9 additions & 3 deletions dbm-ui/backend/flow/utils/sqlserver/sqlserver_db_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
from backend.db_meta.models.storage_set_dtl import SqlserverClusterSyncMode
from backend.flow.consts import (
SQLSERVER_CUSTOM_SYS_DB,
SQLSERVER_CUSTOM_SYS_USER,
SqlserverBackupJobExecMode,
SqlserverLoginExecMode,
SqlserverSyncMode,
)
from backend.flow.utils.mysql.db_table_filter import DbTableFilter
from backend.flow.utils.mysql.get_mysql_sys_user import generate_mysql_tmp_user
from backend.flow.utils.sqlserver.payload_handler import PayloadHandler


def sqlserver_match_dbs(
Expand Down Expand Up @@ -263,12 +265,16 @@ def exec_instance_app_login(cluster_id, exec_type: SqlserverLoginExecMode) -> bo
instance_role__in=[InstanceRole.ORPHAN, InstanceRole.BACKEND_MASTER]
)

# 获取系统账号
sys_users = SQLSERVER_CUSTOM_SYS_USER
sys_users.append(PayloadHandler.get_sqlserver_drs_account(cluster.bk_cloud_id)["drs_user"])
sys_users_str = ",".join([f"'{i}'" for i in sys_users])

# 查询所有的业务账号名称
get_login_name_sql = f"""select a.name as login_name
from master.sys.sql_logins a left join sys.syslogins b
on a.name=b.name where principal_id>4 and a.name not in('{SQLSERVER_CUSTOM_SYS_DB}') and a.name not like '#%'
from master.sys.sql_logins a left join master.sys.syslogins b
on a.name=b.name where principal_id>4 and a.name not in({sys_users_str}) and a.name not like '#%'
"""

ret = DRSApi.sqlserver_rpc(
{
"bk_cloud_id": cluster.bk_cloud_id,
Expand Down

0 comments on commit 065fcd1

Please sign in to comment.