在 Service Fabric 中将 SSL 添加到 Web Api 的基本步骤是:
- 将证书添加到 KeyVault
- 在 VM 规模集 VM 上安装它
- 将证书添加到 ServiceManifest 和 ApplicationManifest (或以其他方式将其添加到您的服务中,让我们在这里使用清单)
根据您上面的描述,您可能已经涵盖了所有这些步骤。当您使用证书保护集群时,该证书会安装在集群中的每个 VM 上。这应该只是在您的清单中引用它的问题。如果您需要向集群添加另一个证书(如果您正在运行使用不同证书保护的多个应用程序),请查看下面的步骤 2 以使用 ARM 更新 VM。
仅供参考,我在下面添加了所有必需的步骤。
将证书添加到 KeyVault
您已经完成此操作,但仅供参考
我建议使用ServiceFabricRPHelpers来帮助将证书添加到 KeyVault。PowerShell 中的一些类似的东西
Invoke-AddCertToKeyVault
-SubscriptionId $subscriptionId
-ResourceGroupName $vaultResourceGroupName
-Location $vaultLocation
-VaultName $vaultName
-CertificateName $clusterCertName
-Password $clusterCertPw
-UseExistingCertificate
-ExistingPfxFilePath $certFilePath
在 VMSS 上安装证书
由于您已使用证书保护集群,因此您的 VM 已经安装了保管库证书,但同样,仅供参考
您可以使用 PS cmdlet 或更新 ARM 模板来执行此操作。PS cmdlet 可能如下所示:
$certConfig = New-AzureRmVmssVaultCertificateConfig
-CertificateUrl $certificateUrl
-CertificateStore $certStore
# Add the certificate as a new secret on each VM in the scaleset
$vmss = (Get-AzureRmVmss | Where-Object{$_.name -eq $vmssName})[0]
$vmss.VirtualMachineProfile.OsProfile.Secrets[0].VaultCertificates.Add($certConfig)
# Trigger an update the VMs in the scaleset
Update-AzureRmVmss -ResourceGroupName $ResourceGroup -Name $VmssName -VirtualMachineScaleSet $Vmss
ARM版本看起来像这样
"osProfile": {
"adminPassword": "[parameters('adminPassword')]",
"adminUsername": "[variables('adminUsername')]",
"computernamePrefix": "[variables('vmNodeType0ComputerName')]",
"secrets": [
{
"sourceVault": {
"id": "[parameters('sourceVaultValue')]"
},
"vaultCertificates": [
{
"certificateStore": "[variables('certificateStoreValue')]",
"certificateUrl": "[parameters('certificateUrlValue')]"
}
]
}
]
},
对于此 ARM 模板版本,您可以通过从 Azure 门户下载自动生成的脚本或下载第一次部署时使用的实际模板来更新已部署的集群(即使您使用向导中的向导进行部署)门户它实际上为您在幕后创建了一个模板,它是您在最后一步单击确定时部署的模板)。
在门户中找到包含您的集群的资源组。
![在此处输入图像描述](https://i.stack.imgur.com/wS8I2.png)
自动化脚本根据资源组此时包含的内容为您呈现一个新模板,它是您对组中资源的所有更改的累积。单击下载,您将获得一个包含模板文件和参数的 .zip。
![在此处输入图像描述](https://i.stack.imgur.com/c75eg.png)
您现在可以使用 PowerShell 重新部署它,如下所示:
New-AzureRmResourceGroupDeployment
-Name "Update_admin_cert"
-TemplateFile .\template.json
-ResourceGroupName $resourceGroupName
-Mode Incremental
请注意该Mode Incremental
选项,它只是使用您正在部署的模板中的任何新定义或重叠定义来修补资源组中已有的任何内容,因此如果您只想更改或在现有资源组上运行它(通常)是安全的为资源添加一些细节。
将证书添加到 ApplicationManifest
将证书添加到您的服务是更新用于部署应用程序/服务的清单的问题。本文档文章概述了您的需求。简而言之,在引用证书指纹的标签中添加一个EndpointBindingPolicy
in和ServiceManifestImport
一个ApplicationManifest.xml
证书:Certificates
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Stateful1Pkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<Policies>
<EndpointBindingPolicy CertificateRef="TestCert1" EndpointRef="ServiceEndpoint3"/>
</Policies>
</ServiceManifestImport>
<Certificates>
<EndpointCertificate Name="TestCert1" X509FindValue="ABCDEF27174012740129FADBC232348324" X509StoreName="MY" />
</Certificates>