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

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

时间:2022-12-27 15:34:38浏览次数:57  
标签:服务 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

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

最终结果如下:

 

实现步骤

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

注意:如果没有使用管理员权限执行 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)

 

第二步:修改云服务配置文件,添加 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>

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

 

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

 

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

 

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

 如果使用自签名证书,浏览到与自签名证书关联的 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://www.cnblogs.com/lulight/p/17008017.html

相关文章

  • 麒麟系统访问 FTP 服务端
    1.远程目录访问ftp服务端文件浏览器地址栏或浏览器地址栏输入:ftp://172.19.72.171(此为访问主机的ip地址)设置匿名登录即可直接登录,若设置用户登录,则需要输入用户......
  • 腾讯云免费申请SSL证书配置https
    证书申请1、进入腾讯云官网,在上方直接搜索SSL,搜索到后点击立即选购;2、点击进去后选择自定义配置,加密标准选择默认的国际标准,证书种类选择域名免费版(DV),勾选同意服务条款......
  • 造成香港服务器突然断网的原因有哪些
    1、电信出口异常由于电信运营商网络异常的缘故,香港服务器租用服务,有时会出现大陆通过电信访问香港服务器出现网络不稳定甚至网络中断的情况,这就需要您的香港服务器租......
  • 谷歌为iOS开发者推出地图服务SDK
    12月13日消息,谷歌没有满足于在iOS平台推出一个独立的地图应用,他们希望其他开发人员能把谷歌地图服务整合他们自己的应用中去。因此,谷歌推出了一个地图服务SDK,它通过URL方......
  • Centos7下单节点部署etcd服务
    一台Centos7的服务器,我的IP:172.16.4.67登陆到服务器,切换到root用户#cd/tmp下载安装包,下载地址:https://github.com/etcd-io/etcd/releases#wget https://github.com/......
  • Microsoft Azure解决方案:如何创建Remote App应用程序组并授权
    51CTO博客地址:​ ​​​​https://blog.51cto.com/14669127​​​Azure培训视频地址:​ ​​​https://space.bilibili.com/2000820534​​本文将给大家介绍一下如何创建R......
  • Microsoft Azure 解决方案:如何在Azure虚拟桌面安装OneDrive和Teams
    51CTO博客地址: ​​https://blog.51cto.com/14669127​​Azure培训视频地址: ​​https://space.bilibili.com/2000820534​​​本文给大家分享如何在Azure 虚拟桌面上......
  • 远距离串口服务器模块PS304 多种数字接口物理层协议转发器
     PS304(PortsServerchannel4)是多种数字接口物理层协议转发器,可实现UART转换I2C、SPI、1Wire远距离通讯,内嵌磁隔离双电源及辅助增强电源电路、自适应线缆算法、......
  • C# font远程服务器字体无法显示
    项目中使用了System.Drawing相关的font,本地正常,远程显示方块,可以把本地字体文件复制到远程。关键代码:System.Drawing.Text.PrivateFontCollectionprivateFonts=newSy......
  • 0310_【掌握】微服务注册
    1、//https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-alibaba-nacos-discoveryimplementationgroup:'com.alibaba.cloud',name:'spring......