如何检索本地 Service Fabric 集群的证书指纹?
How to retrieve certificate thumbprint of the local Service Fabric cluster?
我们有一个由微服务组成的应用程序,还使用各种 Azure 资源,如 CosmosDB、Redis、EventHub。
所以我们编写了一个 Powershell 脚本,它从 Azure 资源组中检索各种秘密:CosmosDB 连接字符串以及 Redis 和 Eventhub 的连接字符串。此外,还会从资源组中的 Key Vault 中读取 SF 证书指纹。然后将机密存储在 git 工作区外的 Json 文件中。
然后在Scripts\Deploy-FabricApplication.ps1我们读取Json文件,使用secrets替换占位符:
$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
这适用于远程发布和调试(从 Visual Studio 2017 年起)使用 Cloud.xml。
但是对于 Local.1Node.xml 它失败了,因为我们的应用程序通过 ServiceManifest.xml
中的条目检查证书指纹
<Endpoint Protocol="https" Name="ServiceEndpoint"
Type="Input" Port="9950" CertificateRef="MY_CERT" />
因此在本地发布 SF 应用程序失败:
我的问题是:如何获取本地Service Fabric SDK安装的证书指纹?
如果可以的话,我会把它放在上面的脚本中(请参阅“TODO”注释)
我已经能够解决我的问题:
Write-Host "Retrieving thumbprint for local SF certificate... " -NoNewline
$localCert = Get-ChildItem cert:\LocalMachine\My | Where { $_.Subject -eq 'CN=AzureServiceFabric-AnonymousClient'}
Write-Host "ok"
现在我可以在 Visual Studio 中进行本地和远程调试(在 Azure 中部署的 SF)。
我们有一个由微服务组成的应用程序,还使用各种 Azure 资源,如 CosmosDB、Redis、EventHub。
所以我们编写了一个 Powershell 脚本,它从 Azure 资源组中检索各种秘密:CosmosDB 连接字符串以及 Redis 和 Eventhub 的连接字符串。此外,还会从资源组中的 Key Vault 中读取 SF 证书指纹。然后将机密存储在 git 工作区外的 Json 文件中。
然后在Scripts\Deploy-FabricApplication.ps1我们读取Json文件,使用secrets替换占位符:
$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
这适用于远程发布和调试(从 Visual Studio 2017 年起)使用 Cloud.xml。
但是对于 Local.1Node.xml 它失败了,因为我们的应用程序通过 ServiceManifest.xml
中的条目检查证书指纹<Endpoint Protocol="https" Name="ServiceEndpoint"
Type="Input" Port="9950" CertificateRef="MY_CERT" />
因此在本地发布 SF 应用程序失败:
我的问题是:如何获取本地Service Fabric SDK安装的证书指纹?
如果可以的话,我会把它放在上面的脚本中(请参阅“TODO”注释)
我已经能够解决我的问题:
Write-Host "Retrieving thumbprint for local SF certificate... " -NoNewline
$localCert = Get-ChildItem cert:\LocalMachine\My | Where { $_.Subject -eq 'CN=AzureServiceFabric-AnonymousClient'}
Write-Host "ok"
现在我可以在 Visual Studio 中进行本地和远程调试(在 Azure 中部署的 SF)。