Skip to content

Commit

Permalink
fix: erroneous error message for host validation
Browse files Browse the repository at this point in the history
when crafting an ingress YAML file by hand its easy to write the following by mistake:
```yaml
ingress:
  - hostname: https://example.com
    service: http://localhost:50100
  - service: http_status:404
```

`cloudflared` would report the error: `Hostname cannot contain a port`

this confused me for a few minutes before i compared two configs and saw my mistake. this change introduces a check prior to port splitting to see if the hostname contains a protocol and reports a relevant error
  • Loading branch information
andrewmd5 committed Jun 27, 2023
1 parent 31f424d commit 9d0e7b5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
errLastRuleNotCatchAll = errors.New("The last ingress rule must match all URLs (i.e. it should not have a hostname or path filter)")
errBadWildcard = errors.New("Hostname patterns can have at most one wildcard character (\"*\") and it can only be used for subdomains, e.g. \"*.example.com\"")
errHostnameContainsPort = errors.New("Hostname cannot contain a port")
errHostnameContainsProtocol = errors.New("Hostname cannot contain a protocol (e.g. http://, https:/, etc.)")
ErrURLIncompatibleWithIngress = errors.New("You can't set the --url flag (or $TUNNEL_URL) when using multiple-origin ingress rules")
)

Expand Down Expand Up @@ -359,6 +360,10 @@ func validateIngress(ingress []config.UnvalidatedIngressRule, defaults OriginReq
}

func validateHostname(r config.UnvalidatedIngressRule, ruleIndex, totalRules int) error {
// Ensure the hostname doesn't contain a protocol so a less confusing error is returned.
if u, e := url.Parse(r.Hostname); e == nil && isHTTPService(u) {
return errHostnameContainsProtocol
}
// Ensure that the hostname doesn't contain port
_, _, err := net.SplitHostPort(r.Hostname)
if err == nil {
Expand Down

0 comments on commit 9d0e7b5

Please sign in to comment.