在某个环境中运行 Liberty,在该环境中,您必须使用可由提供信任的认证中心签署的现有第三方证书。
开始之前
- 创建包含该证书的 server.crt 文件和包含专用密钥的 server.key 文件。
- 使用 openssl 命令和 Java keytool
命令以根据 server.crt 文件和 server.key 文件创建 trust.jks 文件和
key.jks 文件。
使用以下示例创建密钥库和信任库 JKS 文件:
- 按公用密钥密码标准 12 (PKCS12) 格式导出服务器 CA 证书和密钥。
openssl pkcs12 -export -in server.crt -inkey server.key -out key.p12 -name default -passout pass:mypassword
- 将服务器 PKCS12 文件导入至密钥库 key.jks 文件。
keytool -importkeystore -deststorepass mypassword -destkeypass mypassword -destkeystore key.jks -srckeystore key.p12 -srcstoretype PKCS12 -srcstorepass mypassword -alias default
- 将服务器 CA 证书导入至密钥库 trust.jks 文件。
keytool -importcert -keystore trust.jks -storepass mypassword -file server.crt -alias default -noprompt
- 确定是否已创建 SSL 配置。为此,通过运行以下命令来检查密钥是否已存在:
kubectl get secrets
如果 SSL
配置已存在,那么将显示以下密钥:
mb-keystore, mb-keystore-password, mb-truststore, mb-truststore-password
过程
- 如果未创建 SSL 配置,请完成以下步骤以自动使用第三方证书启用 SSL:
- 创建以下 Kubernetes 密钥。此示例使用 Liberty
securityUtility encode 命令以通过 XOR 加密对密钥库和信任库密码进行编码。
kubectl create secret generic mb-keystore --from-file=./key.jks
kubectl create secret generic mb-truststore --from-file=./trust.jks
kubectl create secret generic mb-keystore-password --from-literal=password="{xor}Ej4xPjg6MjoxKw =="
kubectl create secret generic mb-truststore-password --from-literal=password="{xor}Ej4xPjg6MjoxKw=="
- 部署 Liberty Helm 图表时,设置以下值:
- ssl.enabled=true
- 此选项告知 Helm 图表将使用安全协议 HTTPS。
- ssl.useClusterSSLConfiguration=true
- 此选项告知 Helm 图表安装所创建证书,该证书用于密钥库和信任库。
- ssl.createClusterSSLConfiguration=true
- 此选项告知 Helm 创建使用第三方证书和密码密钥的 Liberty 配置。设置为 true 时,此选项不会覆盖您刚创建的证书和密钥。
- service.port=secure_port_number
- 缺省安全端口为 9443。
- service.targetPort=secure_port_number
- 缺省安全端口为 9443。
- ingress.secureBackends=true
- 如果已启用入口,请使用此选项以使入口可与安全 Liberty 应用程序通信。
- 如果已创建 SSL 配置,请完成以下步骤以自动启用 SSL:
- 删除先前创建的密钥。
kubectl delete secrets mb-keystore mb-keystore-password mb-truststore mb-truststore-password
- 创建以下 Kubernetes 密钥:
kubectl create secret generic mb-keystore --from-file=./key.jks
kubectl create secret generic mb-truststore --from-file=./trust.jks
kubectl create secret generic mb-keystore-password --from-literal=password="{xor}Ej4xPjg6MjoxKw=="
kubectl create secret generic mb-truststore-password --from-literal=password="{xor}Ej4xPjg6MjoxKw=="
- 部署 Liberty Helm 图表时,设置以下值:
- ssl.enabled=true
- 此选项告知 Helm 图表将使用安全协议 HTTPS。
- ssl.useClusterSSLConfiguration=true
- 此选项告知 Helm 图表安装所创建证书,该证书用于密钥库和信任库。
- ssl.createClusterSSLConfiguration=false
- 此选项告知 Helm 不创建使用第三方证书和密码密钥的 Liberty 配置。
- service.port=secure_port_number
- 缺省安全端口为 9443。
- service.targetPort=secure_port_number
- 缺省安全端口为 9443。
- ingress.secureBackends=true
- 如果已启用入口,请使用此选项以使入口可与安全 Liberty 应用程序通信。