管理 Service Fabric 网格应用程序机密
重要
Azure Service Fabric 网格的预览版已停用。 不允许再通过 Service Fabric 网格 API 进行新的部署。 对现有部署的支持将会持续到 2021 年 4 月 28 日。
有关详细信息,请参阅 Azure Service Fabric 网格预览版停用。
Service Fabric 网格支持将机密作为 Azure 资源。 Service Fabric 网格机密可以是任何敏感文本信息,例如存储连接字符串、密码或应该安全存储和传输的其他值。 本文展示了如何使用 Service Fabric Secure Store Service 来部署和维护机密。
网格应用程序机密包括:
- 一个机密资源,它是一个用于存储文本机密的容器。 机密资源中包含的机密将安全地进行存储和传输。
- 存储在机密资源容器中的一个或多个机密/值资源。 每个机密/值资源都由版本号予以区分。 无法修改机密/值资源的版本,只能追加新版本。
管理机密包括以下步骤:
- 在 Azure 资源模型 YAML 或 JSON 文件中,使用 inlinedValue 种类和 SecretsStoreRef contentType 定义来声明一个网格机密资源。
- 在 Azure 资源模型 YAML 或 JSON 文件中,声明将存储在机密资源(来自步骤 1)中的网格机密/值资源。
- 修改网格应用程序以引用网格机密值。
- 部署或滚动升级网格应用程序以使用机密值。
- 使用 Azure "az" CLI 命令进行 Secure Store Service 生命周期管理。
声明网格机密资源
网格机密资源是在 Azure 资源模型 JSON 或 YAML 文件中使用 inlinedValue 种类定义声明的。 网格机密资源支持源自 Secure Store Service 的机密。
下面是有关如何在 JSON 文件中声明网格机密资源的示例:
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "WestUS",
"metadata": {
"description": "Location of the resources (e.g. westus, eastus, westeurope)."
}
}
},
"sfbpHttpsCertificate": {
"type": "string",
"metadata": {
"description": "Plain Text Secret Value that your container ingest"
}
},
"resources": [
{
"apiVersion": "2018-07-01-preview",
"name": "sfbpHttpsCertificate.pfx",
"type": "Microsoft.ServiceFabricMesh/secrets",
"location": "[parameters('location')]",
"dependsOn": [],
"properties": {
"kind": "inlinedValue",
"description": "SFBP Application Secret",
"contentType": "text/plain",
}
}
]
}
下面是有关如何在 YAML 文件中声明网格机密资源的示例:
services:
- name: helloWorldService
properties:
description: Hello world service.
osType: linux
codePackages:
- name: helloworld
image: myapp:1.0-alpine
resources:
requests:
cpu: 2
memoryInGB: 2
endpoints:
- name: helloWorldEndpoint
port: 8080
secrets:
- name: MySecret.txt
description: My Mesh Application Secret
secret_type: inlinedValue
content_type: SecretStoreRef
value: mysecret
replicaCount: 3
networkRefs:
- name: mynetwork
声明网格机密/值资源
网格机密/值资源依赖于在前面的步骤中定义的网格机密资源。
关于 "resources" 部分中 "value:" 与 "name:" 字段之间的关系:由冒号分隔的 "name:" 字符串的第二部分是用于机密的版本号,冒号之前的名称需要与它依赖的网格机密值匹配。 例如,对于元素 name: mysecret:1.0
,版本号是 1.0,并且名称 mysecret
必须与前面定义的 "value": "mysecret"
匹配。
下面是有关如何在 JSON 文件中声明网格机密/值资源的示例:
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "WestUS",
"metadata": {
"description": "Location of the resources (e.g. westus, eastus, westeurope)."
}
}
},
"sfbpHttpsCertificate": {
"type": "string",
"metadata": {
"description": "Plain Text Secret Value that your container ingest"
}
},
"resources": [
{
"apiVersion": "2018-07-01-preview",
"name": "sfbpHttpsCertificate.pfx",
"type": "Microsoft.ServiceFabricMesh/secrets",
"location": "[parameters('location')]",
"dependsOn": [],
"properties": {
"kind": "inlinedValue",
"description": "SFBP Application Secret",
"contentType": "text/plain",
}
},
{
"apiVersion": "2018-07-01-preview",
"name": "sfbpHttpsCertificate.pfx/2019.02.28",
"type": "Microsoft.ServiceFabricMesh/secrets/values",
"location": "[parameters('location')]",
"dependsOn": [
"Microsoft.ServiceFabricMesh/secrets/sfbpHttpsCertificate.pfx"
],
"properties": {
"value": "[parameters('sfbpHttpsCertificate')]"
}
}
],
}
下面是有关如何在 YAML 文件中声明网格机密/值资源的示例:
services:
- name: helloWorldService
properties:
description: Hello world service.
osType: linux
codePackages:
- name: helloworld
image: myapp:1.0-alpine
resources:
requests:
cpu: 2
memoryInGB: 2
endpoints:
- name: helloWorldEndpoint
port: 8080
Secrets:
- name: MySecret.txt
description: My Mesh Application Secret
secret_type: inlinedValue
content_type: SecretStoreRef
value: mysecret
- name: mysecret:1.0
description: My Mesh Application Secret Value
secret_type: value
content_type: text/plain
value: "P@ssw0rd#1234"
replicaCount: 3
networkRefs:
- name: mynetwork
修改网格应用程序以引用网格机密值
要使用 Secure Store Service 机密值,Service Fabric 网格应用程序需要知道以下两个字符串:
- Microsoft.ServiceFabricMesh/Secrets.name 包含文件的名称,并且将包含明文形式的机密值。
- Windows 或 Linux 环境变量“Fabric_SettingPath”包含可以从中访问 Secure Store Service 机密值所在文件的目录路径。 对于 Windows 承载的网格应用程序,这是“C:\Settings”;对于 Linux 承载的网格应用程序,这是“/var/settings”。
部署或滚动升级网格应用程序以使用机密值
创建机密和/或带有版本的机密/值仅限于资源模型声明的部署。 创建这些资源的唯一方法是使用 az mesh deployment 命令传递资源模型 JSON 或 YAML 文件,如下所示:
az mesh deployment create –-<template-file> or --<template-uri>
用于管理 Secure Store Service 生命周期的 Azure CLI 命令
创建新的机密资源
az mesh deployment create –-<template-file> or --<template-uri>
传递 template-file 或 template-uri(但不能同时传递两者)。
例如:
- az mesh deployment create --c:\MyMeshTemplates\SecretTemplate1.txt
- az mesh deployment create --https://www.fabrikam.com/MyMeshTemplates/SecretTemplate1.txt
显示机密
返回机密的说明(但不是值)。
az mesh secret show --Resource-group <myResourceGroup> --secret-name <mySecret>
删除机密
- 当机密正在由某个网格应用程序引用时,无法删除机密。
- 删除机密资源会删除所有机密/资源版本。
az mesh secret delete --Resource-group <myResourceGroup> --secret-name <mySecret>
列出订阅中的机密
az mesh secret list
列出资源组中的机密
az mesh secret list -g <myResourceGroup>
列出某个机密的所有版本
az mesh secretvalue list --Resource-group <myResourceGroup> --secret-name <mySecret>
显示机密版本值
az mesh secretvalue show --Resource-group <myResourceGroup> --secret-name <mySecret> --version <N>
删除机密版本值
az mesh secretvalue delete --Resource-group <myResourceGroup> --secret-name <mySecret> --version <N>
后续步骤
若要详细了解 Service Fabric 网格,请阅读概述: