windows - 在 Windows 上使用 Azure CLI 颁发证书链中的自签名证书

标签 windows azure ssl openssl

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

如果我发出以下命令:

  az login --tenant my-domain.org

我收到以下错误:

HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /my-domain.org/.well-known/openid-configuration (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_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\

没有变化。我不知道如何继续。

也许这个问题与以下帖子和文章有关:

编辑:

我已将解决方案从此处移至答案 block ,以突出显示我的问题已解决。根据 react ,我得出结论,它确实对其他人也有用。

最佳答案

您可以使用以下方法

您的 azure CLI 正在此位置查找证书(如果使用 Windows)

默认证书颁发机构 bundle Windows C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\certifi\cacert.pem

下载 Azure 门户 (portal.azure.com) 的证书

将证书附加到上面的 cacert.pem 文件中 重新启动 powershell 后再次尝试 Az 登录。

或者

如果通过代理服务器使用 Azure CLI,可能会导致以下错误:SSLError("错误握手:错误([('SSL 例程', 'tls_process_server_certificate', '证书验证失败')],) ”,)。要解决此错误,请将环境变量 REQUESTS_CA_BUNDLE 设置为 PEM 格式的证书颁发机构捆绑证书文件的路径。

将代理服务器的证书附加到此文件或将内容复制到另一个证书文件,然后为其设置 REQUESTS_CA_BUNDLE。您可能还需要设置 HTTP_PROXY 或 HTTPS_PROXY 环境变量。

Link to Ms Docs Solution

关于windows - 在 Windows 上使用 Azure CLI 颁发证书链中的自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69541003/

相关文章:

c# - Azure 函数 C# : Create or replace document in cosmos db on HTTP request

azure - 带有文档的 Azure CosmosDB 如何避免同时编辑单个文档?

database - 从 Windows 7 64 位连接到 32 位 Oracle 数据库

windows - aws s3 命​​令在 Windows 任务计划程序触发的批处理文件中不起作用

python - Azure函数Python docker容器: Unable to find an Azure Storage connection string to use for this binding

Qt SSL 服务器只在本地网络可见

安全建议 : SSL and API access

windows - NSIS 使用 GetParameters 的奇怪行为

windows - PowerShell:仅为单个命令设置环境变量

ssl - 如何以编程方式为 Tyrus WebSocket @ServerEndpoint 启用 WSS