-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document Consul ACL requirements and integration #11962
Comments
Hi @ygersie 👋 That's actually working as intended. Nomad will use the Consul token set in the agent to register services. Then token passed using
If you need to isolate access to services in Consul you can Consul Namespaces, which is a Consul Enterprise feature. We ave an internal ticket to track improvements to Consul registration, so I'm going to close this one, but feel free to ask any other question you may have 🙂 |
Hey @lgfa29 thanks for that clarification although I have to say the docs aren't very descriptive on the consul_token use. There's mentioned that this token is only used for Consul Connect enabled services, but how exactly? Even in Consul enterprise, how would one prevent a random job from registering a Consul service it shouldn't? I kind of assumed that passing the Consul token, which would have an acl policy that limits service registration to a specific service name, would provide that functionality. That's why I thought this was a bug. |
Okay after some experimentation I understand better, the Consul token is used to verify if a user is allowed to create a new service. The docs could definitely use a bit more clarification. The Nomad agent Consul token needs There is however a bug in there when using interpolation. $ nomad job run example-service.hcl
Error submitting job: Unexpected response code: 500 (rpc error: job-submitter consul token denied: insufficient Consul ACL permissions to write service "${NOMAD_JOB_NAME}") The service {
name = "${NOMAD_JOB_NAME}"
port = "nc"
check {
type = "tcp"
interval = "3s"
timeout = "1s"
}
} isn't expanded correctly. |
Ah good catch! I believe this is the same issue described in #9741 which is also in our backlog. Would you mind giving it a 👍? I will re-open this issue and rename it to focus on improving our docs around Consul ACL integration. The context you provided will be very valuable. |
Starting in Nomad 1.7.0-beta.1 we've deprecated the use of Consul tokens in the Nomad agent configuration for purposes of giving workload access to Consul KV. Nomad will use workload identities to sign into Consul for purposes of getting Consul tokens for those workloads. As part of that work we've documented the new requirements. |
Nomad version
v1.2.3
Issue
The Consul token passed in either the job using
consul_token
, through the CLI using-consul-token=<token>
or using the env varCONSUL_HTTP_TOKEN
doesn't seem to be used by Nomad to register services and healthchecks.Reproduction steps
I've setup a Nomad cluster with a Consul token that has the following policy associated:
And passed to Nomad the following Consul config:
I then setup a Consul ACL for my example service:
And a token for my example service:
To verify this token works I've used the following consul service definition:
Now registering and later deregistering this service to test:
So the newly created token works as expected. Now deploy the following job:
I'd expect this would register the Consul service
example-netcat
with the provided token but I get the following in the Nomad log file:2022-01-31T14:45:04.486+0100 [WARN] consul.sync: failed to update services in Consul: error="Unexpected response code: 403 (Permission denied: Missing service:write on example-netcat)"
So as you would expect based on the above log entry no services nor healthchecks are registered:
To make it even more unexpected the job deployment succeeded anyway, while the default update stanza should make sure that health checks are
passing
for min_healthy_time. In this case the health check was never created so I'd expect the deployment to fail as well.TLDR
It seems that when the Nomad agent is configured to use a Consul token this token will always be used for registering services and healthchecks part of a Nomad job. The workaround is to create a Consul token with a policy that allows to register any service to be used by the Nomad agent, which is not a secure way of setting up a hashi cluster.
Am I misunderstanding how this should work or is this a bug?
The text was updated successfully, but these errors were encountered: