From 1742379ba4892a4e5722c0dc1cccec42f71815a7 Mon Sep 17 00:00:00 2001 From: Sudarsan Reddy Date: Mon, 13 Mar 2023 09:24:20 +0000 Subject: [PATCH] TUN-7271: Return 503 status code when no ingress rules configured --- CHANGES.md | 2 +- component-tests/test_tunnel.py | 6 +++--- ingress/ingress.go | 4 ++-- ingress/origin_service.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e34f8615..d11b3578 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/component-tests/test_tunnel.py b/component-tests/test_tunnel.py index 9a193aec..d6978825 100644 --- a/component-tests/test_tunnel.py +++ b/component-tests/test_tunnel.py @@ -24,7 +24,7 @@ class TestTunnel: 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) @@ -32,9 +32,9 @@ class TestTunnel: 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) diff --git a/ingress/ingress.go b/ingress/ingress.go index 2b20fc48..926d1bf1 100644 --- a/ingress/ingress.go +++ b/ingress/ingress.go @@ -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") @@ -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) diff --git a/ingress/origin_service.go b/ingress/origin_service.go index 99953c4f..361470f2 100644 --- a/ingress/origin_service.go +++ b/ingress/origin_service.go @@ -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 {