【问题标题】:"bq" command line tool throws CERTIFICATE_VERIFY_FAILED“bq”命令行工具抛出 CERTIFICATE_VERIFY_FAILED
【发布时间】:2018-10-17 07:48:00
【问题描述】:

更新 (2019-02-07):issue 现已修复,所以如果您仍然遇到此问题,请尝试 gcloud components update


在过去几个月的某个时间点,我的 bq 工具停止工作。即使是简单的事情也会显示此错误:

$ bq show
BigQuery error in show operation: Cannot contact server. Please try again.
Traceback: Traceback (most recent call last):
File "/opt/google-cloud-sdk/platform/bq/bigquery_client.py", line 685, in BuildApiClient
response_metadata, discovery_document = http.request(discovery_url)
File "/opt/google-cloud-sdk/platform/bq/third_party/oauth2client_4_0/transport.py", line 176, in new_request
redirections, connection_type)
File "/opt/google-cloud-sdk/platform/bq/third_party/oauth2client_4_0/transport.py", line 283, in request
connection_type=connection_type)
File "/opt/google-cloud-sdk/platform/bq/third_party/httplib2/__init__.py", line 1626, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/opt/google-cloud-sdk/platform/bq/third_party/httplib2/__init__.py", line 1368, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/opt/google-cloud-sdk/platform/bq/third_party/httplib2/__init__.py", line 1288, in _conn_request
conn.connect()
File "/opt/google-cloud-sdk/platform/bq/third_party/httplib2/__init__.py", line 1082, in connect
raise SSLHandshakeError(e)
SSLHandshakeError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)

我尝试了以下方法:

  • sudo gcloud components update(版本 221.0.0)。
  • sudo pacman -Syu(系统更新)获取最新的 SSL 证书集。这是 Arch Linux,几乎总是最前沿。
  • sudo gcloud components reinstall
  • 卸载 google-cloud-sdk,清除剩余的 /opt/google-cloud-sdk 并完全从 AUR 重新安装。
  • 添加--httplib2_debuglevel=3(有效值未记录,找到值3here)。这不会提供任何额外的输出。
  • 添加--ca_certificates_file=/etc/ca-certificates/extracted/tls-ca-bundle.pem--ca_certificates_file=/etc/ca-certificates/extracted/ca-bundle.trust.crt--ca_certificates_file=/etc/ssl/certs/ca-certificates.crt 之一,其中之一肯定是我系统上的根证书捆绑包。其中最后一个是 curl 使用的,它可以与 www.googleapis.com 通话。
  • 查看源代码发现/opt/google-cloud-sdk/platform/bq/third_party/httplib2/cacerts.txt 是默认使用的证书包。如果我用curl --cacert ... 试试这个,它仍然有效。
  • 在这个 shell 中设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量。正如预期的那样,这也没有什么不同。 SSL 错误发生在 bq 甚至有机会开始 OAuth 握手之前。
  • 添加--disable_ssl_validation。这“有效”,但显然不安全。

其他人看到这个,或者有如何调试/解决的想法?

【问题讨论】:

  • 我想知道这是否与 Python OpenSSL 本身有关。如果您尝试使用requests 与任何安全 URL 建立 SSL 连接,它是否有效?也许更新 pyopenssl 和 http2 也可能会改变一些东西。
  • 我今天遇到同样的错误,更新到 Ubuntu 18.10 后,暂时使用 --disable_ssl_validation 虽然不推荐
  • 可能与新的 Ubuntu 18.10 有关?因为我也安装了它。

标签: ssl google-bigquery ssl-certificate gcloud google-cloud-sdk


【解决方案1】:

我在使用 Arch Linux 时也遇到了完全相同的问题。

但是,当您在命令行上发出 bq 命令时,我很确定 /opt/google-cloud-sdk/platform/bq/third_party/httplib2/cacerts.txt 处的证书文件被使用,因为标志 --ca_certificates_file=/etc/ssl/certs/ca-certificates.crt 将被放置在应用程序引导过程中自动进入标志。在 Arch Linux 上,此文件是指向 /etc/ca-certificates/extracted/tls-ca-bundle.pem 的符号链接。

我已尝试将 curlopenssl s_client 与此 CA 捆绑包一起用于调用的 API URL,即

https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest

而且效果很好。

我的假设是,这不是证书丢失或过期的问题。我的pyopenssl 包的版本是18.0.0,所以我在这里是最新版本。但是,我认为这个问题是由 TLS 握手过程中不受支持的密码或算法引起的。

【讨论】:

  • 感谢您确认我没有疯。那么一定是与 Arch 相关的东西……不知何故。您是否也从 AUR 安装了 google-cloud-sdk
  • 没关系,我从官方 tarball 中尝试过,但它也失败了。我向 gcloud 提出了问题:issuetracker.google.com/issues/117948931
【解决方案2】:

public issue tracker 与您的行为相似。我建议starring it 不断更新它并提供您的方案。

如果您使用公司代理,请在评论 #8 中找到公司代理替换证书的情况,并且在评论 #16 中提供了解决方法

希望对你有帮助。

【讨论】:

猜你喜欢
  • 2012-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多