You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform生成自签名证书后redli连Redis报未知权威签名错误排查

Redis自签名证书连接问题排查

背景与配置

在测试环境中,我使用Terraform生成自签名证书保障Redis容器连接安全,相关配置如下:

Terraform证书配置

resource "tls_private_key" "private_key" {
  algorithm = "RSA"
}

resource "tls_self_signed_cert" "signed_cert" {
  private_key_pem       = tls_private_key.private_key.private_key_pem
  ip_addresses          = ["0.0.0.0", "127.0.0.1"]
  validity_period_hours = 6
  early_renewal_hours   = 1

  subject {
    organization = "example"
  }

  allowed_uses = [
    "key_encipherment",
    "digital_signature",
    "server_auth",
    "client_auth",
    "cert_signing"
  ]
}

Dockerfile

FROM redis:alpine

RUN apk update && apk add ca-certificates && update-ca-certificates

COPY ./redis.conf /etc/redis.conf

COPY ./redis.crt /redis.crt

COPY ./redis.key /redis.key

CMD ["redis-server", "/etc/redis.conf"]

Redis配置文件(redis.conf)

requirepass "password"
port 0
tls-port 6379
tls-cert-file /redis.crt
tls-ca-cert-file /redis.crt
tls-key-file /redis.key

遇到的错误

尝试用redli连接时,首先遇到证书信任问题:

$ redli -a "password" --tls
... Dial x509: certificate signed by unknown authority

添加--skipverify跳过验证后,又出现新错误:

$ redli -a password --tls --skipverify
... Dial remote error: tls: certificate required

问题原因与解决方案

核心问题:Redis强制要求客户端提供证书

Redis默认的tls-auth-clients参数值为yes,这会强制客户端在TLS连接时提供合法证书。你配置了tls-ca-cert-file但未给redli提供客户端证书,所以即使跳过证书验证,Redis依然会拒绝连接。

解决步骤

1. 修改Redis配置,关闭客户端证书验证

修改redis.conf,添加tls-auth-clients no,或者直接删除tls-ca-cert-file /redis.crt(关闭客户端验证后该配置无意义):

requirepass "password"
port 0
tls-port 6379
tls-cert-file /redis.crt
tls-key-file /redis.key
tls-auth-clients no

2. 重新构建并启动Redis容器

3. 再次用redli连接

此时使用--skipverify即可正常连接:

redli -a password --tls --skipverify

可选方案:不跳过验证,信任自签名证书

如果你不想跳过证书验证,可以将生成的redis.crt指定给redli的信任CA:

redli -a password --tls --cacert ./redis.crt

小优化:调整Terraform证书用途

你的自签名证书allowed_uses中包含cert_signing,这是CA证书的用途,作为服务器证书可以去掉,不影响功能但更规范:

allowed_uses = [
  "key_encipherment",
  "digital_signature",
  "server_auth",
  "client_auth"
]

内容的提问来源于stack exchange,提问作者Nullndr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 13:55:17