0

我已经使用 Azure 门户创建了一个 Service Fabric 群集。它由来自 CA 的通配符 SSL 证书保护。证书存储在密钥库中。

在集群中,我有几个 web api 服务。我想向它们添加 https 端点。

我已按照本指南更新配置,将 https 端点添加ServiceManifest.xmlNimles.UserManagement.Api.Authorized

<Endpoint Protocol="https" Name="ServiceEndpointHttps" Type="Input" Port="9021" />

添加绑定到ApplicationManifest.xml

<ServiceManifestRef ServiceManifestName="Nimles.UserManagement.Api.AuthorizedPkg" ServiceManifestVersion="1.0.0" />
<Policies>
  <EndpointBindingPolicy EndpointRef="ServiceEndpointHttps" CertificateRef="NimlesComCert" />
</Policies>

添加证书

<Certificates>
  <EndpointCertificate X509FindValue="*****" Name="NimlesComCert" />
</Certificates>

但是我找不到有关如何将证书添加到 VM 的信息,因为我已使用门户创建集群,并且所有指南都只是 ARM 模板的引用。

如果无法从门户网站上使用 ARM,我不介意是否需要使用 ARM,但我不想重新创建集群,在这种情况下,只需将 ARM 与我当前的集群一起使用。

4

2 回答 2

5

在 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 门户下载自动生成的脚本或下载第一次部署时使用的实际模板来更新已部署的集群(即使您使用向导中的向导进行部署)门户它实际上为您在幕后创建了一个模板,它是您在最后一步单击确定时部署的模板)。

在门户中找到包含您的集群的资源组。

在此处输入图像描述

自动化脚本根据资源组此时包含的内容为您呈现一个新模板,它是您对组中资源的所有更改的累积。单击下载,您将获得一个包含模板文件和参数的 .zip。

在此处输入图像描述

您现在可以使用 PowerShell 重新部署它,如下所示:

New-AzureRmResourceGroupDeployment 
    -Name "Update_admin_cert" 
    -TemplateFile .\template.json 
    -ResourceGroupName $resourceGroupName 
    -Mode Incremental

请注意该Mode Incremental选项,它只是使用您正在部署的模板中的任何新定义或重叠定义来修补资源组中已有的任何内容,因此如果您只想更改或在现有资源组上运行它(通常)是安全的为资源添加一些细节。

将证书添加到 ApplicationManifest

将证书添加到您的服务是更新用于部署应用程序/服务的清单的问题。本文档文章概述了您的需求。简而言之,在引用证书指纹的标签中添加一个EndpointBindingPolicyin和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>
于 2017-03-21T13:55:50.153 回答
0

您可以使用门户为现有资源组生成 ARM 模板。单击“自动化脚本”菜单项。然后点击“下载”。

然后,您可以使用节点“virtualMachineProfile”中的证书信息重新部署“Microsoft.Compute/virtualMachineScaleSets”类型的资源。(删除其余的,删除依赖项)

请注意,您必须提供任何参数值,因为它们不会自动填写。

(不过,我建议使用 ARM 模板来创建集群。)

于 2017-03-21T07:28:41.160 回答