HAProxy

haproxy-team Publisher

Platform:

Ubuntu
24.04 22.04 20.04 18.04 16.04 14.04
Channel Revision Published Runs on
latest/stable 147 30 Apr 2025
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/stable 66 08 Nov 2021
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/candidate 147 30 Apr 2025
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/candidate 64 14 Oct 2021
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/beta 147 30 Apr 2025
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04
latest/edge 147 29 Apr 2025
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
latest/edge 37 11 Nov 2020
Ubuntu 24.04 Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04 Ubuntu 16.04 Ubuntu 14.04
2.8/stable 567 19 Oct 2026
Ubuntu 24.04
2.8/candidate 571 19 Oct 2026
Ubuntu 24.04
2.8/edge 586 Today
Ubuntu 24.04
2.8/edge 585 Today
Ubuntu 24.04
juju deploy haproxy

charms.haproxy.v0.ddos_protection

DDoS protection interface library.

Getting Started

To get started using the library, you need to first declare the library in the charm-libs section of your charmcraft.yaml file:

charm-libs:
- lib: haproxy.ddos_protection
  version: "0"

Then, fetch the library using charmcraft:

cd some-charm
charmcraft fetch-libs
Using the library as the Provider

The provider charm should expose the interface as shown below:

provides:
    ddos-protection:
        interface: ddos-protection

Then, to initialise the library:

from charms.haproxy.v0.ddos_protection import DDoSProtectionProvider

class DDoSConfigurator(CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.ddos_provider = DDoSProtectionProvider(self)
        # Set the configuration when ready
        self.ddos_provider.set_config(
            rate_limit_requests_per_minute=100,
            rate_limit_connections_per_minute=50,
            concurrent_connections_limit=1000,
            error_rate=10,
            limit_policy_http="reject",
            limit_policy_tcp="reject",
            ip_allow_list=["192.168.1.1", "192.168.1.0/24"],
            http_request_timeout=30,
            http_keepalive_timeout=60,
            client_timeout=50,
            deny_paths=["/admin", "/internal"],
        )
Using the library as the Requirer

The requirer charm should expose the interface as shown below:

requires:
    ddos-protection:
        interface: ddos-protection

Then, to initialise the library:

from charms.haproxy.v0.ddos_protection import DDoSProtectionRequirer

class HaproxyCharm(CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.ddos_requirer = DDoSProtectionRequirer(self, relation_name="ddos-protection")

        self.framework.observe(
            self.on.config_changed, self._on_config_changed
        )

    def _on_config_changed(self, event):
        # Read DDoS protection configuration
        config = self.ddos_requirer.get_ddos_config()
        if config:
            # Apply the configuration
            ...

class DataValidationError

Description

Raised when data validation fails. None

class DDoSProtectionInvalidRelationDataError

Description

Raised when data validation of the ddos-protection relation fails. None

class HttpRateLimitPolicy

Enum of possible HTTP rate limiting policies.

Description

Attrs: DENY: Deny the connection. REJECT: Send a TCP reset packet to close the connection. SILENT: disconnects immediately without notifying the client that the connection has been closed (no packet sent).

class TcpRateLimitPolicy

Enum of possible TCP rate limiting policies.

Description

Attrs: REJECT: Send a TCP reset packet to close the connection. SILENT: disconnects immediately without notifying the client that the connection has been closed (no packet sent).

class DDoSProtectionProviderAppData

Configuration model for DDoS protection provider.

Attributes

rate_limit_requests_per_minute
Maximum number of requests per minute per entry.
rate_limit_connections_per_minute
Maximum number of connections per minute per entry.
concurrent_connections_limit
Maximum number of concurrent connections per entry.
error_rate
Number of errors per minute per entry to trigger the limit policy.
limit_policy_http
Policy to be applied when HTTP-level limits are exceeded.
limit_policy_tcp
Policy to be applied when TCP-level limits are exceeded.
policy_status_code
HTTP status code for deny policy (only set when limit_policy_http is deny).
ip_allow_list
List of IP addresses or CIDR blocks to be allowed.
http_request_timeout
Timeout for HTTP requests in seconds.
http_keepalive_timeout
Timeout for HTTP keep-alive connections in seconds.
client_timeout
Timeout for client connections in seconds.
deny_paths
List of paths to deny.

Methods

DDoSProtectionProviderAppData. validate_ip_allow_list( cls , v )

Validate and convert IP allow list.

Arguments

v

The list of IP addresses or CIDR blocks as strings.

Returns

The list of converted IP address or network objects.

Description

Converts each string to either an IP address or a network.

DDoSProtectionProviderAppData. validate_deny_paths( cls , v )

Validate that deny_paths contains no empty strings.

Arguments

v

The validated list of paths.

Returns

The validated list of paths.

DDoSProtectionProviderAppData. validate_limit_policies( self )

Validate and convert the limit_policy_http and limit_policy_tcp parameters.

Returns

The validated model.

Description

The limit_policy_http must be one of: silent-drop, reject, or deny. The limit_policy_tcp must be one of: silent-drop or reject. For deny, optionally an HTTP status code can be appended (e.g., "deny 503"). Extracts and stores the status code separately in policy_status_code.

DDoSProtectionProviderAppData. validate_limit_policies_with_rate_limits( self )

Validate that limit policies are only set when corresponding rate limits are configured.

Returns

The validated model.

Description

HTTP policy applies to: rate_limit_requests_per_minute, error_rate TCP policy applies to: rate_limit_connections_per_minute, concurrent_connections_limit Sets default policies to SILENT when rate limits are present but policies are not set.

class DDoSProtectionProvider

Description

DDoS protection interface provider implementation. None

Methods

DDoSProtectionProvider. __init__( self , charm: CharmBase , relation_name: str )

Initialize the DDoSProtectionProvider.

Arguments

charm

The charm that is instantiating the library.

relation_name

The name of the relation.

DDoSProtectionProvider. set_config( self )

Update the DDoS protection configuration.

Arguments

rate_limit_requests_per_minute

Maximum number of requests per minute per entry.

rate_limit_connections_per_minute

Maximum number of connections per minute per entry.

concurrent_connections_limit

Maximum number of concurrent connections per entry.

error_rate

Number of errors per minute per entry to trigger the limit policy.

limit_policy_http

Policy to be applied when HTTP-level limits are exceeded.

limit_policy_tcp

Policy to be applied when TCP-level limits are exceeded.

ip_allow_list

List of IP addresses or CIDR blocks to be allowed.

http_request_timeout

Timeout for HTTP requests in seconds.

http_keepalive_timeout

Timeout for HTTP keep-alive connections in seconds.

client_timeout

Timeout for client connections in seconds.

deny_paths

List of paths to deny.

class DDoSProtectionRequirer

Description

DDoS protection interface requirer implementation. None

Methods

DDoSProtectionRequirer. __init__( self , charm: CharmBase , relation_name: str )

Initialize the DDoSProtectionRequirer.

Arguments

charm

The charm that is instantiating the library.

relation_name

The name of the relation to bind to.

DDoSProtectionRequirer. get_ddos_config( self )

Retrieve the DDoS protection configuration from the provider.

Returns

DDoSProtectionProviderAppData

The DDoS protection configuration if available, or None if the relation is not established or contains no data.