Skip to content

Commit

Permalink
fix(backend): 修复redis主从校验密码bug #5200
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud authored and zhangzhw8 committed Jun 27, 2024
1 parent a940500 commit bb5455b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions dbm-ui/backend/configuration/handlers/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ def get_random_password(cls, security_type: str = DBM_PASSWORD_SECURITY_NAME):
return random_password

@classmethod
def verify_password_strength(cls, password: str, echo: bool = False):
def verify_password_strength(
cls, password: str, echo: bool = False, security_type: str = DBM_PASSWORD_SECURITY_NAME
):
"""
校验密码强度
@param password: 密码(这里是不加盐的)
@param echo: 是否回显解密密码
@param security_type: 密码类型
"""
try:
plain_password = AsymmetricHandler.decrypt(
Expand All @@ -64,7 +67,7 @@ def verify_password_strength(cls, password: str, echo: bool = False):
# 密码需要用base64加密后传输
b64_plain_password = base64_encode(plain_password)
check_result = DBPrivManagerApi.check_password(
{"password": b64_plain_password, "security_rule_name": DBM_PASSWORD_SECURITY_NAME}
{"password": b64_plain_password, "security_rule_name": security_type}
)
if echo:
check_result.update(password=plain_password)
Expand Down
4 changes: 3 additions & 1 deletion dbm-ui/backend/ticket/builders/redis/redis_cluster_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def validate(self, attrs):

# proxy密码校验,如果是用户输入,则必须满足密码强度
if attrs.get("proxy_pwd"):
verify_result = DBPasswordHandler.verify_password_strength(attrs["proxy_pwd"], echo=True)
verify_result = DBPasswordHandler.verify_password_strength(
attrs["proxy_pwd"], echo=True, security_type=DBPrivSecurityType.REDIS_PASSWORD
)
attrs["proxy_pwd"] = verify_result["password"]
if not verify_result["is_strength"]:
raise serializers.ValidationError(_("密码强度不符合要求,请重新输入密码。"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class NodeRebalanceItemSerializer(serializers.Serializer):
cluster_shard_num = serializers.IntegerField(help_text=_("集群分片数"))
remote_shard_num = serializers.IntegerField(help_text=_("单机分片数"))
resource_spec = serializers.JSONField(help_text=_("规格要求"))
# 前端额外需要参数,用于详情展示
prev_cluster_spec_name = serializers.CharField(help_text=_("变更前的规格名"))
prev_machine_pair = serializers.CharField(help_text=_("变更前机器组数"))

infos = serializers.ListSerializer(help_text=_("集群扩缩容信息"), child=NodeRebalanceItemSerializer())
backup_source = serializers.ChoiceField(
Expand Down

0 comments on commit bb5455b

Please sign in to comment.