diff --git a/docker-compose.yaml b/docker-compose.yaml index 5cd98599b..59d4bc306 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -22,7 +22,7 @@ services: # MCP settings SERVER_IMAGE_HOST: http://YOUR_SERVE_IP:MCP_PORT/images/ # Auth & Security - SECRET_KEY: y5txe1mRmS_JpOrUzFzHEu-kIQn3lf7ll0AOv9DQh0s + SECRET_KEY: ${SECRET_KEY:?Set a unique SECRET_KEY in .env before starting SQLBot} # CORS settings BACKEND_CORS_ORIGINS: "http://localhost,http://localhost:5173,https://localhost,https://localhost:5173" # Logging diff --git a/installer/install.conf b/installer/install.conf index 42a58a7c6..0e15dff21 100644 --- a/installer/install.conf +++ b/installer/install.conf @@ -22,8 +22,8 @@ SQLBOT_DB_PASSWORD=Password123@pg # 其他配置 ## 普通用户默认密码 SQLBOT_DEFAULT_PWD=SQLBot@123456 -## SQLBot Secret Key -SQLBOT_SECRET_KEY=y5txe1mRmS_JpOrUzFzHEu-kIQn3lf7ll0AOv9DQh0s +## SQLBot Secret Key(留空时安装程序会生成并持久化随机密钥) +SQLBOT_SECRET_KEY= ## Cross-Origin Resource Sharing (CORS) 设置 SQLBOT_CORS_ORIGINS=http://localhost,http://localhost:5173,https://localhost,https://localhost:5173 ## 日志级别 DEBUG, INFO, WARNING, ERROR diff --git a/installer/install.sh b/installer/install.sh index 3f277c53a..707f27931 100644 --- a/installer/install.sh +++ b/installer/install.sh @@ -21,6 +21,47 @@ function log_content () { log "\t${1}" } +COMPROMISED_SECRET_KEY_SHA256='78682d15dcf21e49b462da00b3ab33355c095450e02e2b37ed601e08e1b799c5' + +function secret_key_fingerprint() { + printf '%s' "$1" | sha256sum | awk '{print $1}' +} + +function prepare_secret_key() { + local current_fingerprint='' + local secret_action='generated' + + if [[ -n "${SQLBOT_SECRET_KEY:-}" ]]; then + current_fingerprint=$(secret_key_fingerprint "${SQLBOT_SECRET_KEY}") + fi + + if [[ "${current_fingerprint}" == "${COMPROMISED_SECRET_KEY_SHA256}" ]]; then + secret_action='rotated' + SQLBOT_SECRET_KEY='' + fi + + if [[ -z "${SQLBOT_SECRET_KEY:-}" ]]; then + SQLBOT_SECRET_KEY=$( + LC_ALL=C tr -dc 'A-Za-z0-9_-'