Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T6226: add HAPROXY tcp-request related block to load-balancing reverse proxy config #3306

Closed
wants to merge 9 commits into from
10 changes: 10 additions & 0 deletions data/templates/load-balancing/haproxy.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ frontend {{ front }}
{% endif %}
{% if front_config.mode is vyos_defined %}
mode {{ front_config.mode }}
{# add tcp-request related directive if ssl is configed #}
{% if front_config.mode is vyos_defined('tcp') and front_config.rule is vyos_defined %}
{% for rule, rule_config in front_config.rule.items() %}
{% if rule_config.ssl is vyos_defined %}
tcp-request inspect-delay 5s
fsdrw08 marked this conversation as resolved.
Show resolved Hide resolved
tcp-request content accept if {{ "{" }} req_ssl_hello_type 1 {{ "}" }}
fsdrw08 marked this conversation as resolved.
Show resolved Hide resolved
{% break %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% if front_config.rule is vyos_defined %}
{% for rule, rule_config in front_config.rule.items() %}
Expand Down
44 changes: 44 additions & 0 deletions smoketest/scripts/cli/test_load-balancing_reverse-proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,50 @@ def test_03_lb_reverse_proxy_ca_not_exists(self):
self.cli_set(base_path + ['backend', 'bk-01', 'ssl', 'ca-certificate', 'smoketest'])
self.cli_commit()

def test_04_lb_reverse_proxy_tcp_mode(self):
frontend = 'tcp_8443'
mode = 'tcp'
front_port = '8433'
rule_thirty = '30'
domain_bk = 'n6.example.com'
ssl_opt = "req-ssl-sni"
bk_name = 'bk-03'
bk_server = '192.0.2.11'
bk_server_port = '9090'

back_base = base_path + ['backend']

self.cli_set(base_path + ['service', frontend, 'mode', mode])
self.cli_set(base_path + ['service', frontend, 'port', front_port])

self.cli_set(base_path + ['service', frontend, 'rule', rule_thirty, 'domain-name', domain_bk])
self.cli_set(base_path + ['service', frontend, 'rule', rule_thirty, 'ssl', ssl_opt])
self.cli_set(base_path + ['service', frontend, 'rule', rule_thirty, 'set', 'backend', bk_name])

self.cli_set(back_base + [bk_name, 'mode', mode])
self.cli_set(back_base + [bk_name, 'server', bk_name, 'address', bk_server])
self.cli_set(back_base + [bk_name, 'server', bk_name, 'port', bk_server_port])

# commit changes
self.cli_commit()

config = read_file(HAPROXY_CONF)

# Frontend
self.assertIn(f'frontend {frontend}', config)
self.assertIn(f'bind :::{front_port} v4v6', config)
self.assertIn(f'mode {mode}', config)

self.assertIn(f'tcp-request inspect-delay', config)
self.assertIn(f"tcp-request content accept if {{ req_ssl_hello_type 1 }}", config)
self.assertIn(f'acl {rule_thirty} req_ssl_sni -i {domain_bk}', config)
self.assertIn(f'use_backend {bk_name} if {rule_thirty}', config)

# Backend
self.assertIn(f'backend {bk_name}', config)
self.assertIn(f'balance roundrobin', config)
self.assertIn(f'mode {mode}', config)
self.assertIn(f'server {bk_name} {bk_server}:{bk_server_port}', config)

if __name__ == '__main__':
unittest.main(verbosity=2)