首页 > 其他分享 >【Azure 云服务】为Azure云服务配置上自签名的SSL证书步骤

【Azure 云服务】为Azure云服务配置上自签名的SSL证书步骤

时间:2022-12-31 22:04:57浏览次数:53  
标签:服务 cn 证书 SSL services 签名 Azure cloud

问题描述

在使用Azure Cloud Service(云服务),默认的情况下都是使用的 HTTP 服务,通过 Visual Studio 2022 创建的默认 Cloud Service项目中,在ServiceDefinition.csdef 服务定义文件中,值默认开启了HTTP 80的Endpoint。

<InputEndpoint name="Endpoint1" protocol="http" port="80" />

而如果要让云服务使用HTTPS,需要那些操作步骤呢? 在官网中,有两部分文档对此有所介绍:

第一部分:云服务证介绍和生成自签名证书 ​​https://docs.azure.cn/zh-cn/cloud-services/cloud-services-certs-create#create-a-new-self-signed-certificate​

$cert = New-SelfSignedCertificate -DnsName yourdomain.chinacloudapp.cn -CertStoreLocation "cert:\LocalMachine\My" -KeyLength 2048 -KeySpec "KeyExchange"
$password = ConvertTo-SecureString -String "your-password" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath ".\my-cert-file.pfx" -Password $password

第二部分:为云服务 配置TLS ​​https://docs.azure.cn/zh-cn/cloud-services/cloud-services-configure-ssl-certificate-portal#step-2-modify-the-service-definition-and-configuration-files​

参照以上两部分内容,就可以实现为云服务配置自签名证书。虽然通过浏览器访问时,还是会提示自签名证书不受信任,但在实验阶段已完全可用!

最终结果如下:

【Azure 云服务】为Azure云服务配置上自签名的SSL证书步骤_云服务

 

实现步骤

第一步: 通过Windows 机器使用Powershell脚本生成 以云服务域名为主题的自签名证书 (注意:需要以管理员权限运行PowerShell)

【Azure 云服务】为Azure云服务配置上自签名的SSL证书步骤_云服务_02

注意:如果没有使用管理员权限执行 New-SelfSignedCertificate 命令,则会出现权限不够的提示信息“New-SelfSignedCertificate : CertEnroll::CX509Enrollment::_CreateRequest: Access is denied. 0x80070005 (WIN32: 5 ERROR_ACCESS_DENIED)”。

证书生成完毕后,进入C:\WINDOWS\system32 目录,找到 my-cert-file.pfx 文件,双击,安装此证书到本机。最后,通过 Certmgr 证书管理工具查看证书的指纹信息(thumbprint)

【Azure 云服务】为Azure云服务配置上自签名的SSL证书步骤_签名证书_03

 

第二步:修改云服务配置文件,添加 Certificates , Endpoints 以及 Site Binding

参考“​​为Azure云服务配置SSL​​”文章中的第二部分,修改服务定义和配置文件。可以完全参考文档中的步骤2操作,本试验中,因为使用的是自签名证书,所以就没有有配置CA root部分。

一:修改 ServiceDefinition.csdef 文件中的 Certificates, InputEndpoint 和 Site Binding

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AzureCloudService1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">
<WebRole name="WebRole2" vmsize="Standard_D1_v2">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="Endpoint1" endpointName="Endpoint1" />
<Binding name="HttpsIn" endpointName="HttpsIn" />
</Bindings>
</Site>
</Sites>
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"/>
</ConfigurationSettings>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
<InputEndpoint name="HttpsIn" protocol="https" port="443"
certificate="SampleCertificate" />
</Endpoints>
<Imports>
<Import moduleName="RemoteAccess" />
<Import moduleName="RemoteForwarder" />
</Imports>
<Certificates>
<Certificate name="SampleCertificate"
storeLocation="LocalMachine"
storeName="My"
permissionLevel="limitedOrElevated" />
<!-- IMPORTANT! Unless your certificate is either
self-signed or signed directly by the CA root, you
must include all the intermediate certificates
here. You must list them here, even if they are
not bound to any endpoints. Failing to list any of
the intermediate certificates may cause hard-to-reproduce
interoperability problems on some clients.-->
<!--<Certificate name="CAForSampleCertificate"
storeLocation="LocalMachine"
storeName="CA"
permissionLevel="limitedOrElevated" />-->
</Certificates>
</WebRole>
</ServiceDefinition>
  1. 在 Sites 节中添加 Binding 元素。 此元素添加 HTTPS 绑定以将终结点映射到站点
  2. 在“Endpoints”部分中添加 InputEndpoint 元素以启用 HTTPS
  3. Certificates 节定义了证书的名称、位置及其所在存储的名称

二:在服务配置文件 (CSCFG) ServiceConfiguration.Cloud.cscfg 中,添加 Certificates 值并为其指定证书的指纹(thumbprint)

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="AzureCloudService1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="6" osVersion="*" schemaVersion="2015-04.2.6">
<Role name="WebRole2">
<Instances count="1" />

... ...

<Certificates>
<Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="B8E0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXD6D8" thumbprintAlgorithm="sha1" />
<Certificate name="SampleCertificate"
thumbprint="deb8bff5ced1e43e0723cdf9857b6a6ca1d793b2"
thumbprintAlgorithm="sha1" />
</Certificates>
</Role>
</ServiceConfiguration>

在云服务项目文件中修改的动图说明如下:

【Azure 云服务】为Azure云服务配置上自签名的SSL证书步骤_云服务_04

 

第三步:上传第一步生成的 my-cert-file.pfx证书到 云服务的 Certificates 页面

 

【Azure 云服务】为Azure云服务配置上自签名的SSL证书步骤_Azure 云服务_05

在门户中,上传服务证书。 这一步需要在部署之前操作,否则会出现部署失败。失败原因为:The certificate with thumbprint deb8bff5ced1e43e0723cdf9857b6a6ca1d793b2 was not found.'

 

第四步:重新部署云服务, 然后使用https访问,而不是http

【Azure 云服务】为Azure云服务配置上自签名的SSL证书步骤_签名证书_06

 如果使用自签名证书,浏览到与自签名证书关联的 HTTPS 终结点时,浏览器中可能会显示一个证书错误。 使用由受信任证书颁发机构签名的证书可消除此问题;同时,你可以忽略此错误。 (也可以将自签名证书添加到用户的受信任证书颁发机构证书存储中。)

 

参考资料

云服务证介绍和生成自签名证书 : ​​https://docs.azure.cn/zh-cn/cloud-services/cloud-services-certs-create#create-a-new-self-signed-certificate​

为云服务 配置TLS : ​​https://docs.azure.cn/zh-cn/cloud-services/cloud-services-configure-ssl-certificate-portal#step-2-modify-the-service-definition-and-configuration-files​

 

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!



标签:服务,cn,证书,SSL,services,签名,Azure,cloud
From: https://blog.51cto.com/u_13773780/5982404

相关文章

  • Nginx 安装 SSL 配置 HTTPS 超详细完整全过程
    在Nginx或Tengine服务器上安装证书说到 ​​Nginx​​​ 服务器,个人认为最大特点就是轻量级和高性能。通过在几台不同的服务器上进行测试,发现它的并发能力特别强,并且相对......
  • 阿里云服务器安装Apache环境外网不能访问
    原文地址:https://www.cnblogs.com/mnhy/p/8086015.html今天在阿里云上配置Apache+mysql+PHP,发现使用浏览器一直访问不了 我在网上找了好多方法都没有用,然后我想是不是......
  • 在Ubuntu上安装Azure DevOps代理程序
    Contents1概述2.安装Ubuntu18.04操作系统3.安装AzureDevOpsServer代理3.1安装AzureDevOpsServer代理3.2以服务方式运行代理1.概述Ubuntu是一个以桌面应用为主......
  • 微服务 Spring Boot Mybatis-Plus 整合 EasyPOI 实现 Excel 一对多 导入
    文章目录​​⛄引言​​​​一、EasyPOI实现Excel的一对多导入--代码实现​​​​⛅需求说明​​​​⚡核心源码实现​​​​二、EasyPOI实现一对多导入--测试​​......
  • 如何为企业打造优质应用环境!华为云弹性服务器了解一下
    一个业务好不好最重要是取决于他的服务器,服务器好的话,能够给业务带来非常不错的应用环境,也能给使用者带来非常多的便利。所以说一个好的服务器是非常重要的,在众多服务器中,华......
  • 【Azure Developer】开发模式下使用AAD账号访问Azure Blob的相关参考
    问题描述开发模式下使用AAD账号访问AzureBlob的流程参考文件 问题解答第一步:先在AAD中注册一个APP,步骤可参考:将应用程序注册到Microsoft标识平台:​​https://docs.azur......
  • WSGI服务器源码分析
    一、wsgiref模块在web开发中,后端服务分为服务器和应用程序:服务器本质就是通过socket进行请求的接收应用程序就是对请求进行相应业务处理为了开发方便,将上述两部分分......
  • 华为云弹性负载均衡服务,如何助企业应付流量压力
    随着企业的云上业务不断发展,企业对于应用系统的性能要求越来越高,而企业应用系统的性能受到带宽流量和网络备份及负载的压力的影响。​为了帮助企业提升应用系统的对外服务能......
  • 华为云连接CC服务助企业联通全球
    随着世界经济一体化,众多企业开始将业务渠道拓展到海外市场。但在具体实施布局跨境业务渠道时,会遇到巨大的难题和挑战,首当其冲的便是企业对全球级云网络的搭建与连接,并需要保......
  • 构建服务的命令
    *windowPowerShell创建服务New-Service-NamedevApi-BinaryPathName"D:\website\dev\Dev.Api\bin\Release\net6.0\publish\Dev.Api.exe"查看状态Get-Service......