你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Azure IoT MQ 预览版中使用 Azure Key Vault 或 Kubernetes 机密管理机密

重要

Azure IoT 操作预览版(由 Azure Arc 启用)当前处于预览状态。 不应在生产环境中使用此预览版软件。

有关 beta 版本、预览版或尚未正式发布的版本的 Azure 功能所适用的法律条款,请参阅 Microsoft Azure 预览版的补充使用条款

可以使用 Azure Key Vault 管理 Azure IoT MQ 预览版分布式 MQTT 代理(而不是 Kubernetes 机密)的机密。 本文介绍了如何为代理设置密钥保管库,并使用它管理机密。

先决条件

使用 Azure 密钥保管库进行机密管理

无论在哪里使用 Kubernetes 机密 (secretName),都可以使用keyVault字段。 下表描述了keyVault字段的属性。

properties 必选 说明
保管库 指定包含机密的 Azure 密钥保管库。
vault.name 指定 Azure 密钥保管库的名称。 要从 Azure 门户获取密钥保管库名称,请导航到密钥保管库实例,并从“概述”页复制该名称。
vault.directoryId 指定 Microsoft Entra 租户 ID。 要从 Azure 门户获取租户 ID,请导航到密钥保管库实例,并从“概述”页复制租户 ID。
vault.credentials.servicePrincipalLocalSecretName 指定包含服务主体凭据的机密的名称。
vaultSecret 是,使用常规 Key Vault 机密时 指定 Azure 密钥保管库中的机密。
vaultSecret.name 指定机密的名称。
vaultSecret.version 指定机密的版本。
vaultCert 是,使用 Key Vault 证书时 指定 Azure Key Vault 中的证书。
vaultCert.name 指定证书机密的名称。
vaultCert.version 指定证书机密的版本。
vaultCaChainSecret 是,使用证书链时 指定 Azure Key Vault 中的证书链。
vaultCaChainSecret.name 指定证书链的名称。
vaultCaChainSecret.version 指定证书链的版本。
username 仅用于事件中心 Kafka 连接器,请参阅在 Azure IoT MQ 与 Azure 事件中心或 Kafka 之间发送和接收消息

使用的机密类型决定了可以使用以下哪些字段:

  • vaultSecret:使用常规机密时使用此字段。 例如,可以使用此字段结合 usernamePassword 字段配置 BrokerAuthentication 资源
  • vaultCert:如果配合使用证书类型机密与客户端证书和密钥,请使用此字段。 例如,可以使用此字段在 BrokerListener 上启用 TLS
  • vaultCaChainSecret:如果需要向远程服务器提供包含所有额外中间证书或根证书的完整证书链,请使用此字段。 例如,可以使用此字段结合 remoteBrokerConnection 字段配置 MqttBridgeConnector 资源。 若要使用此字段,请将不带私钥的 X.509 证书(PEM 格式)作为多行常规机密(不是证书类型)导入到 Key Vault。 除了具有客户端证书和私钥的 vaultCert 外,还应使用此字段。

示例

例如,要创建使用 Azure 密钥保管库作为服务器证书机密的 TLS BrokerListener,请使用以下 YAML:

apiVersion: mq.iotoperations.azure.com/v1beta1
kind: BrokerListener
metadata:
  name: tls-listener-manual
  namespace: azure-iot-operations
spec:
  brokerRef: broker
  authenticationEnabled: true
  authorizationEnabled: false
  port: 8883
  tls:
    keyVault:
      vault:
        name: my-key-vault
        directoryId: <AKV directory ID>
        credentials:
          servicePrincipalLocalSecretName: aio-akv-sp
      vaultCert:
        name: my-server-certificate
        # version: 939ecc2...

下一个示例演示了如何将 Azure 密钥保管库用于 BrokerAuthentication 资源中的usernamePassword字段:

apiVersion: mq.iotoperations.azure.com/v1beta1
kind: BrokerAuthentication
metadata:
  name: my-authentication
  namespace: azure-iot-operations
spec:
  listenerRef: 
    - tls-listener-manual
  authenicationMethods:
    - usernamePassword:
        keyVault:
          vault:
            name: my-key-vault
            directoryId: <AKV directory ID>
            credentials:
              servicePrincipalLocalSecretName: aio-akv-sp
          vaultSecret:
            name: my-username-password-db
            # version: 939ecc2...

此示例演示了如何将 Azure 密钥保管库用于 MQTT 桥接远程代理凭据:

apiVersion: mq.iotoperations.azure.com/v1beta1
kind: MqttBridgeConnector
metadata:
  name: my-bridge
  namespace: azure-iot-operations
spec:
  image:
    repository: mcr.microsoft.com/azureiotoperations/mqttbridge
    tag: 0.4.0-preview
    pullPolicy: IfNotPresent
  protocol: v5
  bridgeInstances: 1
  remoteBrokerConnection:
    endpoint: example.broker.endpoint:8883
    tls:
      tlsEnabled: true
      trustedCaCertificateConfigMap: my-ca-certificate
    authentication:
      x509:
        keyVault:
          vault:
            name: my-key-vault
            directoryId: <AKV directory ID>
            credentials:
              servicePrincipalLocalSecretName: aio-akv-sp
          vaultCaChainSecret:
            name: my-remote-broker-certificate
            # version: 939ecc2...