diff --git a/dbm-ui/frontend/src/locales/zh-cn.json b/dbm-ui/frontend/src/locales/zh-cn.json index a312daaaae..c7cdcdfc9f 100644 --- a/dbm-ui/frontend/src/locales/zh-cn.json +++ b/dbm-ui/frontend/src/locales/zh-cn.json @@ -3674,5 +3674,7 @@ "默认协作人": "默认协作人", "冷/热节点": "冷/热节点", "冷_热节点规格": "冷_热节点规格", + "不允许使用特殊账号名称n": "不允许使用特殊账号名称 {n}", "这行勿动!新增翻译请在上一行添加!": "" + } diff --git a/dbm-ui/frontend/src/views/db-manage/common/permission/components/common/AccountCreate.vue b/dbm-ui/frontend/src/views/db-manage/common/permission/components/common/AccountCreate.vue index aaead0bff1..4f6ebf0ada 100644 --- a/dbm-ui/frontend/src/views/db-manage/common/permission/components/common/AccountCreate.vue +++ b/dbm-ui/frontend/src/views/db-manage/common/permission/components/common/AccountCreate.vue @@ -102,6 +102,10 @@ import PasswordInput from '@views/db-manage/common/password-input/Index.vue'; + import MongoConfig from '../mongo/config'; + import MysqlConfig from '../mysql/config'; + import SqlserverConfig from '../sqlserver/config'; + interface Props { accountType: AccountTypes; } @@ -135,12 +139,15 @@ const passwordRef = ref>(); const defaultUserPlaceholder = t('由_1_~_32_位字母_数字_下划线(_)_点(.)_减号(-)字符组成以字母或数字开头'); + let validValue = ''; + const userPlaceholder = computed(() => { if (props.accountType === AccountTypes.MONGODB) { return t('格式为:(库名).(名称)_如 admin.linda'); } return defaultUserPlaceholder; }); + const rules = computed(() => ({ user: [ { @@ -155,6 +162,20 @@ validator: (value: string) => /^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)$/g.test(value), } : {}, + { + trigger: 'change', + validator: (value: string) => { + const specialAccountMap = { + [AccountTypes.MYSQL]: MysqlConfig[AccountTypes.MYSQL].special_account, + [AccountTypes.TENDBCLUSTER]: MysqlConfig[AccountTypes.TENDBCLUSTER].special_account, + [AccountTypes.MONGODB]: MongoConfig.special_account, + [AccountTypes.SQLSERVER]: SqlserverConfig.special_account, + }; + validValue = props.accountType === AccountTypes.MONGODB ? value.split('.')[1] : value; + return !specialAccountMap[props.accountType].includes(validValue); + }, + message: () => t('不允许使用特殊账号名称n', { n: validValue }), + }, ], password: [ { diff --git a/dbm-ui/frontend/src/views/db-manage/common/permission/components/mongo/config.ts b/dbm-ui/frontend/src/views/db-manage/common/permission/components/mongo/config.ts index 743c8f5c16..70ca816caf 100644 --- a/dbm-ui/frontend/src/views/db-manage/common/permission/components/mongo/config.ts +++ b/dbm-ui/frontend/src/views/db-manage/common/permission/components/mongo/config.ts @@ -14,4 +14,5 @@ export default { 'dbOwner', 'root', ], + special_account: ['dba', 'apppdba', 'monitor', 'appmonitor'], }; diff --git a/dbm-ui/frontend/src/views/db-manage/common/permission/components/mysql/config.ts b/dbm-ui/frontend/src/views/db-manage/common/permission/components/mysql/config.ts index 8070a33ea7..ef484c91b1 100644 --- a/dbm-ui/frontend/src/views/db-manage/common/permission/components/mysql/config.ts +++ b/dbm-ui/frontend/src/views/db-manage/common/permission/components/mysql/config.ts @@ -1,5 +1,22 @@ import { AccountTypes } from '@common/const'; +const SPECIAL_ACCOUNT = [ + 'gcs_admin', + 'gcs_dba', + 'MONITOR', + 'GM', + 'ADMIN', + 'repl', + 'dba_bak_all_sel', + 'yw', + 'partition_yw', + 'spider', + 'mysql.session', + 'mysql.sys', + 'gcs_spider', + 'sync', +]; + export default { [AccountTypes.MYSQL]: { dbOperations: { @@ -21,6 +38,7 @@ export default { glob: ['file', 'reload', 'show databases', 'process', 'replication slave', 'replication client'], }, ddlSensitiveWords: ['trigger', 'event', 'create routine', 'alter routine', 'references', 'create temporary tables'], + special_account: SPECIAL_ACCOUNT, }, [AccountTypes.TENDBCLUSTER]: { dbOperations: { @@ -29,5 +47,6 @@ export default { glob: ['file', 'reload', 'process', 'show databases'], }, ddlSensitiveWords: [], + special_account: SPECIAL_ACCOUNT, }, }; diff --git a/dbm-ui/frontend/src/views/db-manage/common/permission/components/sqlserver/config.ts b/dbm-ui/frontend/src/views/db-manage/common/permission/components/sqlserver/config.ts index 7123991fe5..7ab1258392 100644 --- a/dbm-ui/frontend/src/views/db-manage/common/permission/components/sqlserver/config.ts +++ b/dbm-ui/frontend/src/views/db-manage/common/permission/components/sqlserver/config.ts @@ -1,4 +1,5 @@ export default { dml: ['db_datawriter', 'db_datareader'], owner: ['db_owner'], + special_account: ['mssql_exporter', 'dbm_admin', 'sa', 'sqlserver'], };