如何将 JKS 转换为 Docker 注册表 cert/key?

How to convert JKS into Docker Registry cert/key?

我正在尝试 set up a secure Docker Registry 在两个 VM 上(用于 HA)并且对设置 SSL 有疑问。根据文档中的 link,我需要一个包含两个文件的 certs 目录:

我获得了一个 Java JKS(密钥库),其中包含适用于这些 VM 的通配符 CA 证书。我能够像这样从密钥库中成功导出证书:

keytool -export -alias certalias -file registry.crt -keystore mycerts.jks

到目前为止一切顺利:我有 registry.crt。然而,一些相关的 questions/concerns 阻止我完成此设置:

这里真的是三个问题。你可能应该问不同的问题。我不知道你的第二个问题的答案,但会回答另外两个问题。


简单来说,在 SSL 上下文中,客户端使用证书中包含的 public 密钥启动安全连接。只有拥有相应(私钥)密钥的服务器才能应答并因此建立连接。 (还有很多事情要做。)

关于密钥库的简短说明是:帮自己一个忙,使用像 KeyStore Explorer. No affiliation, I just like the tool. Exporting the private key with keytool is not that simple. As far as I know you cannot export the private key directly. You can however export to PKCS12 and use other tools like OpenSSL from there:

这样的工具

keytool -importkeystore -srckeystore existing-store.jks -destkeystore new-store.p12 -deststoretype PKCS12

如果您只有一个自签名证书(签名者与主题相同),则无需担心中介。中间证书意味着由签署您的证书的 CA 签署的证书本身由另一个 CA 签署。

CA 0 (signed by CA 0) - well known certificate, self-signed
 \_ CA 1 (signed by CA 0) - intermediate certificate
     \_ Your Cert (signed by CA 1)

为了验证证书的完整性,客户必须知道整个链。通常只有最顶层的 CA 分布在浏览器和操作系统 (CA 0) 中,因此您需要发布证书 "in between"—中间人 (CA 1)。