问题描述

因为Key Vault的证书上传功能中,只支持pfx格式的证书,而中间证书,根证书不能转换为pfx格式,只能是公钥证书格式 cet 或者 crt,能通过文本工具直接查看base64编码内容。

如一个证书链文件中可以看见中间证书,根证书:

当把包含完成证书链的证书PFX上传到Key Vault certificates中后,certificates只会显示服务器证书的指纹,导致无法直接在Cloud Service(Extended Support)的配置文件中修改。

所以,如果中间证书,根证书需要安装到Cloud Service (Extended Support) 中,要先把中间证书,根证书放置在Key Vault Secrets中,然后调用Cloud Service API更新证书和配置Secrets Identifier URL来完成证书配置。

操作步骤

第一步:准备中间证书和根证书的cer 文件

(* 如果已经有中间证书的cer/crt 文件,用记事本查看证书Base64编码内容则可以跳过第一步)

查看PFX证书及证书链信息:

mmc certmgr.msc /CERTMGR:FILENAME="C:\Users\... \Downloads\mykey.pfx"

选中中间证书-> Details -> Copy to File

在打开的向导窗口中,点击Next,选择 "Base-64 encoded X.509 (.CER)“ --》设置保存路径 --》 导出成功

用记事本打开,查看证书Base64编码内容

(重复以上操作,把根证书也保存为CER文件)

(非常重要)第二步:把证书内容JSON格式化后,通过az cli命令设置到Key Vault Secret中

(这一步不能通过门户完成)

把证书的Base64编码内容填入JSON格式的data中

{
"data": "Your base64 certificate",
"dataType": "PFX",
"password": ""
}

然后把JSON内容保存为一个文件,使用az keyvault secret set   --file “” --encoding base64  添加到Key Vault中

注意:可以使用证书指纹作为机密名称,以方便更好的关联到证书信息

## 设置Key Vault机密

##intermediate
az keyvault secret set --vault-name <key value name> --name <thumbprint> --file ".\SSL\intermediate.txt" --encoding base64 ##root
az keyvault secret set --vault-name <key value name> --name <thumbprint> --file ".\SSL\root.txt" --encoding base64

执行完成后,从返回结果中获取到 id 值(Secret Identifier URL).

完成以上内容后,复制出指纹值和Secret ID URL,就可以通过Cloud Service (Extended Support)的API更新证书。

第三步:获取Cloud Service的信息,调用接口为GET API

参考文档:https://learn.microsoft.com/en-us/rest/api/compute/cloud-services/get?view=rest-compute-2024-07-01&tabs=HTTP

注意,在中国区需要修改Host Endpoint为:management.chinacloudapi.cn

GET https:// management.chinacloudapi.cn /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/cloudServices/{cloudServiceName}?api-version=2022-04-04

需要携带Authorization Token,否则会获得如下错误:

{
"error": {
"code": "AuthenticationFailed",
"message": "Authentication failed. The 'Authorization' header is missing."
}
}

获取Token的方式可以通过浏览器访问Cloud Service(Extended Support)门户,然后通过开发者工具(F12)查看网络请求,从访问Cloud Service的请求头中获取Authorization内容。或者通过az cli获取token

az cloud set --name AzureChinaCloud
az login
az account get-access-token --scope "https://management.core.chinacloudapi.cn/.default" --query accessToken

当成功获取到Cloud Service的信息后,调整 JSON内容:

删除Properties中,除了configuration 和 osProfile 外的全部内容。

整理之后JSON格式如下:

{
"name": "cloud service extended support name",
"id": "cloud service (extended) support resource id",
"type": "Microsoft.Compute/cloudServices",
"location": "chinanorth3",
"properties": {
"configuration": "{ServiceConfiguration}",
"osProfile": {
"secrets": [
{
"sourceVault": {
"id": "key vault resource id"
},
"vaultCertificates": [
{
"certificateUrl": "key vault Secret Identifier"
},
{
"certificateUrl": "key vault Secret Identifier"
},
{
"certificateUrl": "key vault Secret Identifier"
}
]
}
]
}
}
}

需要修改的地方有两处:

1) configuration内容中Certificates指纹,用第二步中的指纹值替换文件中需要修改的内容

2)同时,使用第二步中的机密标识URL来替换旧的certificateUrl值

准备好以上的内容后,既可以进行第三步,发送PUT请求把新证书更新到Cloud Service(Extended Support)

第四步:更新Cloud Service的信息,调用接口为PUT API

参考文档:https://learn.microsoft.com/en-us/rest/api/compute/cloud-services/create-or-update?view=rest-compute-2024-07-01&tabs=HTTP

PUT https:// management.chinacloudapi.cn /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/cloudServices/{cloudServiceName}?api-version=2022-04-04

 

使用第三步中同样的URL,把请求类型修改为PUT,然后把第三步修改的JSON放入Request Body。点击发送,查看请求的状态。

* 如果遇见证书格式不对错误,需要检查Key Vault Secret中保存的内容是否是正确的JSON格式。

格式不对的错误信息:

{
"error": {
"code": "CertificateImproperlyFormatted",
"message": "The data retrieved from https://XXXXXXXXX.vault.azure.cn/secrets/XXXXX/7eXXXX is not deserializable into JSON."
}
}

【END】

【Azure Cloud Service】使用Key Vault Secret添加.CER证书到Cloud Service Extended Support中的更多相关文章

  1. 【Azure Developer】记录一次使用Java Azure Key Vault Secret示例代码生成的Jar包,单独运行出现 no main manifest attribute, in target/demo-1.0-SNAPSHOT.jar 错误消息

    问题描述 创建一个Java Console程序,用于使用Azure Key Vault Secret.在VS Code中能正常Debug,但是通过mvn clean package打包为jar文件后, ...

  2. 【Azure Developer】解决Azure Key Vault管理Storage的示例代码在中国区Azure遇见的各种认证/授权问题 - C# Example Code

    问题描述 使用Azure密钥保管库(Key Vault)来托管存储账号(Storage Account)密钥的示例中,从Github中下载的示例代码在中国区Azure运行时候会遇见各种认证和授权问题, ...

  3. 【Azure Developer】Python代码通过AAD认证访问微软Azure密钥保管库(Azure Key Vault)中机密信息(Secret)

    关键字说明 什么是 Azure Active Directory?Azure Active Directory(Azure AD, AAD) 是 Microsoft 的基于云的标识和访问管理服务,可帮 ...

  4. Azure Key Vault (3) 在Azure Windows VM里使用Key Vaule

    <Windows Azure Platform 系列文章目录> 本章我们介绍如何在Azure Windows VM里面,使用.NET使用Azure Key Vault 我们需要对Key V ...

  5. 【应用服务 App Service】App Service证书导入,使用Key Vault中的证书

    问题描述 正常情况下,如果需要为应用服务安装SSL证书,可以在证书准备好的情况,通过门户上传即可,详细步骤可以参考微软官方文档(在 Azure 应用服务中添加 TLS/SSL 证书:https://d ...

  6. 【Azure Developer】使用 CURL 获取 Key Vault 中 Secrets 中的值

    问题描述 在使用CURL通过REST API获取Azure Key Vaualt的Secrets值,提示Missing Token, 问如何来生成正确的Token呢? # curl 命令 curl - ...

  7. Azure Key Vault(二)- 入门简介

    一,引言 在介绍 Azure Key Vault 之前,先简单介绍一下 HSM(硬件安全模块). -------------------- 我是分割线 -------------------- 1,什 ...

  8. 【Azure 云服务】Azure Cloud Service (Extended Support) 云服务开启诊断日志插件 WAD Extension (Windows Azure Diagnostic) 无法正常工作的原因

    问题描述 在Azure中国区上面创建一个云服务(外延支持)后,根据官方文档(在云服务(外延支持)中应用 Azure 诊断扩展: https://docs.azure.cn/zh-cn/cloud-se ...

  9. Azure China (3) 使用Visual Studio 2013证书发布Cloud Service至Azure China

    <Windows Azure Platform 系列文章目录> 之前有很多网友询问我如何通过VS发布Cloud Service至Azure China,这里我专门写篇文章,给大家详细介绍下 ...

  10. Azure Key Vault (2) 使用Azure Portal创建和查看Azure Key Vault

    <Windows Azure Platform 系列文章目录> 请注意: 文本仅简单介绍如何在Azure Portal创建和创建Key Vault,如果需要结合Application做二次 ...

随机推荐

  1. AI的发展需要有应用和落地场景 —— 李开复:传统公司看不懂技术,大模型落地B端阻碍多

    引自:https://baijiahao.baidu.com/s?id=1801826206644007472&wfr=spider&for=pc "我们投了七八家机器人企业 ...

  2. 人形机器人(humanoid)(双足机器人、四足机器人) —— 硬件测试的方法

    硬件测试的方法: 硬件的稳定性.鲁棒性.为机器人设定好固有的执行策略,然后长时间的让机器人重复执行这些既定好的动作.该种测试方法主要测试硬件的设计是否合理,硬件在长时间的运行中是否可以稳定运行而不是出 ...

  3. Ubuntu的性能模式与省电模式:进行科学计算时一定要手动将Ubuntu的CPU模式设置为性能模式

    不论是什么系统,windows11还是Ubuntu.Centos.RedHat,其运行时都有一个运行模式的概念,其实这个运行模式就是CPU的性能模式,一般可以分为性能模式和省电模式两种,当然也有介于两 ...

  4. 始智AI —— https://wisemodel.cn/ —— 试用

    清华大学的合资企业推出的服务: 始智AI -- https://wisemodel.cn/ 链接: 始智AI -- https://wisemodel.cn/ 和modelscope比相对简约,毕竟功 ...

  5. AI未来应用的新领域:具有领域知识的专属智能拼音输入法 —— 医生专属的智能输入法

    本人上个月去辽宁中医看了些小毛病,在和医生交流的时候随便小聊一下,其中一个主要的话题就是"医生是否需要练习五笔".众所周知,医生的主要工作是看病,而需要使用输入法打字写病历只是看病 ...

  6. 微信支付APIV3私钥与证书配置

    1.加载商户私钥(privateKey:私钥字符串) 这个私钥是下载证书的的:apiclient_key.pem 2.转换下单时的证书 文档:https://github.com/wechatpay- ...

  7. Java核心编程-第一卷:基础知识

    public static void main(String[] args) { BigInteger bigInteger1 = BigInteger.probablePrime(20, new R ...

  8. RabbitMq高级特性之延迟队列 通俗易懂 超详细 【内含案例】

    RabbitMq高级特性之延迟队列 介绍 消息进入队列后不能立即被消费,到达指定时间后才可被消费 实现 结合以下两种即可达到延迟队列 RabbitMq高级特性之TTL过期时间 RabbitMq高级特性 ...

  9. SMU Summer 2023 Contest Round 9(2019 山东省大学生程序设计竞赛)

    2019 山东省大学生程序设计竞赛 A. Calandar 纯模拟吧(感觉我做麻烦了(?), 就是如果问的是未来的日期,就用相隔天数取模后加上这天的星期, 如果问的是曾经的,就用这天的星期减去相隔天数 ...

  10. .NET MAUI 里,为什么 FlexLayout 这么难用?

    管中窥豹,可见一斑 Layout: FlexLayout: