Skip to content

Commit

Permalink
TUN-7271: Return 503 status code when no ingress rules configured
Browse files Browse the repository at this point in the history
  • Loading branch information
sudarshan-reddy committed Mar 13, 2023
1 parent 9c15f31 commit 1742379
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 2023.3.1
### Breaking Change
- Running a tunnel without ingress rules defined in configuration file nor from the CLI flags will no longer provide a default ingress rule to localhost:8080 and instead will return HTTP response code 502 for all incoming HTTP requests.
- Running a tunnel without ingress rules defined in configuration file nor from the CLI flags will no longer provide a default ingress rule to localhost:8080 and instead will return HTTP response code 503 for all incoming HTTP requests.

## 2023.2.2
### Notices
Expand Down
6 changes: 3 additions & 3 deletions component-tests/test_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ def test_tunnel_url(self, tmp_path, component_tests_config):

def test_tunnel_no_ingress(self, tmp_path, component_tests_config):
'''
Running a tunnel with no ingress rules provided from either config.yaml or CLI will still work but return 502
Running a tunnel with no ingress rules provided from either config.yaml or CLI will still work but return 503
for all incoming requests.
'''
config = component_tests_config(cfd_mode=CfdModes.NAMED, run_proxy_dns=False, provide_ingress=False)
LOGGER.debug(config)
with start_cloudflared(tmp_path, config, cfd_args=["run"], new_process=True):
wait_tunnel_ready(require_min_connections=4)
resp = send_request(config.get_url()+"/")
assert resp.status_code == 502, "Expected cloudflared to return 502 for all requests with no ingress defined"
assert resp.status_code == 503, "Expected cloudflared to return 503 for all requests with no ingress defined"
resp = send_request(config.get_url()+"/test")
assert resp.status_code == 502, "Expected cloudflared to return 502 for all requests with no ingress defined"
assert resp.status_code == 503, "Expected cloudflared to return 503 for all requests with no ingress defined"


@retry(stop_max_attempt_number=MAX_RETRIES, wait_fixed=BACKOFF_SECS * 1000)
Expand Down
4 changes: 2 additions & 2 deletions ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

var (
ErrNoIngressRules = errors.New("The config file doesn't contain any ingress rules")
ErrNoIngressRulesCLI = errors.New("No ingress rules were defined in provided config (if any) nor from the cli, cloudflared will return 502 for all incoming HTTP requests")
ErrNoIngressRulesCLI = errors.New("No ingress rules were defined in provided config (if any) nor from the cli, cloudflared will return 503 for all incoming HTTP requests")
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")
Expand Down Expand Up @@ -129,7 +129,7 @@ func parseCLIIngress(c *cli.Context, allowURLFromArgs bool) (Ingress, error) {
return ing, err
}

// newDefaultOrigin always returns a 502 response code to help indicate that there are no ingress
// newDefaultOrigin always returns a 503 response code to help indicate that there are no ingress
// rules setup, but the tunnel is reachable.
func newDefaultOrigin(c *cli.Context, log *zerolog.Logger) Ingress {
noRulesService := newDefaultStatusCode(log)
Expand Down
4 changes: 2 additions & 2 deletions ingress/origin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ 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
// default status code (503) 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}
return statusCode{code: 503, defaultResp: true, log: log}
}

func (o *statusCode) String() string {
Expand Down

0 comments on commit 1742379

Please sign in to comment.