From fc1cc74059e51a0317a678026d8f170d4c12bded Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 5 Feb 2026 13:01:41 +0100 Subject: [PATCH 1/5] VR: fix haproxy check when ssl offloading is configured --- systemvm/debian/root/health_checks/haproxy_check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemvm/debian/root/health_checks/haproxy_check.py b/systemvm/debian/root/health_checks/haproxy_check.py index c1db51e440c2..497cc04100e4 100644 --- a/systemvm/debian/root/health_checks/haproxy_check.py +++ b/systemvm/debian/root/health_checks/haproxy_check.py @@ -50,7 +50,7 @@ def checkLoadBalance(haproxyData, haCfgSections): correct = False bindStr = lbSec["sourceIp"] + ":" + formatPort(lbSec["sourcePortStart"], lbSec["sourcePortEnd"]) - if cfgSection["bind"][0] != bindStr: + if not cfgSection["bind"][0].startswith(bindStr): print("Incorrect bind string found. Expected " + bindStr + " but found " + cfgSection["bind"][0] + ".") correct = False From 9a312bd4fca1292e606b1d3fad3ae63874787ad4 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Sun, 8 Feb 2026 15:52:07 +0100 Subject: [PATCH 2/5] Update systemvm/debian/root/health_checks/haproxy_check.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- systemvm/debian/root/health_checks/haproxy_check.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/systemvm/debian/root/health_checks/haproxy_check.py b/systemvm/debian/root/health_checks/haproxy_check.py index 497cc04100e4..e3b053b1c831 100644 --- a/systemvm/debian/root/health_checks/haproxy_check.py +++ b/systemvm/debian/root/health_checks/haproxy_check.py @@ -50,7 +50,9 @@ def checkLoadBalance(haproxyData, haCfgSections): correct = False bindStr = lbSec["sourceIp"] + ":" + formatPort(lbSec["sourcePortStart"], lbSec["sourcePortEnd"]) - if not cfgSection["bind"][0].startswith(bindStr): + bind_line = cfgSection["bind"][0] + bind_token = bind_line.split()[0] if bind_line else "" + if bind_token != bindStr: print("Incorrect bind string found. Expected " + bindStr + " but found " + cfgSection["bind"][0] + ".") correct = False From 12ff7a33a3e5a350385badadb55e10dfbf314199 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Mon, 11 May 2026 11:54:37 +0200 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Wei Zhou --- systemvm/debian/root/health_checks/haproxy_check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemvm/debian/root/health_checks/haproxy_check.py b/systemvm/debian/root/health_checks/haproxy_check.py index e3b053b1c831..56a33345ee9f 100644 --- a/systemvm/debian/root/health_checks/haproxy_check.py +++ b/systemvm/debian/root/health_checks/haproxy_check.py @@ -51,8 +51,8 @@ def checkLoadBalance(haproxyData, haCfgSections): bindStr = lbSec["sourceIp"] + ":" + formatPort(lbSec["sourcePortStart"], lbSec["sourcePortEnd"]) bind_line = cfgSection["bind"][0] - bind_token = bind_line.split()[0] if bind_line else "" - if bind_token != bindStr: + bind_token = bind_line.split()[:2] if bind_line else "" + if (" ").join(bind_token) != bindStr: print("Incorrect bind string found. Expected " + bindStr + " but found " + cfgSection["bind"][0] + ".") correct = False From cf3067af3e462bb848440aa7148f81e5d562b0a8 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 26 Nov 2026 19:31:19 +0100 Subject: [PATCH 4/5] Revert "Apply suggestions from code review" This reverts commit 12ff7a33a3e5a350385badadb55e10dfbf314199. --- systemvm/debian/root/health_checks/haproxy_check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemvm/debian/root/health_checks/haproxy_check.py b/systemvm/debian/root/health_checks/haproxy_check.py index 56a33345ee9f..e3b053b1c831 100644 --- a/systemvm/debian/root/health_checks/haproxy_check.py +++ b/systemvm/debian/root/health_checks/haproxy_check.py @@ -51,8 +51,8 @@ def checkLoadBalance(haproxyData, haCfgSections): bindStr = lbSec["sourceIp"] + ":" + formatPort(lbSec["sourcePortStart"], lbSec["sourcePortEnd"]) bind_line = cfgSection["bind"][0] - bind_token = bind_line.split()[:2] if bind_line else "" - if (" ").join(bind_token) != bindStr: + bind_token = bind_line.split()[0] if bind_line else "" + if bind_token != bindStr: print("Incorrect bind string found. Expected " + bindStr + " but found " + cfgSection["bind"][0] + ".") correct = False From 9e880e5b9c5aa018429f5c8028106288d1008319 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 26 Nov 2026 19:44:01 +0100 Subject: [PATCH 5/5] systemvm: add unit tests for haproxy bind check Cover plain bind, SSL bind with options, and wrong port/IP cases for checkLoadBalance in haproxy_check.py, so the SSL-offloading regression reported in #12591 is caught by unit tests. --- systemvm/test/TestHaproxyCheck.py | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 systemvm/test/TestHaproxyCheck.py diff --git a/systemvm/test/TestHaproxyCheck.py b/systemvm/test/TestHaproxyCheck.py new file mode 100644 index 000000000000..f96c95f10fae --- /dev/null +++ b/systemvm/test/TestHaproxyCheck.py @@ -0,0 +1,77 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import os +import sys +import unittest + +HEALTH_CHECKS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), + "..", "debian", "root", "health_checks") +sys.path.insert(0, HEALTH_CHECKS_DIR) + +import haproxy_check # noqa: E402 + + +SSL_BIND_OPTIONS = ("ssl crt /etc/cloudstack/ssl/10_0_62_24-443.pem alpn h2,http/1.1 " + "ssl-min-ver TLSv1.2 no-tls-tickets") + + +def build_lb_rule(): + return { + "sourceIp": "10.0.62.24", + "sourcePortStart": "443", + "sourcePortEnd": "443", + "algorithm": "roundrobin", + "keepAliveEnabled": "true", + "stickiness": "", + "vmIps": "10.1.1.10", + "destPortStart": "80", + "destPortEnd": "80", + } + + +def build_haproxy_section(bind_value): + return { + "balance": ["roundrobin"], + "bind": [bind_value], + "server": ["10_0_62_24-443_1 10.1.1.10:80 check"], + } + + +class TestHaproxyCheckBind(unittest.TestCase): + + def check(self, bind_value): + haCfgSections = { + "listen 10_0_62_24-443": build_haproxy_section(bind_value), + } + return haproxy_check.checkLoadBalance([build_lb_rule()], haCfgSections) + + def test_plain_bind_passes(self): + self.assertTrue(self.check("10.0.62.24:443")) + + def test_ssl_bind_with_options_passes(self): + self.assertTrue(self.check("10.0.62.24:443 " + SSL_BIND_OPTIONS)) + + def test_ssl_bind_with_wrong_port_fails(self): + self.assertFalse(self.check("10.0.62.24:4430 " + SSL_BIND_OPTIONS)) + + def test_ssl_bind_with_wrong_ip_fails(self): + self.assertFalse(self.check("10.0.62.25:443 " + SSL_BIND_OPTIONS)) + + +if __name__ == '__main__': + unittest.main()