Consul Config and Discovery - 只读键值存储,服务写权限

Consul Config and Discovery - Read-only key-value-store, write rights for services

我想使用 Consul 进行服务发现并作为我的微服务的分布式配置。在没有任何安全措施的情况下,我的系统工作正常,但我不希望每个用户都能够更改键值存储中的值。所以我尝试使用 Consul 的 ACL 引入安全性,但现在我的服务无法再自行注册。

我在我的 HCL 配置中将默认策略设置为 "deny" 并尝试为每个服务设置写入策略,以便它们可以在 Consul 上注册自己,并为键值存储设置读取策略,所以这些值只能通过 UI 读取。但是我的服务在注册过程中收到 403。

agent.hcl

service_prefix "" {
  policy = "write"
}
key_prefix "" {
  policy = "read"
}

领事-policy.hcl

service_prefix "" {
  policy = "write"
}
key_prefix "" {
  policy = "read"
}

我用以下命令启动了服务器:

consul agent -config-file agent.hcl -dev

并添加策略(在获取和设置 ACL 令牌之后):

consul acl policy create -name consul-server-one -rules @consul-policy.hcl
  1. 如何为 UI 中的键值存储定义只读策略和为服务定义写策略?
  2. 是否可以使用 ACL 配置启动 Consul(而不是在启动过程后交付)?
  3. 哪些 ACL 资源适合我的问题? service_prefix 和 key_prefix 是正确的选择吗?

我没有注意到您需要为策略生成令牌这一事实。

consul acl token create -description "Token description" -policy-name "consul-server-one" -token "(your global token)"

我想要使用可以通过以下方式设置的默认令牌:

consul acl set-agent-token -token "(your global token)" default (your generated token)