Fix secret key inconsistency cross the RAGFlow servers (#14591)

### What problem does this PR solve?

A and B, two API servers and a REDIS server.
If A and REDIS restart, B will hold the obsolete secret key and will
lead to error.

TODO:
app.config['SECRET_KEY'] and app.secret_key still hold obsolete secret
key.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-05-07 10:10:02 +08:00
committed by GitHub
parent 15dcdd7b5b
commit 1d0519d025
6 changed files with 28 additions and 7 deletions

View File

@@ -17,6 +17,8 @@ import os
import json
import secrets
import logging
from datetime import date
from common.constants import RAG_FLOW_SERVICE_NAME
from common.file_utils import get_project_base_directory
from common.config_utils import get_base_config, decrypt_database_config
@@ -139,6 +141,24 @@ def get_svr_queue_name(priority: int) -> str:
def get_svr_queue_names():
return [get_svr_queue_name(priority) for priority in [1, 0]]
def init_secret_key():
secret_key = os.environ.get("RAGFLOW_SECRET_KEY")
if secret_key and len(secret_key) >= 32:
return secret_key
# Check if there's a configured secret key
configured_key = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("secret_key")
if configured_key and configured_key != str(date.today()) and len(configured_key) >= 32:
return configured_key
return None
def get_secret_key():
global SECRET_KEY
if SECRET_KEY is None:
return _get_or_create_secret_key()
return SECRET_KEY
def _get_or_create_secret_key():
# secret_key = os.environ.get("RAGFLOW_SECRET_KEY")
# if secret_key and len(secret_key) >= 32:
@@ -245,7 +265,7 @@ def init_settings():
HOST_PORT = get_base_config(RAG_FLOW_SERVICE_NAME, {}).get("http_port")
global SECRET_KEY
SECRET_KEY = _get_or_create_secret_key()
SECRET_KEY = init_secret_key()
# authentication