Using v1/agent/check/register
requires node:write
when registering a check for a specific service.
#5705
Labels
good first issue
A well-defined bug or improvement with sufficient context which should be approachable for new contr
theme/acls
ACL and token generation
theme/api
Relating to the HTTP API interface
theme/health-checks
Health Check functionality
type/bug
Feature does not function as expected
Overview of the Issue
Consul is requiring
node:write
on the agent node for check registration even though a service level check is being registered.Code Deep Dive
Decoding of Request
First we decode the
structs.CheckDefinition
consul/agent/agent_endpoint.go
Lines 556 to 565 in f2213f6
The check definition contains a service id in it but not a service name.
Type Conversion
Then we convert the
structs.CheckDefinition
into astructs.HealthCheck
here:consul/agent/agent_endpoint.go
Line 581 in f2213f6
This is implemented here:
consul/agent/structs/check_definition.go
Lines 42 to 58 in f2213f6
Basically it copies the
ServiceID
in theCheckDefinition
to theServiceID
in theHealthCheck
but leaves theServiceName
in theHealthCheck
untouched.Check ACLs
Back in the
AgentRegisterCheck
function we need to verify that the entity making the check registration request has adequate privileges so we invokevetCheckRegister
here:consul/agent/agent_endpoint.go
Lines 592 to 597 in f2213f6
Then within
vetCheckRegister
we check specifically for theServiceName
on theHealthCheck
here:consul/agent/acl.go
Lines 151 to 160 in f2213f6
End Result
Because the
ServiceName
was never set, theServiceID
is ignored and we are treating this as a node level check and requiringnode:write
instead of treating it as a service level check and only requiringservice:write
.Possible solution
Before calling
vetCheckRegister
we could look up theServiceID
within the local state and fixup theServiceName
on theHealthCheck
structure.The text was updated successfully, but these errors were encountered: