将https添加到Service Fabric Web Api

Lil*_*vik 0 azure azure-resource-manager azure-service-fabric azureportal

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

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

我已经按照本指南更新configuraton,新增https端点ServiceManifest.xmlNimles.UserManagement.Api.Authorized

<Endpoint Protocol="https" Name="ServiceEndpointHttps" Type="Input" Port="9021" />
Run Code Online (Sandbox Code Playgroud)

添加了对 ApplicationManifest.xml

<ServiceManifestRef ServiceManifestName="Nimles.UserManagement.Api.AuthorizedPkg" ServiceManifestVersion="1.0.0" />
<Policies>
  <EndpointBindingPolicy EndpointRef="ServiceEndpointHttps" CertificateRef="NimlesComCert" />
</Policies>
Run Code Online (Sandbox Code Playgroud)

添加证书

<Certificates>
  <EndpointCertificate X509FindValue="*****" Name="NimlesComCert" />
</Certificates>
Run Code Online (Sandbox Code Playgroud)

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

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

yoa*_*ape 5

在Service Fabric中将SSL添加到Web Api的基本步骤是:

  • 将证书添加到KeyVault
  • 在VM Scale Set VMs上安装
  • 将证书添加到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
Run Code Online (Sandbox Code Playgroud)

在VMSS上安装证书 由于已经通过证书保护了群集,因此您的VM已安装了Vault证书,但是再次,仅供参考。

您可以使用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
Run Code Online (Sandbox Code Playgroud)

而ARM版本看起来像这样

"osProfile": {
    "adminPassword": "[parameters('adminPassword')]",
    "adminUsername": "[variables('adminUsername')]",
    "computernamePrefix": "[variables('vmNodeType0ComputerName')]",
    "secrets": [
        {
            "sourceVault": {
                "id": "[parameters('sourceVaultValue')]"
            },
            "vaultCertificates": [
                {
                    "certificateStore": "[variables('certificateStoreValue')]",
                    "certificateUrl": "[parameters('certificateUrlValue')]"
                }
            ]
        }
    ]
},
Run Code Online (Sandbox Code Playgroud)

对于此版本的ARM模板版本,您可以通过从Azure门户下载自动生成的脚本,或通过下载首次部署时使用的实际模板来更新已部署的群集(即使您通过使用它实际上为您在幕后创建了一个模板,并且是在最后一步中单击“确定”时部署的模板。

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

在此处输入图片说明

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

在此处输入图片说明

现在,您可以使用以下任一PowerShell重新部署它:

New-AzureRmResourceGroupDeployment 
    -Name "Update_admin_cert" 
    -TemplateFile .\template.json 
    -ResourceGroupName $resourceGroupName 
    -Mode Incremental
Run Code Online (Sandbox Code Playgroud)

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

将证书添加到ApplicationManifest

将证书添加到您的服务就是更新用于部署应用程序/服务的清单。本文档文章概述了您所需要的。简而言之,将in 添加EndpointBindingPolicyServiceManifestImportApplicationManifest.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>
Run Code Online (Sandbox Code Playgroud)