首页 > 解决方案 > 如何检索本地 Service Fabric 群集的证书指纹?

问题描述

我们有一个由微服务组成的应用程序,还使用各种 Azure 资源,如 CosmosDB、Redis、EventHub。

所以我们编写了一个 Powershell 脚本,它从 Azure 资源组中检索各种机密:CosmosDB 连接字符串,对于 Redis 和 Eventhub 也是如此。此外,还从资源组中的 Key Vault 读取 SF 证书指纹。然后将秘密存储在 git 工作区之外的 Json 文件中。

然后在 Scripts\Deploy-FabricApplication.ps1 我们读取 Json 文件并使用秘密替换占位符:

$jsonFile = "$rootDir\secrets.json"
$secretsHashtable = @{}
(Get-Content $jsonFile| ConvertFrom-Json).psobject.properties | Foreach { $secretsHashtable[$_.Name] = $_.Value }

$ApplicationPackagePath = Resolve-Path $ApplicationPackagePath

$publishProfile = Read-PublishProfile $PublishProfileFile

if ($PublishProfileFile.EndsWith("Local.1Node.xml"))
{
    $secretsHashtable['Cluster-Host-Name'] = 'localhost'
    # TODO store the local SF certificate thumbprint in $secretsHashtable['SSL-Certificate-Find-Value']
    $publishProfile.CopyPackageParameters.CompressPackage = $true
    $OutFile = "$LocalFolder\..\ApplicationParameters\Local.1Node.xml"
}
else
{
    $OutFile = "$LocalFolder\..\ApplicationParameters\Cloud.xml"
}

# Replace $( ... ) in Cloud.Template.xml by the values from the hashtable
$TemplateFile = "$LocalFolder\..\ApplicationParameters\Template.xml"
$TemplateStr  = Get-Content $TemplateFile -Raw
$ReplacedStr  = [regex]::Replace($TemplateStr, '\$\(([\w-]+)\)', {
    param($match)
    $key = $match.Groups[1].Value
    $value = $secretsHashtable[$key]
    if ($value -ne $null)
    {
        return $value
    }
    else
    {
        throw "$key not found in $jsonFile"
    }
})

Set-Content -Path $OutFile -Value $ReplacedStr

这适用于使用 Cloud.xml 进行远程发布和调试(来自 Visual Studio 2017)。

但是 Local.1Node.xml 失败,因为我们的应用程序通过 ServiceManifest.xml 中的条目检查证书指纹

<Endpoint Protocol="https" Name="ServiceEndpoint" 
    Type="Input" Port="9950" CertificateRef="MY_CERT" />

因此在本地发布 SF 应用程序失败:

事件查看器日志

我的问题是:如何检索本地 Service Fabric SDK 安装的证书指纹?

如果我能做到这一点,我会把它放在上面的脚本中(请参阅“TODO”评论)

标签: azurecertificateazure-service-fabricazure-powershell

解决方案


我已经能够解决我的问题:

Write-Host "Retrieving thumbprint for local SF certificate... " -NoNewline
$localCert = Get-ChildItem cert:\LocalMachine\My | Where { $_.Subject -eq 'CN=AzureServiceFabric-AnonymousClient'}
Write-Host "ok"

现在我可以在本地和远程(在 Azure 中部署的 SF)在 Visual Studio 中进行调试。


推荐阅读