菜单
企业版 开源

配置 Grafana 秘密扫描和通知

通过 Grafana,您可以使用 GitHub Secret Scanning 服务来确定您的服务账号令牌是否已在 GitHub 上泄露。

当 GitHub Secret Scanning 检测到 Grafana 秘密时,其哈希值会存储在 Grafana Labs 的秘密扫描服务中。

无论是在本地还是在云端,Grafana 实例都可以使用此服务验证该实例生成的令牌是否已被公开。此验证通过比较令牌的哈希值与已泄露令牌的哈希值来完成。

如果服务检测到泄露的令牌,它会立即撤销该令牌,使其失效,并记录事件日志。

注意

如果 revoke 选项被禁用,服务只会向配置的网络钩子 (webhook) URL 发送通知并记录事件日志。令牌不会自动撤销。

您还可以配置服务向网络钩子 (webhook) URL 发送出站网络钩子通知。

通知包含一个 JSON 有效负载,其中包含以下数据

json
{
  "alert_uid": "c9ce50a1-d66b-45e4-9b5d-175766cfc026",
  "link_to_upstream_details": <URL to token leak>,
  "message": "Token of type grafana_service_account_token with name
sa-the-toucans has been publicly exposed in <URL to token leak>.
Grafana has revoked this token",
  "state": "alerting",
  "title": "SecretScan Alert: Grafana Token leaked"
}

注意

秘密扫描默认禁用。启用后才会进行出站连接。

开始之前

配置秘密扫描

  1. 打开 Grafana 配置文件。

  2. [secretscan] 部分,更新以下参数

ini
[secretscan]
# Enable secretscan feature
enabled = true

# Whether to revoke the token if a leak is detected or just send a notification
revoke = true

保存配置文件并重启 Grafana。

配置出站网络钩子通知

  1. 创建一个类型为 Webhook 的排班集成并设置告警。要了解如何创建 Grafana OnCall 集成,请参阅Grafana OnCall 的入站网络钩子集成

  2. 复制新集成的网络钩子 URL。

  3. 打开 Grafana 配置文件。

  4. [secretscan] 部分,更新以下参数,将 URL 替换为您在步骤 2 中复制的网络钩子 URL。

ini
[secretscan]
# URL to send a webhook payload in oncall format
oncall_url = https://example.url/integrations/v1/webhook/3a359nib9eweAd9lAAAETVdOx/

保存配置文件并重启 Grafana。