跳转到内容

证书管理

Nantian Gateway 的 gRPC 控制面可以使用 TLS 或双向 TLS 来保护控制面与数据面之间的 xDS 流。Helm Chart 提供两种证书生成策略:用于开发和测试的自签名证书,以及用于生产环境的 cert-manager 集成。

使用这些证书的 TLS 和 mTLS 配置见 TLS / mTLS

Chart 可以为 gRPC mTLS 生成所需的三份证书:CA 证书、控制面的服务器证书,以及每个数据面的客户端证书。生成在安装时执行一次,结果存储在 Kubernetes Secret 中。升级时,Chart 会复用已有的 Secret。

证书管理在 certs 键下配置:

certs:
generate: true
domain: ""
selfSigned:
caDurationDays: 365
serverDurationDays: 90
clientDurationDays: 90
certManager:
enabled: false
issuerRef:
name: ""
kind: ClusterIssuer
group: cert-manager.io
duration: 2160h
renewBefore: 360h
参数类型默认值说明
certs.generatebooltrue安装时生成自签名证书
certs.domainstring""gRPC 服务器证书 SAN 的命名空间作用域域名。留空时根据 release 名称和命名空间自动计算
certs.selfSigned.caDurationDaysint365自签名 CA 证书的有效天数
certs.selfSigned.serverDurationDaysint90自签名服务器证书的有效天数
certs.selfSigned.clientDurationDaysint90自签名客户端证书的有效天数
certs.certManager.enabledboolfalse使用 cert-manager 颁发证书,替代自签名生成
certs.certManager.issuerRef.namestring""cert-manager Issuer 或 ClusterIssuer 的名称
certs.certManager.issuerRef.kindstring"ClusterIssuer"cert-manager 颁发者的类型(IssuerClusterIssuer
certs.certManager.issuerRef.groupstring"cert-manager.io"cert-manager 颁发者的 API 组
certs.certManager.durationstring"2160h"请求的证书有效期(90 天)
certs.certManager.renewBeforestring"360h"到期前提前续期的时长(15 天)

设置 certs.generate: true 来创建自签名证书。此模式适用于开发、测试以及没有安装 cert-manager 的非生产环境。

certs:
generate: true
selfSigned:
caDurationDays: 365
serverDurationDays: 90
clientDurationDays: 90

Chart 会在 release 命名空间中创建三个 Secret:

  • nantian-gw-grpc-ca:CA 证书和密钥
  • nantian-gw-grpc-server-tls:gRPC 服务器证书和密钥
  • nantian-gw-grpc-client-tls:gRPC 客户端证书和密钥

服务器证书 SAN 字段的域名默认自动计算为 <release-name>.<namespace>.svc,除非你显式设置了 certs.domain。这确保数据面在连接到集群内部的 gRPC 服务时可以验证服务器身份。

启用证书生成后,还要在控制面配置中启用 gRPC TLS,证书才会被实际使用。TLS / mTLS 页面涵盖了这些设置。

对于已安装 cert-manager 的生产环境,使用 certs.certManager.enabled: true。这会将证书生命周期管理委托给 cert-manager,由它自动处理颁发、轮换和续期。

certs:
certManager:
enabled: true
issuerRef:
name: nantian-gw-ca-issuer
kind: ClusterIssuer
group: cert-manager.io
duration: 2160h
renewBefore: 360h

在安装或升级 Chart 之前,你必须先创建 Issuer。ClusterIssuer 适用于所有命名空间,而 Issuer 仅限于单个命名空间:

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: nantian-gw-ca-issuer
spec:
ca:
secretName: nantian-gw-root-ca

Chart 创建三个 Certificate 资源(CA、服务器、客户端),引用你的 Issuer。cert-manager 处理其余工作:生成密钥、向 Issuer 请求证书、存储到 Secret 中,并在到期前自动轮换。

模式使用场景轮换方式
certs.generate: false你自己提供 Secret,或不使用 gRPC TLS手动
certs.generate: true(默认,自签名)开发、测试、临时集群手动(重装或手动轮换)
certs.certManager.enabled: true已安装 cert-manager 的生产集群通过 cert-manager 自动轮换

当自签名生成和 cert-manager 都未启用时,Chart 期望你自己创建了三个 TLS Secret(nantian-gw-grpc-canantian-gw-grpc-server-tlsnantian-gw-grpc-client-tls)。这样你可以使用自己的 PKI 或工具完全控制证书生命周期。