Azure云服务(经典)-单个实例缺少根CA / SSL证书,无法验证

时间:2020-05-07 13:56:43

标签: .net azure ssl cloud

我在托管WCF服务的Azure中运行了一个云服务(经典)。通过Cloud Service的Scale功能在Cloud Service中配置了多个实例。已通过Azure门户提供了SSL通配符证书,并在相应的Visual Studio Cloud项目的csdef / cscfg中对其进行了配置。直到最近,一切都运行良好,没有出现证书等问题。

.csdef

<Sites>
  <Site name="Web">
    <Bindings>
      <Binding name="Endpoint2" endpointName="EndpointSSL" />
    </Bindings>
  </Site>
</Sites>
<Endpoints>
  <InputEndpoint name="EndpointSSL" protocol="https" port="443" certificate="SSL" />
</Endpoints>
<Certificates>
  <Certificate name="SSL" storeLocation="LocalMachine" storeName="My" />
</Certificates>

.cscfg

<Role name="FR">
  <Instances count="3" />
  <ConfigurationSettings>
    <!-- Settings are set here -->
  </ConfigurationSettings>
  <Certificates>
    <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="THUMBPRINT_A" thumbprintAlgorithm="sha1" />
    <Certificate name="SSL" thumbprint="THUMBPRINT_B" thumbprintAlgorithm="sha1" />      
  </Certificates>
</Role>

证书已正确安装,如您在Windows的“证书管理”窗口中所见。不幸的是,从上周开始,当通过SSL Labs(https://www.ssllabs.com/ssltest/)检查站点时,它开始在结果报告中提供两个证书,其中一个证书无效,因为证书链似乎已损坏。使用相同通配符证书的其他服务没有此问题。

到目前为止,我对这个问题所了解的内容:

  • 三个正在运行的实例之一的证书存储中的证书无法通过Windows本身进行验证。
  • 在其他两个实例上,证书是正确的,并且可以通过Windows进行验证
  • 具有无效证书的实例在Windows的“受信任的根CA”存储中没有相应的根CA。
  • 重新部署,重新映像,重新启动等无济于事。它可能只是将问题从一个实例转移到另一个实例。到目前为止,一次只影响一个实例。
  • 没有手动进行更改,最近也没有应用更新的部署。它刚刚开始突然出现

Certificates on the invalid and a correct instance

有人知道这个问题可能是什么吗?我还向Microsoft开了一张支持票,但到目前为止,他们也一无所知。部署时是否可以尝试进行任何设置以强制在部署时验证证书?还是可以选择在启动时从代码中获取丢失的根CA(因为我怀疑这可能是为什么无法在一个实例上对其进行验证的问题)?

1 个答案:

答案 0 :(得分:0)

Microsoft Azure支持人员也不知道此行为的根本原因,但是他们暂时提出了合适的解决方法。

在Cloud Service中,已添加了一个启动任务,用于检查所有根CA列表中是否存在潜在丢失的根CA。如果不是,将安装缺少的一个(通过Powershell)。之后,应该将丢失的根CA添加到根CA列表中,并且可以成功验证实际的SSL通配符证书(验证失败)-通过SSLLabs进行的检查将再次起作用。

至少对于我的问题,这是成功的秘诀。我不完全满意它,因为我想知道根本原因,但是Microsoft似乎已经意识到了这个问题,并且(据我了解)正在进一步调查。如果出现任何适当的解决方案(而不是替代方法),我也会尝试在此处添加它。

用于启动任务的CMD文件:

SET LOG_FILE="%TEMP%\StartupLog.txt"
SET EXECUTE_PS1=0

IF "%ComputeEmulatorRunning%" == "" (
    SET EXECUTE_PS1=1
)

IF "%ComputeEmulatorRunning%" == "false" (
    SET EXECUTE_PS1=1
) 

IF %EXECUTE_PS1% EQU 1 (
    echo "Invoking InstallCertificateSSLConfigure.ps1 on Azure service at %TIME% on %DATE%" >> %LOG_FILE% 2>&1  
    PowerShell -ExecutionPolicy Unrestricted .\Startup\InstallCertificate.ps1 >> %LOG_FILE% 2>&1
    IF %ERRORLEVEL% NEQ 0 (EXIT /B %ERRORLEVEL%)
) ELSE (
    echo "Skipping InstallCertificate.ps1 invocation on emulated environment" >> %LOG_FILE% 2>&1    
)    

EXIT /B 0 

用于安装证书的Powershell脚本(从CMD执行)

$thumbprint = "THUMBPRINT"
$path = ".\Startup\MISSING ROOT CA.crt"

$cert = Get-ChildItem -Path Cert:\LocalMachine\Root | Where-Object {$_.Thumbprint -eq $thumbprint}

if ( $cert )
{
    Write-Host "The Certificate $($cert.Thumbprint) is installed already"
}
else
{
    Write-Host "The Certificate $thumbprint is not installed"
    Import-Certificate -FilePath $path -CertStoreLocation Cert:\LocalMachine\Root
    Write-Host "installed the Certificate $thumbprint"
}