TUN-7259: Add warning for missing ingress rules

Providing no ingress rules in the configuration file or via the CLI will now provide a warning and return 502 for all incoming HTTP requests.
This commit is contained in:
Devin Carr
2023-03-09 15:23:11 -08:00
parent ede3c8e056
commit 7b8b3f73e7
13 changed files with 255 additions and 39 deletions

View File

@@ -247,13 +247,26 @@ func (o helloWorld) MarshalJSON() ([]byte, error) {
// Typical use-case is "user wants the catch-all rule to just respond 404".
type statusCode struct {
code int
// Set only when the user has not defined any ingress rules
defaultResp bool
log *zerolog.Logger
}
func newStatusCode(status int) statusCode {
return statusCode{code: status}
}
// default status code (502) that is returned for requests to cloudflared that don't have any ingress rules setup
func newDefaultStatusCode(log *zerolog.Logger) statusCode {
return statusCode{code: 502, defaultResp: true, log: log}
}
func (o *statusCode) String() string {
// returning a different service name can help with identifying users via config that don't setup ingress rules
if o.defaultResp {
return "default_http_status:502"
}
return fmt.Sprintf("http_status:%d", o.code)
}