节点证明器
概述
节点证明器(NodeAttestor)用于在 Agent 启动时建立其身份。Server 和 Agent 都需要配置对应的证明器。
AWS IID
使用 AWS 实例身份文档进行证明。
Agent 配置
plugins {
NodeAttestor "aws_iid" {
plugin_data {
# EC2 实例身份文档端点(可选)
# identity_document_url = "http://169.254.169.254/latest/dynamic/instance-identity/document"
}
}
}
Server 配置
plugins {
NodeAttestor "aws_iid" {
plugin_data {
# 允许的 AWS 账户
account_ids = ["123456789012", "987654321098"]
# 使用 STS 区域端点
# use_sts_regional_endpoint = true
# 允许的实例配置文件
# agent_path_template = "/spire/agent/aws_iid/{{ .PluginName}}/{{ .Region }}/{{ .AccountID }}/{{ .InstanceID }}"
}
}
}
生成的 SPIFFE ID
spiffe://example.org/spire/agent/aws_iid/<account-id>/<region>/<instance-id>
GCP IIT
使用 GCP 实例身份令牌进行证明。
Agent 配置
plugins {
NodeAttestor "gcp_iit" {
plugin_data {
# 服务账户(可选)
# service_account = "my-service-account@project.iam.gserviceaccount.com"
}
}
}
Server 配置
plugins {
NodeAttestor "gcp_iit" {
plugin_data {
# 允许的项目
project_id_allow_list = ["my-project-1", "my-project-2"]
# 使用实例元数据获取服务账户
use_instance_metadata = true
# 允许的服务账户
# service_account_allow_list = ["*"]
}
}
}
Azure MSI
使用 Azure 托管服务身份进行证明。
Agent 配置
plugins {
NodeAttestor "azure_msi" {
plugin_data {
# 资源 ID(可选)
# resource_id = "https://management.azure.com/"
}
}
}
Server 配置
plugins {
NodeAttestor "azure_msi" {
plugin_data {
tenants = {
"tenant-id-1" = {
# 资源组
resource_groups = ["rg-production"]
# 允许的订阅
subscription_id_allow_list = ["sub-1", "sub-2"]
}
}
}
}
}
Kubernetes PSAT
使用 Kubernetes 投影服务账户令牌进行证明(推荐)。
Agent 配置
plugins {
NodeAttestor "k8s_psat" {
plugin_data {
# 集群名称
cluster = "production"
# 令牌路径
token_path = "/var/run/secrets/tokens/spire-agent"
}
}
}
Agent Pod 配置
apiVersion: v1
kind: Pod
spec:
containers:
- name: spire-agent
volumeMounts:
- name: spire-token
mountPath: /var/run/secrets/tokens
volumes:
- name: spire-token
projected:
sources:
- serviceAccountToken:
path: spire-agent
expirationSeconds: 7200
audience: spire-server
Server 配置
plugins {
NodeAttestor "k8s_psat" {
plugin_data {
clusters = {
"production" = {
# 允许的服务账户
service_account_allow_list = ["spire:spire-agent"]
# Kubernetes API 配置(可选)
# kube_config_file = "/path/to/kubeconfig"
# 允许的节点标签
allowed_node_label_keys = ["topology.kubernetes.io/zone"]
# 允许的 Pod 标签
allowed_pod_label_keys = ["app", "version"]
}
}
}
}
}
Kubernetes SAT
使用 Kubernetes 服务账户令牌进行证明(较老方式)。
Agent 配置
plugins {
NodeAttestor "k8s_sat" {
plugin_data {
cluster = "production"
token_path = "/var/run/secrets/kubernetes.io/serviceaccount/token"
}
}
}
Server 配置
plugins {
NodeAttestor "k8s_sat" {
plugin_data {
clusters = {
"production" = {
service_account_allow_list = ["spire:spire-agent"]
kube_config_file = "/path/to/kubeconfig"
}
}
}
}
}
Join Token
使用一次性令牌进行证明,适用于初始引导。
Agent 配置
plugins {
NodeAttestor "join_token" {
plugin_data {}
}
}
Server 配置
plugins {
NodeAttestor "join_token" {
plugin_data {}
}
}
使用方法
# 生成 token
spire-server token generate -spiffeID spiffe://example.org/myagent -ttl 600
# 启动 Agent 时使用
spire-agent run -config agent.conf -joinToken <token>
X509 POP
使用 X.509 证书持有证明进行证明。
Agent 配置
plugins {
NodeAttestor "x509pop" {
plugin_data {
# 私钥路径
private_key_path = "/opt/spire/conf/agent/agent-key.pem"
# 证书链路径
certificate_path = "/opt/spire/conf/agent/agent-cert.pem"
}
}
}
Server 配置
plugins {
NodeAttestor "x509pop" {
plugin_data {
# CA 证书包
ca_bundle_path = "/opt/spire/conf/server/agent-ca.pem"
# Agent 路径模板
# agent_path_template = "/x509pop/{{ .Subject.CommonName }}"
}
}
}
SSH POP
使用 SSH 证书持有证明进行证明。
Agent 配置
plugins {
NodeAttestor "sshpop" {
plugin_data {
host_cert_path = "/etc/ssh/ssh_host_rsa_key-cert.pub"
host_key_path = "/etc/ssh/ssh_host_rsa_key"
}
}
}
Server 配置
plugins {
NodeAttestor "sshpop" {
plugin_data {
cert_authorities = ["/opt/spire/conf/server/ssh-ca.pub"]
cert_authorities_path = "/opt/spire/conf/server/ssh-cas/"
# 指定 CA 指纹
# ca_fingerprints = ["SHA256:..."]
}
}
}
选择建议
选择指南
Kubernetes: 优先使用
k8s_psat,它比k8s_sat更安全云环境: 使用对应云厂商的证明器(
aws_iid、gcp_iit、azure_msi)初始引导: 使用
join_token进行一次性引导持久环境: 使用
x509pop或sshpop进行持久证明