【问题标题】:Self signed certificate in certificate chain issue using Azure CLI on Windows在 Windows 上使用 Azure CLI 的证书链问题中的自签名证书
【发布时间】:2021-12-01 01:52:03
【问题描述】:

我在配置我的 Windows 以使用 az 命令行工具时遇到了一些问题。我已经测试了多种配置。一个在本地安装的系统上,一个在基于 Windows 的 docker 容器上。我在两个系统上都遇到了同样的错误。

如果我发出以下命令:

  az login --tenant my-domain.org

我收到以下错误:

HTTPSConnectionPool(host='login.microsoftonline.com', port=443):最大重试次数超出了 url:/my-domain.org/.well-known/openid-configuration(由 SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:证书链中的自签名证书 (_ssl.c:1125)')))

容器有以下azopenssl版本:

PS C:\azp> az version
{
  "azure-cli": "2.28.0",
  "azure-cli-core": "2.28.0",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}
PS C:\azp> openssl version
OpenSSL 1.1.1k  25 Mar 2021

本地系统有以下azopenssl版本:

(base) PS C:\01_Dev\dockerdevimage> az version

{
  "azure-cli": "2.26.1",
  "azure-cli-core": "2.26.1",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}
(base) PS C:\01_Dev\dockerdevimage> openssl version

OpenSSL 1.1.1c  28 May 2019

我试图了解为什么会出现错误,因此我测试了与 openssl 的连接,如下所示:

PS C:\azp> openssl s_client -proxy 10.76.209.147:3128 -connect login.microsoftonline.com:443 -showcerts
CONNECTED(00000180)
Can't use SSL_get_servername
depth=2 DC = org, DC = my-domain, CN = PKI, CN = BB-CA-DD   <-- edited manually
verify error:num=19:self signed certificate in certificate chain
verify return:1

我还使用相同的代理服务器和 Linux 容器进行了测试,并且 az 命令按预期工作:


$ az version
{
  "azure-cli": "2.25.0",
  "azure-cli-core": "2.25.0",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}

$ openssl version                                                                             
OpenSSL 1.1.1f  31 Mar 2020

$ az login --tenant my-domain.org 
The default web browser has been opened at https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/oauth2/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.
You have logged in. Now let us find all the subscriptions to which you have access...
[
  {
    "cloudName": "AzureCloud",
...

在 Linux 容器上,openssl 命令返回以下输出:

$ openssl s_client -proxy 10.76.209.147:3128 -connect login.microsoftonline.com:443 -showcerts
Can't use SSL_get_servername
depth=2 DC = org, DC = my-domain, CN = PKI, CN = BB-CA-DD
verify return:1

我还基于this link使用以下命令导入了证书:

PS C:\azp> Import-Certificate -FilePath .\BB-CA-DD.crt -CertStoreLocation Cert:\LocalMachine\Root\

没有变化。我不确定如何继续。

这个问题可能与以下帖子和文章有关:

编辑:

我已将解决方案从此处移至答案块,以强调我的问题已解决。根据反应,我得出结论,它确实对其他人也有用。

【问题讨论】:

    标签: windows azure ssl openssl


    【解决方案1】:

    最后我能够解决如下问题:

    我找到了以下文档:

    Setting up certificates for Azure CLI on Azure Stack Development Kit

    基本思路是找到用于Azure CLI的python安装并更新相关证书文件。

    在我的例子中,Azure CLI 与 python 一起安装在以下位置:

    C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe

    使用建议的命令,返回如下:

    PS > & "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe" -c "import certifi; print(certifi.where())"
    C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\certifi\cacert.pem
    

    更新上述文件为我解决了az login 问题。 my-domain.org 提供的 python 安装之一包含正确配置的 cacert.pem 文件。

    【讨论】:

      猜你喜欢
      • 2019-12-11
      • 2018-11-16
      • 2021-02-20
      • 2020-02-19
      • 2014-02-06
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 2021-08-07
      相关资源
      最近更新 更多