本文为 SPIRE 官方文档 plugin_server_nodeattestor_http_challenge.md 的中文译本,以英文原文为准。 🔗 穿越源码分析:Server 详解 · NodeAttestor
Server 插件:NodeAttestor "http_challenge"
必须与 Agent 侧 http_challenge 插件配合使用
http_challenge 插件通过 HTTP 进行握手(handshake),以确保 agent 运行在一个有效的 DNS 名称上。
插件生成的 SPIFFE ID 基于被认证的 DNS 名称。SPIFFE ID 的格式为:
xml
spiffe://<trust_domain>/spire/agent/http_challenge/<hostname>| Configuration | Description | Default |
|---|---|---|
allowed_dns_patterns | 一组正则表达式,用于匹配被认证的主机名(hostname)。若无任何一条匹配,认证将失败。若不设置,则允许所有主机名。 | |
required_port | 设为某个端口号后,要求客户端只能监听该端口。若不设置,则允许所有端口号。 | |
allow_non_root_ports | 设为 true 时,允许 agent 使用 >= 1024 的端口作为 advertised_port。 | true |
tofu | 对成功的挑战启用首次使用即信任(Trust on first use)。仅当 allow_non_root_ports=false 或 required_port < 1024 时才可禁用。 | true |
一份示例配置:
hcl
NodeAttestor "http_challenge" {
plugin_data {
# 仅匹配以 p 开头、后接一个数字、并以 example.com 结尾的主机。例如:'p1.example.com'
allowed_dns_patterns = ["p[0-9]\.example\.com"]
# 仅允许客户端使用 80 端口
required_port = 80
# 修改 agent 的 SPIFFE ID 格式
# agent_path_template = "/spire/agent/http_challenge/{{ .Hostname }}"
}
}Selectors(选择器)
| Selector | Example | Description |
|---|---|---|
| Hostname | http_challenge:hostname:p1.example.com | 主体(Subject)的主机名 |
Security Considerations(安全考量)
通常情况下,节点上的任何用户都能访问 TCP 端口。因此,节点上的非 agent 代码有可能向 SPIRE Server 完成认证,从而获取该节点被授权运行的任意工作负载身份(workload identity)。
http_challenge 节点认证器实现了多项特性来缓解这一风险。
首次使用即信任(Trust On First Use,简称 TOFU)便是其中一项选项。启用后,对于任意给定节点,认证只能发生一次,后续的认证尝试都将被拒绝。
在启用 TOFU 的情况下,非 agent 代码仍有可能先于 SPIRE Agent 完成节点认证;不过这种情况很容易被迅速发现,因为此时 SPIRE Agent 将无法启动,并且 SPIRE Agent 和 SPIRE Server 都会记录该事件。此类情况应作为可能的安全事件加以调查。
你还可以要求端口必须是仅受信任用户(例如 root)才能打开的受信任端口(端口号 < 1024)。