azure - 如何检索本地 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”评论)
解决方案
我已经能够解决我的问题:
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 中进行调试。
推荐阅读
- r - 使用列表传递数据框名称时出现意外结果
- spring - Spring缓存@Cacheable和@CachePut。如果@cachePut方法内部抛出异常,则从Cache中获取数据
- c# - 当 Dragon NaturallySpeaking 的 MouseGrid 打开时,C# 保持下拉菜单打开
- json - 如何在本地使用 reactNative 获取 name.json 文件?
- javascript - 如何使用敲除禁用/启用 html 表中的所有元素
- c++ - 为什么我的程序有时只能正确识别数组中的最高值和最低值?
- sql - SQL根据引用表递归选择父子
- bash - In the "rbenv-rehash" bash script, what does "-e* | -- ) break ;;" do?
- python - 如何使用 lxml 选择和更新混合内容中的文本节点?
- android - 如何为小部件重新启动 RemoteViewsService