Skip to content

Conversation

@bentito
Copy link
Contributor

@bentito bentito commented Dec 1, 2025

Previously, when a route was configured with insecureEdgeTerminationPolicy: Redirect, HAProxy would preserve the port from the Host header in the redirect Location. This caused clients to attempt HTTPS connections on port 80 (e.g., https://example.com:80) if the original request included the port.

This commit updates the HAProxy template to explicitly strip any port number from the Host header using 'regsub(:[0-9]+$,,)' before constructing the redirect URL. This ensures redirects always go to the default HTTPS port (443).

A regression test 'Secure Redirect Strips Port' has been added to pkg/router/router_test.go to verify this configuration generation.

Previously, when a route was configured with insecureEdgeTerminationPolicy: Redirect, HAProxy would preserve the port from the Host header in the redirect Location. This caused clients to attempt HTTPS connections on port 80 (e.g., https://example.com:80) if the original request included the port.

This commit updates the HAProxy template to explicitly strip any port number from the Host header using 'regsub(:[0-9]+$,,)' before constructing the redirect URL. This ensures redirects always go to the default HTTPS port (443).

A regression test 'Secure Redirect Strips Port' has been added to pkg/router/router_test.go to verify this configuration generation.
@bentito bentito changed the title Fix HAProxy redirect: strip port from Host header OCPBUGS-65482: Fix HAProxy redirect: strip port from Host header Dec 1, 2025
@openshift-ci-robot openshift-ci-robot added jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Dec 1, 2025
@openshift-ci-robot
Copy link
Contributor

@bentito: This pull request references Jira Issue OCPBUGS-65482, which is invalid:

  • expected the bug to target the "4.21.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Previously, when a route was configured with insecureEdgeTerminationPolicy: Redirect, HAProxy would preserve the port from the Host header in the redirect Location. This caused clients to attempt HTTPS connections on port 80 (e.g., https://example.com:80) if the original request included the port.

This commit updates the HAProxy template to explicitly strip any port number from the Host header using 'regsub(:[0-9]+$,,)' before constructing the redirect URL. This ensures redirects always go to the default HTTPS port (443).

A regression test 'Secure Redirect Strips Port' has been added to pkg/router/router_test.go to verify this configuration generation.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@bentito
Copy link
Contributor Author

bentito commented Dec 1, 2025

/jira refresh

@openshift-ci-robot
Copy link
Contributor

@bentito: This pull request references Jira Issue OCPBUGS-65482, which is invalid:

  • expected the bug to target the "4.21.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

Details

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@bentito
Copy link
Contributor Author

bentito commented Dec 1, 2025

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Dec 1, 2025
@openshift-ci-robot
Copy link
Contributor

@bentito: This pull request references Jira Issue OCPBUGS-65482, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.21.0) matches configured target version for branch (4.21.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @ShudiLi

Details

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested a review from ShudiLi December 1, 2025 23:59
@ShudiLi
Copy link
Member

ShudiLi commented Dec 2, 2025

reproduced it with 4.21.0-0.nightly-2025-11-22-193140 and verified it with 4.21.0-0-2025-12-02-060314-test-ci-ln-sikxch2-latest

Reproduced:

1.
% oc get clusterversion
NAME      VERSION                              AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.21.0-0.nightly-2025-11-22-193140   True        False         5h2m    Cluster version is 4.21.0-0.nightly-2025-11-22-193140

2.
% oc -n test get route
NAME          HOST/PORT                                                         PATH   SERVICES      PORT          TERMINATION     WILDCARD
edge1         edge1-test.apps.shudi-421bm02.qe.devcluster.openshift.com                unsec-apach   unsec-apach   edge/Redirect   None

3.
% curl -L -H "Host: edge1-test.apps.shudi-421bm02.qe.devcluster.openshift.com:80" http://edge1-test.apps.shudi-421bm02.qe.devcluster.openshift.com:80/ -k
curl: (35) LibreSSL/3.3.6: error:1404B42E:SSL routines:ST_CONNECT:tlsv1 alert protocol version

Verified:

1.
% oc get clusterversion
NAME      VERSION                                                AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.21.0-0-2025-12-02-060314-test-ci-ln-sikxch2-latest   True        False         27m     Cluster version is 4.21.0-0-2025-12-02-060314-test-ci-ln-sikxch2-latest

2.
% oc -n test get route
NAME          HOST/PORT                                                                     PATH   SERVICES      PORT          TERMINATION     WILDCARD
edge1         edge1-test.apps.ci-ln-sikxch2-72292.origin-ci-int-gce.dev.rhcloud.com                unsec-apach   unsec-apach   edge/Redirect   None

3.
% curl -L -H "Host: edge1-test.apps.ci-ln-sikxch2-72292.origin-ci-int-gce.dev.rhcloud.com:80" http://edge1-test.apps.ci-ln-sikxch2-72292.origin-ci-int-gce.dev.rhcloud.com:80/ -k
It is a test!

@ShudiLi
Copy link
Member

ShudiLi commented Dec 2, 2025

/label qe-approved
/verified by @ShudiLi

@openshift-ci openshift-ci bot added the qe-approved Signifies that QE has signed off on this PR label Dec 2, 2025
@openshift-ci-robot
Copy link
Contributor

@bentito: This pull request references Jira Issue OCPBUGS-65482, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.21.0) matches configured target version for branch (4.21.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @ShudiLi

Details

In response to this:

Previously, when a route was configured with insecureEdgeTerminationPolicy: Redirect, HAProxy would preserve the port from the Host header in the redirect Location. This caused clients to attempt HTTPS connections on port 80 (e.g., https://example.com:80) if the original request included the port.

This commit updates the HAProxy template to explicitly strip any port number from the Host header using 'regsub(:[0-9]+$,,)' before constructing the redirect URL. This ensures redirects always go to the default HTTPS port (443).

A regression test 'Secure Redirect Strips Port' has been added to pkg/router/router_test.go to verify this configuration generation.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Dec 2, 2025
@openshift-ci-robot
Copy link
Contributor

@ShudiLi: This PR has been marked as verified by @ShudiLi.

Details

In response to this:

/label qe-approved
/verified by @ShudiLi

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Signed-off-by: Brett Tofel <btofel@redhat.com>
@openshift-ci-robot openshift-ci-robot removed the verified Signifies that the PR passed pre-merge verification criteria label Dec 2, 2025
Copy link
Contributor

@alebedev87 alebedev87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First glance.

@alebedev87
Copy link
Contributor

/assign

@alebedev87
Copy link
Contributor

As discussed in Slack, we would need an e2e test for this change. Unfortunately it can't be done in this repository as we host them in openshift/cluster-ingress-operator. However the test scenarios for this change should not be complex.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 2, 2025

@bentito: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@alebedev87
Copy link
Contributor

/assign @Thealisyed

@ShudiLi
Copy link
Member

ShudiLi commented Dec 9, 2025

Tested it again and saw the 302 redirect message

1.
% oc get clusterversion
NAME      VERSION                                                AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.21.0-0-2025-12-09-013709-test-ci-ln-qhf3fg2-latest   True        False         26m     Cluster version is 4.21.0-0-2025-12-09-013709-test-ci-ln-qhf3fg2-latest

2.
 % oc -n test get route                                                                           
NAME          HOST/PORT                                                          PATH   SERVICES      PORT          TERMINATION     WILDCARD
edge1         edge1-test.apps.ci-ln-qhf3fg2-72292.gcp-2.ci.openshift.org                unsec-apach   unsec-apach   edge/Redirect   None

3.
sh-4.4# curl -L -H "Host: edge1-test.apps.ci-ln-qhf3fg2-72292.gcp-2.ci.openshift.org:80" http://edge1-test.apps.ci-ln-qhf3fg2-72292.gcp-2.ci.openshift.org:80 -k
It is a test!

4.
sh-4.4# tcpdump -i any tcp  -s 0 -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
03:06:49.042427 IP 10.128.2.23.47076 > 35.222.177.125.http: Flags [S], seq 137246821, win 64680, options [mss 1320,sackOK,TS val 3691157104 ecr 0,nop,wscale 7], length 0
03:06:49.046854 IP 35.222.177.125.http > 10.128.2.23.47076: Flags [S.], seq 2874001464, ack 137246822, win 65400, options [mss 1320,sackOK,TS val 3046584714 ecr 3691157104,nop,wscale 7], length 0
03:06:49.046929 IP 10.128.2.23.47076 > 35.222.177.125.http: Flags [.], ack 1, win 506, options [nop,nop,TS val 3691157109 ecr 3046584714], length 0
03:06:49.046994 IP 10.128.2.23.47076 > 35.222.177.125.http: Flags [P.], seq 1:126, ack 1, win 506, options [nop,nop,TS val 3691157109 ecr 3046584714], length 125: HTTP: GET / HTTP/1.1
03:06:49.049278 IP 35.222.177.125.http > 10.128.2.23.47076: Flags [P.], seq 1:146, ack 126, win 510, options [nop,nop,TS val 3046584717 ecr 3691157109], length 145: HTTP: HTTP/1.1 302 Found

# check if we need to redirect/force using https.
acl secure_redirect base,map_reg_int(/var/lib/haproxy/conf/os_route_http_redirect.map) -m bool
redirect scheme https if secure_redirect
http-request redirect location https://%[req.hdr(host),regsub(:[0-9]+$,,)]%[path] code 302 if secure_redirect

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the original redirect scheme preserve query strings? If so, then just a thought that this new change could lead to regression IIUC ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Yes, redirect scheme does redirect query component of the URL.

4.21 cluster, router pod unmodified:

$ oc -n openshift-ingress rsh router-default-55fb59cffb-cmxsj cat /var/lib/haproxy/conf/haproxy.config | grep 'redirect scheme'
  redirect scheme https if secure_redirect

$ curl -H "Host: console-openshift-console.apps.ci-ln-8qpdpsb-76ef8.aws-4.ci.openshift.org:80" http://router-default.apps.ci-ln-8qpdpsb-76ef8.aws-4.ci.openshift.org/123?here=there -v 2>&1 | grep '< location:'
< location: https://console-openshift-console.apps.ci-ln-8qpdpsb-76ef8.aws-4.ci.openshift.org:80/123?here=there

Router image replaced with %[path] pattern:

$ oc -n openshift-ingress rsh router-default-6cf87fbfd-4xg8h cat /var/lib/haproxy/conf/haproxy.config | grep 'redirect location'
  http-request redirect location https://%[req.hdr(host),regsub(:[0-9]+$,,)]%[path] code 302 if secure_redirect

$ curl -H "Host: console-openshift-console.apps.ci-ln-8qpdpsb-76ef8.aws-4.ci.openshift.org:80" http://router-default.apps.ci-ln-8qpdpsb-76ef8.aws-4.ci.openshift.org/123?here=there -v 2>&1 | grep '< location:'
< location: https://console-openshift-console.apps.ci-ln-8qpdpsb-76ef8.aws-4.ci.openshift.org/123

%[url] pattern looks to be covering the query case:

$ oc -n openshift-ingress rsh router-default-849c97866f-frw8m cat /var/lib/haproxy/conf/haproxy.config | grep 'redirect location'
  http-request redirect location https://%[req.hdr(host),regsub(:[0-9]+$,,)]%[url] code 302 if secure_redirect

$ curl -H "Host: console-openshift-console.apps.ci-ln-8qpdpsb-76ef8.aws-4.ci.openshift.org:80" http://router-default.apps.ci-ln-8qpdpsb-76ef8.aws-4.ci.openshift.org/123?here=there -v 2>&1 | grep '< location:'
< location: https://console-openshift-console.apps.ci-ln-8qpdpsb-76ef8.aws-4.ci.openshift.org/123?here=there

This should be covered in the e2e test case (openshift/cluster-ingress-operator#1316).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep thansk! I'll fix this and add test cases in the e2e to prevent regression in the future.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 17, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from alebedev87. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. qe-approved Signifies that QE has signed off on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants