`check.port` field is not validated to match label
- Dominant language
- Go
- Stars
- 17k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 105
Description
The docs for [`check.port`](https://developer.hashicorp.com/nomad/docs/job-specification/check#port) say:
> [port](https://developer.hashicorp.com/nomad/docs/job-specification/check#port) (string: ) - Specifies the label of the port on which the check will be performed. Note this is the label of the port and not the port number unless address_mode = driver. The port label must match one defined in the [network](https://developer.hashicorp.com/nomad/docs/job-specification/network) block. If a port value was declared on the service, this will inherit from that value if not supplied. If supplied, this value takes precedence over the service.port value. This is useful for services which operate on multiple ports. grpc, http, and tcp checks require a port while script checks do not. Checks will use the host IP and ports by default. In Nomad 0.7.1 or later numeric ports may be used if address_mode="driver" is set on the check.
The [`validateCheckPort`](https://github.com/hashicorp/nomad/blob/v1.7.0-beta.1/nomad/structs/services.go#L801-L806) function doesn't enforce this however. So it's possible when using the default `host` address mode to set a numeric port value which will get registered but never actually work. We should validate against this case.
It looks like from a report by @ksatirli that the check won't actually work if it's misconfigured today, so it's possible there's no backwards compatibility concerns here. But let's double-check on that when we fix this.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in nomad/structs/services.go at validateCheckPort and trace how check.port is validated for the default host address mode versus driver mode. Confirm the expected behavior against the issue description, including whether rejecting numeric host-mode values has compatibility concerns; done means invalid values are rejected while supported driver-mode values remain valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100