fix(install): correct Redis URL auth for 1Panel root user
Password must use redis://:pass@ or redis://root:pass@ host; wizard adds redis_user field defaulting to root on 1Panel Docker installs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+16
-8
@@ -62,6 +62,7 @@ class InitDbRequest(BaseModel):
|
||||
redis_host: str = "127.0.0.1"
|
||||
redis_port: str = "6379"
|
||||
redis_db: str = "0"
|
||||
redis_user: str = ""
|
||||
redis_pass: str = ""
|
||||
api_port: str = "8600"
|
||||
timezone: str = "Asia/Shanghai"
|
||||
@@ -92,11 +93,17 @@ def _make_db_url(req: InitDbRequest | CreateAdminRequest) -> str:
|
||||
|
||||
|
||||
def _build_redis_url(req: InitDbRequest) -> str:
|
||||
url = "redis://"
|
||||
if req.redis_pass:
|
||||
url += f"{quote_plus(req.redis_pass)}@"
|
||||
url += f"{req.redis_host}:{req.redis_port}/{req.redis_db}"
|
||||
return url
|
||||
"""Build redis:// URL. Password-only auth must use redis://:pass@host (leading colon)."""
|
||||
user = (req.redis_user or "").strip()
|
||||
password = (req.redis_pass or "").strip()
|
||||
auth = ""
|
||||
if user and password:
|
||||
auth = f"{quote_plus(user)}:{quote_plus(password)}@"
|
||||
elif password:
|
||||
auth = f":{quote_plus(password)}@"
|
||||
elif user:
|
||||
auth = f"{quote_plus(user)}@"
|
||||
return f"redis://{auth}{req.redis_host}:{req.redis_port}/{req.redis_db}"
|
||||
|
||||
|
||||
def _read_1panel_hosts_file() -> dict[str, str]:
|
||||
@@ -236,10 +243,10 @@ def _mysql_connect_error_detail(host: str, port: int) -> str:
|
||||
def _redis_auth_error_detail() -> str:
|
||||
if os.environ.get("NEXUS_DOCKER_WRITE_ENV") == "1":
|
||||
return (
|
||||
"Redis 密码错误或用户被禁用(1Panel Redis 请在步骤 3 填写应用参数中的密码;"
|
||||
"无密码则留空)。主机应为 1Panel-redis-xxxx,不是 127.0.0.1。"
|
||||
"Redis 认证失败。1Panel Redis:用户名填 root,密码填应用参数中的随机密码;"
|
||||
"主机为 1Panel-redis-xxxx(不是 127.0.0.1)。无 ACL 的旧版 Redis 用户名可留空。"
|
||||
)
|
||||
return "Redis 密码错误或需要 AUTH;请核对 Redis 密码(无密码则留空)。"
|
||||
return "Redis 密码错误或需要 AUTH;请核对用户名/密码(无密码则留空)。"
|
||||
|
||||
|
||||
def _redis_connect_error_detail(host: str, port: int) -> str:
|
||||
@@ -344,6 +351,7 @@ def _docker_wizard_defaults() -> dict[str, str] | None:
|
||||
"redis_host": redis_host,
|
||||
"redis_port": "6379",
|
||||
"redis_db": "0",
|
||||
"redis_user": "root",
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user