From f16106b3a69d0ea31c87eb554defc54d16f1032a Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Thu, 15 Oct 2026 17:58:02 -0700 Subject: [PATCH] chore(ingress): remove unreachable code - sanitize_client_max_body_size, sanitize_proxy_timeout, sanitize_proxy_buffer_size and sanitize_proxy_buffers are left over from the nginx days; only their tests called them. entrypoint.sh just warns that those settings are ignored. - The `*)` branch of the final CHALLENGE_TYPE dispatch in entrypoint.sh cannot run: the value is validated at the top of the script. Signed-off-by: Kevin Wang --- .../dstack-ingress/scripts/entrypoint.sh | 4 -- .../dstack-ingress/scripts/functions.sh | 57 ------------------- .../scripts/tests/test_sanitizers.sh | 34 ----------- 3 files changed, 95 deletions(-) diff --git a/custom-domain/dstack-ingress/scripts/entrypoint.sh b/custom-domain/dstack-ingress/scripts/entrypoint.sh index bc9fc01..6f761fb 100644 --- a/custom-domain/dstack-ingress/scripts/entrypoint.sh +++ b/custom-domain/dstack-ingress/scripts/entrypoint.sh @@ -186,8 +186,4 @@ case "$CHALLENGE_TYPE" in tls-alpn-01) exec /scripts/tlsalpn.sh "$@" ;; - *) - echo "Error: invalid CHALLENGE_TYPE '$CHALLENGE_TYPE' (expected dns-01 or tls-alpn-01)" >&2 - exit 1 - ;; esac diff --git a/custom-domain/dstack-ingress/scripts/functions.sh b/custom-domain/dstack-ingress/scripts/functions.sh index 7e19935..68c767f 100644 --- a/custom-domain/dstack-ingress/scripts/functions.sh +++ b/custom-domain/dstack-ingress/scripts/functions.sh @@ -69,20 +69,6 @@ sanitize_target_endpoint() { fi } -sanitize_client_max_body_size() { - local candidate="$1" - if [ -z "$candidate" ]; then - echo "" - return 0 - fi - if [[ "$candidate" =~ ^[0-9]+[kKmMgG]?$ ]]; then - echo "$candidate" - else - echo "Warning: Ignoring invalid CLIENT_MAX_BODY_SIZE value: $candidate" >&2 - echo "" - fi -} - sanitize_dns_label() { local candidate="$1" if [ -z "$candidate" ]; then @@ -173,49 +159,6 @@ sanitize_boolean() { esac } -sanitize_proxy_timeout() { - local candidate="$1" - if [ -z "$candidate" ]; then - echo "" - return 0 - fi - if [[ "$candidate" =~ ^[0-9]+[smh]?$ ]]; then - echo "$candidate" - else - echo "Warning: Ignoring invalid proxy timeout value: $candidate" >&2 - echo "" - fi -} - -sanitize_proxy_buffer_size() { - local candidate="$1" - if [ -z "$candidate" ]; then - echo "" - return 0 - fi - if [[ "$candidate" =~ ^[0-9]+[kKmM]?$ ]]; then - echo "$candidate" - else - echo "Warning: Ignoring invalid proxy buffer size value: $candidate" >&2 - echo "" - fi -} - -sanitize_proxy_buffers() { - local candidate="$1" - if [ -z "$candidate" ]; then - echo "" - return 0 - fi - # Format: number size (e.g., "4 256k") - if [[ "$candidate" =~ ^[0-9]+[[:space:]]+[0-9]+[kKmM]?$ ]]; then - echo "$candidate" - else - echo "Warning: Ignoring invalid proxy buffers value: $candidate (expected format: 'number size', e.g., '4 256k')" >&2 - echo "" - fi -} - txt_record_name() { local domain="$1" if [[ "$domain" == \*.* ]]; then diff --git a/custom-domain/dstack-ingress/scripts/tests/test_sanitizers.sh b/custom-domain/dstack-ingress/scripts/tests/test_sanitizers.sh index 39f1513..06239cf 100644 --- a/custom-domain/dstack-ingress/scripts/tests/test_sanitizers.sh +++ b/custom-domain/dstack-ingress/scripts/tests/test_sanitizers.sh @@ -57,14 +57,8 @@ assert_equal "$(sanitize_target_endpoint grpc://svc:50051)" "grpc://svc:50051" " assert_equal "$(sanitize_target_endpoint app:80)" "app:80" "sanitize_target_endpoint accepts bare host:port" assert_equal "$(sanitize_target_endpoint app-main)" "app-main" "sanitize_target_endpoint accepts bare hostname" assert_equal "$(sanitize_target_endpoint 10.0.0.1:8080)" "10.0.0.1:8080" "sanitize_target_endpoint accepts IP:port" -assert_equal "$(sanitize_client_max_body_size 50m)" "50m" "sanitize_client_max_body_size accepts suffix" assert_equal "$(sanitize_dns_label test_label)" "test_label" "sanitize_dns_label accepts lowercase" assert_equal "$(sanitize_dns_label test-label)" "test-label" "sanitize_dns_label accepts hyphen" -assert_equal "$(sanitize_proxy_timeout 30)" "30" "sanitize_proxy_timeout accepts numeric value" -assert_equal "$(sanitize_proxy_timeout 30s)" "30s" "sanitize_proxy_timeout accepts seconds suffix" -assert_equal "$(sanitize_proxy_timeout 5m)" "5m" "sanitize_proxy_timeout accepts minutes suffix" -assert_equal "$(sanitize_proxy_timeout 1h)" "1h" "sanitize_proxy_timeout accepts hours suffix" -assert_equal "$(sanitize_proxy_timeout '')" "" "sanitize_proxy_timeout accepts empty value" assert_equal "$(sanitize_positive_integer 4096 MAXCONN)" "4096" "sanitize_positive_integer accepts 4096" assert_equal "$(sanitize_positive_integer 1 MAXCONN)" "1" "sanitize_positive_integer accepts 1" assert_equal "$(sanitize_haproxy_timeout 10s TIMEOUT_CONNECT)" "10s" "sanitize_haproxy_timeout accepts 10s" @@ -111,34 +105,6 @@ assert_fails "sanitize_gateway_domain rejects a newline" sanitize_gateway_domain assert_fails "sanitize_gateway_domain rejects a space" sanitize_gateway_domain "gw example.com" assert_fails "sanitize_domain rejects path traversal" sanitize_domain ../etc/passwd assert_fails "sanitize_target_endpoint rejects malformed URL" sanitize_target_endpoint "http:///broken" -warning_output="$(sanitize_client_max_body_size "50mb" 2>&1 || true)" -if [[ "$warning_output" == "Warning: Ignoring invalid CLIENT_MAX_BODY_SIZE value: 50mb" ]]; then - echo "PASS: sanitize_client_max_body_size warns and returns empty" -else - echo "FAIL: sanitize_client_max_body_size warning unexpected" - printf '%s\n' "$warning_output" - failures=$((failures + 1)) -fi - -# Test invalid timeout values -timeout_warning="$(sanitize_proxy_timeout "30ms" 2>&1 || true)" -if [[ "$timeout_warning" == "Warning: Ignoring invalid proxy timeout value: 30ms" ]]; then - echo "PASS: sanitize_proxy_timeout warns on invalid suffix (ms)" -else - echo "FAIL: sanitize_proxy_timeout warning unexpected" - printf '%s\n' "$timeout_warning" - failures=$((failures + 1)) -fi - -timeout_warning="$(sanitize_proxy_timeout "abc" 2>&1 || true)" -if [[ "$timeout_warning" == "Warning: Ignoring invalid proxy timeout value: abc" ]]; then - echo "PASS: sanitize_proxy_timeout warns on non-numeric value" -else - echo "FAIL: sanitize_proxy_timeout warning unexpected" - printf '%s\n' "$timeout_warning" - failures=$((failures + 1)) -fi - assert_fails "sanitize_dns_label rejects invalid characters" sanitize_dns_label "bad*label" assert_fails "sanitize_positive_integer rejects zero" sanitize_positive_integer 0 MAXCONN assert_fails "sanitize_positive_integer rejects non-numeric" sanitize_positive_integer abc MAXCONN