Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix(redis): harden TLS tests and surface TLS config at startup

wizardchen4f2dca0b635c
diff --git a/.env.example b/.env.example
index b68398eae..b8aea97a7 100644
--- a/.env.example
+++ b/.env.example
@@ -229,6 +229,7 @@ REDIS_PREFIX=stream:
# 可选:用于证书校验与 SNI 的服务器名(当地址是 IP 时有用)
# REDIS_TLS_SERVER_NAME=
# 跳过服务器证书校验。不安全,仅用于开发或自签名证书环境,生产禁用。
+# 私有 CA 签发的证书目前无法通过自定义 CA 文件校验,只能临时使用 skip-verify(开发环境)。
# REDIS_TLS_INSECURE_SKIP_VERIFY=false
# 当使用本地存储时,文件保存的基础目录路径
diff --git a/internal/common/redis_tls_test.go b/internal/common/redis_tls_test.go
index 252405b81..123101224 100644
--- a/internal/common/redis_tls_test.go
+++ b/internal/common/redis_tls_test.go
@@ -5,8 +5,16 @@ import (
"testing"
)
+func resetRedisTLSEnv(t *testing.T) {
+ t.Helper()
+ t.Setenv("REDIS_USE_TLS", "")
+ t.Setenv("REDIS_TLS_SERVER_NAME", "")
+ t.Setenv("REDIS_TLS_INSECURE_SKIP_VERIFY", "")
+}
+
func TestRedisTLSConfig_DisabledByDefault(t *testing.T) {
- // REDIS_USE_TLS unset.
+ resetRedisTLSEnv(t)
+
if cfg := RedisTLSConfig(); cfg != nil {
t.Fatalf("expected nil tls.Config when REDIS_USE_TLS is unset, got %#v", cfg)
}
@@ -18,6 +26,7 @@ func TestRedisTLSConfig_DisabledByDefault(t *testing.T) {
}
func TestRedisTLSConfig_EnabledSecureByDefault(t *testing.T) {
+ resetRedisTLSEnv(t)
t.Setenv("REDIS_USE_TLS", "true")
cfg := RedisTLSConfig()
@@ -36,6 +45,7 @@ func TestRedisTLSConfig_EnabledSecureByDefault(t *testing.T) {
}
func TestRedisTLSConfig_Options(t *testing.T) {
+ resetRedisTLSEnv(t)
t.Setenv("REDIS_USE_TLS", "TRUE") // case-insensitive
t.Setenv("REDIS_TLS_SERVER_NAME", "redis.example.com")
t.Setenv("REDIS_TLS_INSECURE_SKIP_VERIFY", "true")
diff --git a/internal/runtime/startup.go b/internal/runtime/startup.go
index f9f3b3bd3..dc5da7471 100644
--- a/internal/runtime/startup.go
+++ b/internal/runtime/startup.go
@@ -89,6 +89,8 @@ var startupEnvVars = []envVarSpec{
// Cache / queue
{name: "REDIS_ADDR"},
{name: "REDIS_PASSWORD", sensitive: true},
+ {name: "REDIS_USE_TLS"},
+ {name: "REDIS_TLS_SERVER_NAME"},
// Object storage
{name: "STORAGE_TYPE"},
{name: "MINIO_ENDPOINT"},
@@ -137,6 +139,10 @@ func LogStartupEnv(ctx context.Context) {
"[startup-env] SYSTEM_AES_KEY is set but %d bytes long; AES-256 requires exactly 32 bytes — encryption is DISABLED",
len(k))
}
+ if strings.EqualFold(strings.TrimSpace(os.Getenv("REDIS_TLS_INSECURE_SKIP_VERIFY")), "true") {
+ logger.Warn(ctx,
+ "[startup-env] REDIS_TLS_INSECURE_SKIP_VERIFY=true — Redis TLS certificate verification is DISABLED; do not use in production")
+ }
}
func formatEnvValue(s envVarSpec, val string) string {