【问题标题】:Bazel Remote Cache not working with certificates/TLSBazel 远程缓存不适用于证书/TLS
【发布时间】:2021-08-10 17:18:31
【问题描述】:

我正在 docker 内部从 https://github.com/buchgr/bazel-remote 运行 Bazel 远程缓存,通过运行以下命令来启动 http 和 grpc 服务器:

docker pull buchgr/bazel-remote-cache
docker run -u 1000:1000 -v /path/to/cache/dir:/data -p 9093:8080 -p 9094:9092 buchgr/bazel-remote-cache

到目前为止,我可以通过运行以下命令之一从客户端运行一些测试:

bazelisk test  --remote_cache=http://<SERVER_IP>:<SERVER_PORT> <TEST_TARGET>
bazelisk test  --remote_cache=grpc://<SERVER_IP>:<SERVER_PORT> <TEST_TARGET>

但是当我通过向服务器调用添加以下标志来让我的服务器在 TLS 上运行时:

-v /path/to/certificate_authority:/etc/bazel-remote/ca_cert
-v /path/to/server_cert:/etc/bazel-remote/server_cert
-v /path/to/server_key:/etc/bazel-remote/server_key
--tls_ca_file=/etc/bazel-remote/ca_cert
--tls_cert_file=/etc/bazel-remote/server_cert
--tls_key_file=/etc/bazel-remote/server_key

虽然我创建了一个根 CA 证书来签署我的 服务器 和 客户端 证书,但我无法访问我的服务器通过 https 或 grpcs。 https 出现以下错误:

avax.net.ssl.SSLHandshakeException: General OpenSslEngine problem


sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target


sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

grpcs 如下:

javax.net.ssl.SSLHandshakeException: General OpenSslEngine problem

java.security.cert.CertificateException: No subject alternative names present

ERROR: Failed to query remote execution capabilities: General OpenSslEngine problem

这个问题是否与根 CA 证书本身是自签名的事实有关,还是我在做其他愚蠢的事情?

我使用了以下链接中的相同命令:https://github.com/bazelbuild/bazel/blob/master/src/test/testdata/test_tls_certificate/README.md

【问题讨论】:

  • 你能添加你用来生成根CA和客户端+服务器密钥+证书的命令吗?另外,对问题的疯狂猜测:您的 tls_cert_file 仅具有叶证书,没有形成链所必需的中间证书。
  • 当然。我使用了与我将添加到帖子中的以下链接中相同的命令:github.com/bazelbuild/bazel/blob/master/src/test/testdata/…

标签: https grpc tls1.2 bazel


【解决方案1】:

对于 grpcs,您的问题是客户端使用的主机名与证书不匹配。当我连接到localhost(就像那些默认的方向一样)时,它可以工作:

bazel test --remote_cache=grpcs://localhost:9094 --tls_client_certificate=/path/to/client.crt --tls_client_key=/path/to/client.pem --tls_certificate=/path/to/ca.crt //...

但是如果我切换到127.0.0.1,它会像你看到的那样失败。如果您有主机名,更改 SERVER_CN 以匹配它应该可以工作。不过,IP 地址有点棘手,因为您必须使用主题替代名称将证书与 IP 联系起来。我知道的最直接的方法是使用以下行创建文件extensions.cnf:

subjectAltName=IP:<SERVER_IP>

然后在生成证书时将该文件与-extfile 一起使用。您只需在说明末尾添加此命令即可生成包含它的新证书:

openssl x509 -req -passin pass:1111 -days 358000 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt -extfile extensions.cnf

我认为 bazel 不支持带有 https 的客户端证书。您可以使用自定义信任库解决您遇到的问题,但我不知道如何通过客户端证书。使用该选项的代码的唯一部分看起来像是特定于 GRPC 的。但是文档并没有说清楚......

更多 x509 基础知识:CA 证书通常是自签名的,因为作为信任根的客户端并不关心它们是如何签名的。这些方向生成的服务器证书不是自签名的,这与 echo 语句相反。客户端验证他们从服务器接收的证书是否与他们尝试连接的实体匹配(例如,为 yourwebsite.com 颁发的证书不能被用来伪装成 google.com)。 CN 是一个可以将它们绑定在一起的字段,subjectAltName 是一个扩展,可用于将证书绑定到各种格式的多个实体。

【讨论】:

  • 非常感谢您@Brian 的回答。在这里发布此问题后,我还阅读了更多内容,您所说的一切都很有意义。我希望能够投票两次。再做一些测试,我可能会回来接受这个答案。
  • 我的问题已经解决了。谢谢你的时间。现在我使用主机名而不是 IP 地址运行以下命令:bazelisk test --remote_cache=grpc://&lt;SERVER_HOSTNAME&gt;:&lt;SERVER_PORT&gt; &lt;TEST_TARGET&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-16
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多