From 0269cb2c388e9c87a39ff20610e53096137ff80a Mon Sep 17 00:00:00 2001 From: Stamatis Katsaounis Date: Mon, 23 Mar 2026 12:59:05 +0200 Subject: [PATCH] fix: add proper type to hosts in haproxy libraries --- docs/changelog.md | 4 ++++ docs/release-notes/artifacts/pr0383.yaml | 13 +++++++++++++ .../lib/charms/haproxy/v1/haproxy_route_tcp.py | 10 +++++----- .../lib/charms/haproxy/v2/haproxy_route.py | 8 ++++---- 4 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 docs/release-notes/artifacts/pr0383.yaml diff --git a/docs/changelog.md b/docs/changelog.md index 6d2d081ef..48f594f01 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Each revision is versioned by the date of the revision. +## 2026-03-23 + +- Fixed hosts validation in haproxy-route and haproxy-route-tcp relation libraries. + ## 2026-01-19 - Fixed issues with the DDoS protection configurator charm found in staging. diff --git a/docs/release-notes/artifacts/pr0383.yaml b/docs/release-notes/artifacts/pr0383.yaml new file mode 100644 index 000000000..a5a01d8d3 --- /dev/null +++ b/docs/release-notes/artifacts/pr0383.yaml @@ -0,0 +1,13 @@ +version_schema: 2 +changes: + - title: Fix hosts validation in haproxy-route-tcp, and haproxy-route relation libraries + author: skatsaounis + type: bugfix + description: > + Fixed hosts validation in the haproxy-route-tcp and haproxy-route relation libraries, ensuring + that only valid IP addresses are accepted. + urls: + pr: + - https://github.com/canonical/haproxy-operator/pull/383 + visibility: public + highlight: false diff --git a/haproxy-operator/lib/charms/haproxy/v1/haproxy_route_tcp.py b/haproxy-operator/lib/charms/haproxy/v1/haproxy_route_tcp.py index 48c2f8a6b..2eff32178 100644 --- a/haproxy-operator/lib/charms/haproxy/v1/haproxy_route_tcp.py +++ b/haproxy-operator/lib/charms/haproxy/v1/haproxy_route_tcp.py @@ -186,7 +186,7 @@ def _on_haproxy_route_data_available(self, event: EventBase) -> None: # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 1 +LIBPATCH = 2 logger = logging.getLogger(__name__) HAPROXY_ROUTE_TCP_RELATION_NAME = "haproxy-route-tcp" @@ -976,7 +976,7 @@ def __init__( *, port: Optional[int] = None, backend_port: Optional[int] = None, - hosts: Optional[list[str]] = None, + hosts: Optional[list[IPvAnyAddress]] = None, sni: Optional[str] = None, check_interval: Optional[int] = None, check_rise: Optional[int] = None, @@ -1102,7 +1102,7 @@ def provide_haproxy_route_tcp_requirements( *, port: int, backend_port: Optional[int] = None, - hosts: Optional[list[str]] = None, + hosts: Optional[list[IPvAnyAddress]] = None, sni: Optional[str] = None, check_interval: Optional[int] = None, check_rise: Optional[int] = None, @@ -1200,7 +1200,7 @@ def _generate_application_data( *, port: Optional[int] = None, backend_port: Optional[int] = None, - hosts: Optional[list[str]] = None, + hosts: Optional[list[IPvAnyAddress]] = None, sni: Optional[str] = None, check_interval: Optional[int] = None, check_rise: Optional[int] = None, @@ -1558,7 +1558,7 @@ def configure_backend_port(self, backend_port: int) -> "Self": self._application_data["backend_port"] = backend_port return self - def configure_hosts(self, hosts: Optional[list[int]] = None) -> "Self": + def configure_hosts(self, hosts: Optional[list[IPvAnyAddress]] = None) -> "Self": """Set backend hosts. Args: diff --git a/haproxy-operator/lib/charms/haproxy/v2/haproxy_route.py b/haproxy-operator/lib/charms/haproxy/v2/haproxy_route.py index e3ea4779a..795c815ad 100644 --- a/haproxy-operator/lib/charms/haproxy/v2/haproxy_route.py +++ b/haproxy-operator/lib/charms/haproxy/v2/haproxy_route.py @@ -154,7 +154,7 @@ def _on_haproxy_route_data_available(self, event: EventBase) -> None: # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 0 +LIBPATCH = 1 logger = logging.getLogger(__name__) HAPROXY_ROUTE_RELATION_NAME = "haproxy-route" @@ -1005,7 +1005,7 @@ def __init__( service: Optional[str] = None, ports: Optional[list[int]] = None, protocol: Literal["http", "https"] = "http", - hosts: Optional[list[str]] = None, + hosts: Optional[list[IPvAnyAddress]] = None, paths: Optional[list[str]] = None, hostname: Optional[str] = None, additional_hostnames: Optional[list[str]] = None, @@ -1144,7 +1144,7 @@ def provide_haproxy_route_requirements( service: str, ports: list[int], protocol: Literal["http", "https"] = "http", - hosts: Optional[list[str]] = None, + hosts: Optional[list[IPvAnyAddress]] = None, paths: Optional[list[str]] = None, hostname: Optional[str] = None, additional_hostnames: Optional[list[str]] = None, @@ -1258,7 +1258,7 @@ def _generate_application_data( # noqa: C901 service: Optional[str] = None, ports: Optional[list[int]] = None, protocol: Literal["http", "https"] = "http", - hosts: Optional[list[str]] = None, + hosts: Optional[list[IPvAnyAddress]] = None, paths: Optional[list[str]] = None, hostname: Optional[str] = None, additional_hostnames: Optional[list[str]] = None,