Azure 将https添加到服务结构Web Api
我已经使用Azure门户创建了一个服务结构集群。它由来自CA的通配符SSL证书保护。该证书存储在keyvault中 在集群中,我有几个web api服务。我想向它们添加https端点 我必须更新配置,将https端点添加到Azure 将https添加到服务结构Web Api,azure,azure-service-fabric,azure-resource-manager,azureportal,Azure,Azure Service Fabric,Azure Resource Manager,Azureportal,我已经使用Azure门户创建了一个服务结构集群。它由来自CA的通配符SSL证书保护。该证书存储在keyvault中 在集群中,我有几个web api服务。我想向它们添加https端点 我必须更新配置,将https端点添加到Nimles.UserManagement.Api.Authorized <Endpoint Protocol="https" Name="ServiceEndpointHttps" Type="Input" Port="9021" /> 附加证书 <Cer
Nimles.UserManagement.Api.Authorized
<Endpoint Protocol="https" Name="ServiceEndpointHttps" Type="Input" Port="9021" />
附加证书
<Certificates>
<EndpointCertificate X509FindValue="*****" Name="NimlesComCert" />
</Certificates>
但是我找不到关于如何将证书添加到VM的信息,因为我已经使用门户创建了集群,所有指南都只是引用ARM模板
我不介意在门户不可能的情况下是否需要使用ARM,但我不想重新创建集群,在这种情况下,只需在当前集群中使用ARM即可 您可以使用门户为现有资源组生成ARM模板。单击“自动化脚本”菜单项。然后单击“下载” 然后,您可以重新部署类型为“Microsoft.Compute/virtualmachinescaleets”的资源,其证书信息位于节点“virtualmachineeprofile”中。(删除其余部分,删除依赖项) 请注意,您必须提供任何参数值,因为它们不是自动填写的
(我建议首先使用ARM模板创建集群。)您可以使用门户为现有资源组生成ARM模板。单击“自动化脚本”菜单项。然后单击“下载” 然后,您可以重新部署类型为“Microsoft.Compute/virtualmachinescaleets”的资源,其证书信息位于节点“virtualmachineeprofile”中。(删除其余部分,删除依赖项) 请注意,您必须提供任何参数值,因为它们不是自动填写的
(我建议首先使用ARM模板创建集群。)在Service Fabric中将SSL添加到Web Api的基本步骤如下:
- 将证书添加到KeyVault
- 在虚拟机规模集虚拟机上安装它
- 将证书添加到ServiceManifest和ApplicationManifest(或者以其他方式将其添加到您的服务中,让我们在这里使用清单)
Invoke-AddCertToKeyVault
-SubscriptionId $subscriptionId
-ResourceGroupName $vaultResourceGroupName
-Location $vaultLocation
-VaultName $vaultName
-CertificateName $clusterCertName
-Password $clusterCertPw
-UseExistingCertificate
-ExistingPfxFilePath $certFilePath
在虚拟机上安装证书
由于您已使用证书保护集群,因此您的虚拟机已经安装了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
New-AzureRmResourceGroupDeployment
-Name "Update_admin_cert"
-TemplateFile .\template.json
-ResourceGroupName $resourceGroupName
-Mode Incremental
而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 Portal下载自动生成的脚本或下载第一次部署时使用的实际模板来更新已部署的集群(即使您通过在门户中使用向导进行部署,它实际上也会在后台为您创建一个模板,并且在最后一步中单击“确定”时部署该模板)
在门户中查找具有群集的资源组
自动化脚本根据此时资源组包含的内容为您呈现一个新模板,它是到目前为止组中资源的所有更改的累积。单击“下载”,您将获得一个包含模板文件和参数的.zip文件
您现在可以使用以下任一PowerShell重新部署它:
$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
New-AzureRmResourceGroupDeployment
-Name "Update_admin_cert"
-TemplateFile .\template.json
-ResourceGroupName $resourceGroupName
-Mode Incremental
请注意,模式增量
选项,它只是用您正在部署的模板中的任何新定义或重叠定义来修补资源组中已有的内容,因此(通常)如果您只想更改或添加资源的某些详细信息,则在现有资源组上运行它是安全的
将证书添加到ApplicationManifest
将证书添加到您的服务需要更新用于部署应用程序/服务的清单。概述了您需要的内容。简而言之,在ApplicationManifest.xml
中的ServiceManifestImport
中添加EndpointBindingPolicy
,并在Certificates
标记中添加引用的证书ces证书的指纹:
<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>
在Service Fabric中将SSL添加到Web Api的基本步骤包括:
- 将证书添加到KeyVault
- 在虚拟机规模集虚拟机上安装它
- 将证书添加到ServiceManifest和ApplicationManifest(或者以其他方式将其添加到您的服务中,让我们在这里使用清单)