1.4. 通过入口对象保护路由
您可以通过直接通过入口对象管理证书来保护应用程序流量。这包括在 ingress 注解或使用默认证书中使用目标 CA 证书创建路由。
Ingress Controller 为通过入口对象管理的证书维护单向同步。不要手动将更改直接应用到生成的路由的 TLS 配置。在下一次更新或协调父入口对象时,任何手动修改都会被静默覆盖。当您运行 GitOps 管理的集群时,这尤其要注意。
1.4.1. 在 Ingress 注解中使用目标 CA 证书创建路由 复制链接链接已复制到粘贴板!
要使用自定义目标 CA 证书定义路由,请将 route.openshift.io/destination-ca-certificate-secret 注解应用到 Ingress 对象。此配置可确保 Ingress Controller 使用指定的 secret 来验证目标服务的身份。
先决条件
- 在 PEM 编码文件中有一个证书/密钥对,其中的证书对路由主机有效。
- 在 PEM 编码文件中有一个单独的 CA 证书来完成证书链。
- 在 PEM 编码文件中有一个单独的目标 CA 证书。
- 您有一个要公开的服务。
流程
输入以下命令为目标 CA 证书创建 secret:
$ oc create secret generic dest-ca-cert --from-file=tls.crt=<file_path>例如:
$ oc -n test-ns create secret generic dest-ca-cert --from-file=tls.crt=tls.crt输出示例
secret/dest-ca-cert created将
route.openshift.io/destination-ca-certificate-secret添加到 Ingress 注解中:apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: frontend annotations: route.openshift.io/termination: "reencrypt" route.openshift.io/destination-ca-certificate-secret: secret-ca-cert ...其中:
destination-ca-certificate-secret指定
route.openshift.io/destination-ca-certificate-secret注解。该注解引用 Kubernetes secret。Ingress Controller 将注解中引用的 secret 插入到生成的路由中。
输出示例
apiVersion: route.openshift.io/v1 kind: Route metadata: name: frontend annotations: route.openshift.io/termination: reencrypt route.openshift.io/destination-ca-certificate-secret: secret-ca-cert spec: ... tls: insecureEdgeTerminationPolicy: Redirect termination: reencrypt destinationCACertificate: | -----BEGIN CERTIFICATE----- [...] -----END CERTIFICATE----- ...