菜单
文档breadcrumb arrow Grafana 文档breadcrumb arrow 设置breadcrumb arrow 配置安全性breadcrumb arrow 配置数据库加密breadcrumb arrow 使用 Azure Key Vault 加密数据库密钥
企业版 开源

使用 Azure Key Vault 加密数据库密钥

您可以使用 Azure Key Vault 中的加密密钥来加密 Grafana 数据库中的密钥。

前提条件

  • 具有查看和创建 Key Vault 密钥权限的 Azure 账户,以及访问这些密钥的程序化凭据
  • 访问 Grafana 配置文件
  1. 创建保管库.

  2. 在 **Key Vault** 中使用您想要的名称创建一个密钥,类型为 **RSA**,大小为 `2048`,并赋予加密和解密权限。

  3. 注册应用程序 并为其生成客户端密钥。

  4. 为您创建的密钥保管库分配 Key Vault 访问策略

  5. 在“密钥权限”部分,设置加密和解密权限,然后单击“**保存**”。

  6. 在 Grafana 中,开启信封加密。

  7. 将您的 Azure Key Vault 详细信息添加到 Grafana 配置文件中;根据您的操作系统,通常命名为 `grafana.ini`

    a. 在配置文件中添加一个新部分,名称格式为 `[security.encryption.azurekv.<KEY-NAME>]`,其中 `<KEY-NAME>` 是在其他提供者密钥中唯一标识此密钥的任何名称。

    b. 填写以下值

    • tenant_id:您注册的应用程序的 **Directory ID**(租户)。
    • client_id:您注册的应用程序的 **Application ID**(客户端)。
    • client_secret:您在应用程序中生成的密钥的 VALUE。(请勿使用 Secret ID)。
    • key_id:您在密钥保管库中创建的密钥名称。
    • vault_uri:您的密钥保管库的 URL。

    以下是 `grafana.ini` 文件中 Azure Key Vault 提供者部分示例

    # Azure Key Vault provider setup
    ;[security.encryption.azurekv.example-encryption-key]
    # Azure Application directory ID (tenant)
    tenant_id = 1234abcd-12ab-34cd-56ef-1234567890ab
    # Azure Application application ID (client).
    client_id = 1356dfgh-12ab-34cd-56ef-3322114455cc
    # Azure Application client secret.
    client_secret = FbE4X~4Jq45ERKxx823Aheb9plBjQqHHe81Sc
    # Azure Key Vault key name.
    key_id = mysecretkey
    # Azure Key Vault uri.
    vault_uri = https://my-vault-name.vault.azure.net
  8. 使用您创建的新加密提供者密钥更新 `grafana.ini` 配置文件的 `[security]` 部分

    [security]
    # previous encryption key, used for legacy alerts, decrypting existing secrets or used as default provider when external providers are not configured
    secret_key = AaaaAaaa
    # encryption provider key in the format <PROVIDER>.<KEY-NAME>
    encryption_provider = azurekv.example-encryption-key
    # list of configured key providers, space separated
    available_encryption_providers =  azurekv.example-encryption-key
  9. 重启 Grafana.

  10. (可选)在命令行中,从 Grafana Enterprise 的根目录,使用以下命令使用新密钥重新加密 Grafana 数据库中的所有密钥

    grafana cli admin secrets-migration re-encrypt

    如果您不重新加密现有密钥,它们将保持由先前的加密密钥加密。用户仍然可以访问它们。

    **> 注意:**此过程可能需要几分钟才能完成,具体取决于数据库中的密钥数量(例如数据源)。在此过程运行时,用户可能会遇到错误,并且可能不会发送告警通知。

    **> 注意:**如果您在 Grafana 的初始设置期间更新此加密密钥,且尚未创建任何数据源或仪表盘,则无需此步骤,因为 Grafana 中没有要迁移的密钥。