关于 dd-audit-key-compromise
此调查技能利用 Audit Trail 数据还原疑似 Datadog API 密钥的活动。它按时间、来源、端点和破坏性操作整理事件,并提供异常信号与处置指引。
主要功能
- 01API 密钥活动时间线
- 02GeoIP、ASN 和 IP 分析
- 03端点与 HTTP 方法汇总
- 04破坏性操作检查
- 05异常信号与撤销指引
适用场景
- 01调查疑似 API 密钥泄露
- 02识别异常请求来源
- 03审查受影响资源和已删除对象
- 04查明密钥的创建时间与创建者
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ datadog-labs/ agent-skills --skill dd-audit-key-compromise安装后在 Claude Code 中输入/dd-audit-key-compromise确认已加载。
详细介绍
审计追踪:API 密钥泄露调查
还原 Datadog API 密钥的使用情况、请求来源以及受影响的资源。
前提条件
pup auth login # OAuth2 (recommended)
# or set DD_API_KEY + DD_APP_KEY with audit_logs_read scope
你需要获取可疑密钥的密钥 ID(而非密钥值)。可在 Datadog UI 的 Organization Settings > API Keys 中查找,也可以从显示 @metadata.api_key.id 的上下文中获取。
调查工作流
步骤 1 — 确定时间线
pup audit-logs search --query "@metadata.api_key.id:KEY_ID" --from 90d --limit 200 -o json \
| jq '[.data[] | {
timestamp: .attributes.timestamp,
action: .attributes.attributes.action,
event: .attributes.attributes.evt.name,
resource_type: .attributes.attributes.asset.type,
resource_id: .attributes.attributes.asset.id,
endpoint: .attributes.attributes.http.url_details.path,
method: .attributes.attributes.http.method,
ip: .attributes.attributes.network.client.ip,
city: .attributes.attributes.network.client.geoip.city.name,
country: .attributes.attributes.network.client.geoip.country.name,
asn: .attributes.attributes.network.client.geoip.as.name
}]'
步骤 2 — 按地理位置/IP 细分
pup audit-logs search --query "@metadata.api_key.id:KEY_ID" --from 90d --limit 500 -o json \
| jq '[.data[] | {
country: .attributes.attributes.network.client.geoip.country.name,
asn: .attributes.attributes.network.client.geoip.as.name,
ip: .attributes.attributes.network.client.ip
}]
| group_by(.country)
| map({
country: .[0].country,
count: length,
asns: [.[].asn] | unique,
ips: [.[].ip] | unique
})
| sort_by(-.count)'
步骤 3 — 按端点细分
pup audit-logs search --query "@metadata.api_key.id:KEY_ID" --from 90d --limit 500 -o json \
| jq '[.data[] | {
method: .attributes.attributes.http.method,
path: .attributes.attributes.http.url_details.path
}]
| group_by(.path)
| map({path: .[0].path, methods: [.[].method] | unique, count: length})
| sort_by(-.count)'
步骤 4 — 检查破坏性操作
pup audit-logs search --query "@metadata.api_key.id:KEY_ID @action:deleted" --from 90d -o json \
| jq '[.data[] | {
timestamp: .attributes.timestamp,
resource_type: .attributes.attributes.asset.type,
resource_id: .attributes.attributes.asset.id,
ip: .attributes.attributes.network.client.ip,
country: .attributes.attributes.network.client.geoip.country.name
}]'
步骤 5 — 密钥何时创建,由谁创建?
pup audit-logs search --query "@asset.type:api_key @asset.id:KEY_ID @action:created" --from 90d -o json \
| jq '[.data[] | {
created_at: .attributes.timestamp,
created_by: .attributes.attributes.usr.email,
creator_ip: .attributes.attributes.network.client.ip,
creator_country: .attributes.attributes.network.client.geoip.country.name
}]'
异常标记
| 信号 | 重要原因 |
|---|---|
| 所在国家/地区不在组织的常规基线范围内 | 可能从意外地区窃取数据 |
| ASN 属于云/VPN 提供商(AWS、Cloudflare、NordVPN 等) | 流量经代理传输;来源被隐藏 |
| 对监控器、仪表板或日志管道执行 DELETE 操作 | 可能是蓄意破坏 |
| 短时间内活动激增 | 自动抓取或批量窃取数据 |
| 在非工作时间活动 | 非工作时间访问 |
| 密钥同时从多个 IP 使用 | 密钥被共享或窃取 |
调查输出格式
Key ID: <key_id>
Created: <timestamp> by <user_email>
Active period: <first_seen> to <last_seen>
Total events: <N>
Origins:
- <Country> (<ASN>): <N> events — [NORMAL / FLAG: first-time origin]
Endpoints called (top 5):
- <METHOD> <path>: <N> calls
Destructive actions: <N> deletions — [resource types affected]
Recommended actions:
1. Revoke the key immediately if not already done
2. Review affected resources: [list]
3. Check if any deleted resources need restoration
4. Audit who else had access to this key
补救措施
在 Datadog UI 中撤销:Organization Settings > API Keys > Revoke。
也可以通过 API 操作(需要 manage_api_keys 范围):
pup api-keys delete KEY_ID
参考资料
评论
支持 Markdown