"bq" 命令行工具抛出 CERTIFICATE_VERIFY_FAILED
"bq" command line tool throws CERTIFICATE_VERIFY_FAILED
更新(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
(未记录有效值,找到值 3
here)。这不会提供任何额外的输出。
- 添加
--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
。这"works"但显然不安全。
其他人看到这个,或者有想法如何debug/solve?
我在使用 Arch Linux 时也遇到了完全相同的问题。
但是,当您在命令行上发出 bq
命令时,我很确定 /opt/google-cloud-sdk/platform/bq/third_party/httplib2/cacerts.txt
处的证书文件 未 使用,因为标志 --ca_certificates_file=/etc/ssl/certs/ca-certificates.crt
将在应用程序 bootstrap 过程中自动放入标志中。在 Arch Linux 上,此文件是 /etc/ca-certificates/extracted/tls-ca-bundle.pem
.
的符号链接
我已经尝试将 curl
和 openssl s_client
与此 CA 捆绑包一起使用,以对抗被调用的 API URL,即
https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest
而且效果很好。
我的假设是,这不是证书丢失或过期的问题。我的 pyopenssl
包的版本是 18.0.0
,所以我这里是最新版本。但是,我认为这个问题是由于TLS握手过程中不支持的密码或算法引起的。
有一个 public issue tracker with a similar behavior that you're having. I suggest starring it 可以随时更新它并提供您的场景。
如果您支持公司代理,请发表评论 #8 there's a scenario which the corporate proxy replaces the certificate, and the workaround is provided on comment #16
希望对您有所帮助。
更新(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
(未记录有效值,找到值3
here)。这不会提供任何额外的输出。 - 添加
--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
。这"works"但显然不安全。
其他人看到这个,或者有想法如何debug/solve?
我在使用 Arch Linux 时也遇到了完全相同的问题。
但是,当您在命令行上发出 bq
命令时,我很确定 /opt/google-cloud-sdk/platform/bq/third_party/httplib2/cacerts.txt
处的证书文件 未 使用,因为标志 --ca_certificates_file=/etc/ssl/certs/ca-certificates.crt
将在应用程序 bootstrap 过程中自动放入标志中。在 Arch Linux 上,此文件是 /etc/ca-certificates/extracted/tls-ca-bundle.pem
.
我已经尝试将 curl
和 openssl s_client
与此 CA 捆绑包一起使用,以对抗被调用的 API URL,即
https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest
而且效果很好。
我的假设是,这不是证书丢失或过期的问题。我的 pyopenssl
包的版本是 18.0.0
,所以我这里是最新版本。但是,我认为这个问题是由于TLS握手过程中不支持的密码或算法引起的。
有一个 public issue tracker with a similar behavior that you're having. I suggest starring it 可以随时更新它并提供您的场景。
如果您支持公司代理,请发表评论 #8 there's a scenario which the corporate proxy replaces the certificate, and the workaround is provided on comment #16
希望对您有所帮助。