我们可以在节点或服务的领事政策中使用通配符吗

can we use wildcard in consul policy for node or service

我正在尝试设置一个 consul 支持的保管库集群。 我的 consul 集群工作正常,但是当我设置我的保险库 consul 代理时,我需要提供一个具有策略的代理令牌以在节点上具有写访问权限。

基本上,我希望我的 vault consul 代理能够注册名称仅以“vault-”开头的节点。

为此,我尝试了以下政策

agent_prefix "" {
policy = "write"
}
node "vault-*" {
policy = "write"
}
node_prefix "" {
policy = "read"
}
service_prefix "" {
policy = "read"
}
session_prefix "" {
policy = "read"
}

在我的 consul 配置中我给出了 node_name=vault-0/1/2

我尝试在我的策略中使用通配符来对特定节点名称进行写入访问并读取所有节点,但出现以下错误

代理:坐标更新被 ACL 阻止:accessorID=3db5e2e7-3264-50a9-c8f1-a5c955c5bec0

实际上,我希望我的代理能够使用特定名称注册他们的节点,只是为了识别它们。并且对于每项服务,都会有具有特定策略的单独代理令牌。

Consul的ACL系统支持定义两种类型的规则;基于前缀的规则和精确匹配规则。每 https://www.consul.io/docs/security/acl/acl-rules#rule-specification,

When using prefix-based rules, the most specific prefix match determines the action. This allows for flexible rules like an empty prefix to allow read-only access to all resources, along with some specific prefixes that allow write access or that are denied all access. Exact matching rules will only apply to the exact resource specified.

为与 Vault 服务器位于同一位置的 Consul 代理创建令牌时,您可以使用以下策略。

## consul-agent-policy.hcl

# Allow the agent write access to agent APIs on nodes starting with the name 'vault-'.
agent_prefix "vault-" {
  policy = "write"
}

# Allow registering a node into the catalog if the name starts with 'vault-'
node_prefix "vault-" {
  policy = "write"
}

# Allow the node to resolve any service in the datacenter
service_prefix "" {
  policy = "read"
}

您不需要 Consul 代理的 node:readsession:read 权限,因此我已从示例策略中删除了这些权限。

在 Consul 1.8.1+ 中,您可以使用 node identities 进一步简化此过程,如果您想锁定令牌的策略以便它只能注册一个节点,则无需创建特定于节点的 ACL 策略具体名称(例如,vault-01)。

$ consul acl token create -node-identity=vault-01:dc1