Commit Graph

80 Commits

Author SHA1 Message Date
Damian Dabrowski ed8eeba8d3 Implement haproxy_pki_create_certificates variable
In cases when internal and external haproxy frontends should use
different, pre-generated certificates, it's not possible to define them
with haproxy_user_ssl_cert because it accepts only one certificate.
In this case, certificates can be placed manually in pki/ directory.
Unfortunately, with current logic, certificates creation with PKI role
is disabled only when haproxy_user_ssl_cert is defined.
Possibility of explicitly disabling certificates generation will be
really useful.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible-os_nova/+/915320/
Change-Id: I4eed4d797160b885d5b7187e6106e6ee0073722f
2024-04-10 10:58:02 +00:00
Christian Rohmann 04a8f8532a Enable stats to use dedicated server certificate and allow for client cert auth
Some environments use a dedicated PKI for monitoring and metric collection.
This change allows to configure the serving certificate for stats independently
by setting `haproxy_stats_ssl_cert_path`, the default is to use the same cert.

Also client certificate authentication for stats can now be enabled by defining
a CA cert via `haproxy_stats_ssl_client_cert_ca`.

Change-Id: Ib8be6b7fc3dada9d20905b0f07d90ddce0335605
2023-09-28 09:32:22 +00:00
Zuul b2ea96d50c Merge "Fix linters issue and metadata" 2023-08-31 09:53:51 +00:00
Dmitriy Rabotyagov 67e19ebccd Add HTTP/2 support for frontends/backends
This patch implements extra variables/keys that can be used to
enable HTTP/2 protocol for frontends and backends.

With that patch does not add HTTP/2 support for any redirect frontends
since they can not be configured to use TLS and this it will
cause such redirect backends to be HTTP/2 only, which might break old
clients.

With that regular frontends, that are not terminating TLS can be
configured to be HTTP/2 only as well as TCP backends.

Change-Id: Ib14f031f3c61f31bf7aaf345a3ba635ca5fb9ff8
2023-08-23 13:24:43 +00:00
Dmitriy Rabotyagov c0da2e5095 Fix linters issue and metadata
With update of ansible-lint to version >=6.0.0 a lot of new
linters were added, that enabled by default. In order to comply
with linter rules we're applying changes to the role.

With that we also update metdata to reflect current state.

Change-Id: I8c316dd62ac22ccd9578bb0199ab8f25c0104f9a
2023-08-07 06:55:22 +00:00
Andrew Bonney 97390e88e0 Correct default Content-Type for security.txt
The security.txt RFC specifies a Content-Type of text/plain and
charset of utf-8 [1]. This adjusts the defaults so line breaks are
rendered correctly in a browser.

[1] https://datatracker.ietf.org/doc/html/rfc9116#section-3

Change-Id: I39c2dab5108a815ef966bab0d708d6300eb1a4d1
2023-07-28 14:09:02 +01:00
Damian Dabrowski 8168af6635 Deprecate certbot-auto
Certbot-auto is deprecated since 2020[1] and it is no longer available
under https://dl.eff.org/certbot-auto.
This change removes certbot-auto from haproxy_server role leaving
distro method as the only available option.

[1] https://community.letsencrypt.org/t/certbot-auto-deprecated-explanation-and-solutions/139821

Change-Id: Ibe0f13fc7308359d337fb382cb72998befb90d84
2023-04-26 16:47:58 +02:00
Damian Dabrowski 0f7b091244 Allow haproxy role to create security.txt file
This patch allows haproxy role to create security.txt file.

Change-Id: Ided790a5a89a2298b3b758d4484b25091b92945b
2023-04-12 20:38:15 +02:00
Damian Dabrowski a5f285c51e Simplify haproxy_service_configs structure
For historical reasons the ``haproxy_service_configs`` variable was
a list of nested mappings with only single valid key for the top
level mapping.

There have been no use-cases for extra keys, so this patch simplifies
the code by removing one level of nesting.

Change-Id: I50c17b7020a459ab8a88b004cc8828cac857f1c9
2023-03-16 14:19:22 +01:00
Jonathan Rosser d548b7e5ff Add support for haproxy map files
HAProxy supports the use of map files for selecting backends, or
a number of other functions. See [1] and [2].

This patch adds the key `maps` for each service definition allowing
fragments of a complete map to be defined across all the services,
with each service contributing some elements to the overall map file.

The service enabled/disabled and state flags are observed to add and
remove entries from the map file, and individual map entries can also
be marked as present/absent to make inclusion conditional.

[1] https://www.haproxy.com/blog/introduction-to-haproxy-maps/
[2] https://www.haproxy.com/documentation/hapee/latest/configuration/map-files/syntax/

Change-Id: I755c18a4d33ee69c42d68a50daa63614a2b2feb7
2023-03-16 13:17:39 +01:00
Jonathan Rosser 42d80464af Allow default_backend to be specified
Currently default_backend for a service is always set to the
haproxy_service_name for a service, but this might not be what is
required for some configurations.

This patch allows haproxy_default_backend to be configured for
a service to customise the default_backend setting.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible-rabbitmq_server/+/876436
Change-Id: I9e2be37cb27a33350577a93f23b69e560493b320
2023-03-06 11:56:51 +00:00
Zuul 8514c0d775 Merge "Add a variable to allow extra raw config to be applied to all frontends" 2023-02-21 20:18:48 +00:00
Jonathan Rosser 0d56cfe64b Update hatop to latest release, 0.8.2
Change-Id: I300206a79fcb9e809c1ae714f492583fb9d4e363
2023-02-17 17:22:08 +01:00
Jonathan Rosser f7c87fd118 Add a variable to allow extra raw config to be applied to all frontends
Currently this must be configured on a per-frontend basis through
service.haproxy_frontend_raw. This patch adds a new role default
variable haproxy_frontend_extra_raw which will be combined with all
per service raw config lines.

Change-Id: I506d46d64df93bbb9e6d1ebfa3d3caa44c80fdd5
2023-02-14 18:55:00 +00:00
Damian Dabrowski 34ac0710c5 Fix warnings in haproxy config
Haproxy config check(/usr/sbin/haproxy -c -f /etc/haproxy/haproxy.cfg)
returns 3 warnings:

1. keyword 'forceclose' is deprecated in favor of 'httpclose', and will
not be supported by future versions.
2. backend 'galera-back' : 'option tcplog' directive is ignored in
backends.
3. 'http-request' rules ignored for backend 'galera-back' as they
require HTTP mode.

This change fixes 1. and 2.
Fixing 3. will be a bit more tricky as it's a part of
`openstack_haproxy_stick_table` defined in
/opt/openstack-ansible/inventory/group_vars/haproxy/haproxy.yml

Change-Id: Idaa4b5580039857435f90416924dee26a702deba
2022-12-01 16:41:04 +00:00
Dmitriy Rabotyagov 6025eaac36 Allow do disable SSL only for stats frontend
Currently there is no way of disabling SSL connection for stats frontend
as it implies more global variable. However, for some systems consuming
self-signed root certificate might be not an option and disabling
SSL verification tricky. Thus, we introduce new variable that allows to
nicely control if SSL should be served for stats frontend or not.

Change-Id: Ic4bc4393ec89469876e9e95b12bb9c4069972713
2022-10-05 11:29:50 +00:00
Zuul a502817a89 Merge "Allow haproxy to bind on the interface" 2022-09-27 21:11:49 +00:00
Zuul c1df0a5b56 Merge "Add variable for setting certbot `domains` option" 2022-09-20 16:03:26 +00:00
Danila Balagansky 1664c993b6 Add variable for setting certbot `domains` option
Add `haproxy_ssl_letsencrypt_domains` variable, which
contains a list (defaults to `external_lb_vip_address`)
for `--domains` certbot option.

Change-Id: I2ebfff9eeb5279a3964b8578a6e66aa132d763f5
2022-09-15 08:03:07 +00:00
Dmitriy Rabotyagov 901523ddbb Allow haproxy to bind on the interface
In some user scenarious (like implementing DNS RR) it might be useful to
bind on 0.0.0.0 but at the same time do not conflict with other services
that are binded to the same ports. For that, we can specify a specific
interface, on which haproxy will be binded to 0.0.0.0.

In netstat it would be represented like `0.0.0.0%br-mgmt:5000`.

With that we also allow to fully override `vip_binds` if assumtions
that role make are not valid for some reason.

Change-Id: Ic4c58ef53abc5f454b6fbebbd87292a932d173ae
2022-08-09 18:47:29 +00:00
Andrew Bonney 8dc0ff4e1f tls1.2: update ciphers to latest recommendations
Based upon usual recommendations from:
https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/

Change-Id: I6e549ab3ffcacebe04e188cbf34d8707fb0fe05d
2022-08-05 10:44:07 +01:00
Jonathan Rosser 06e76706c7 Allow customisation of stick-tables for each service.
A new variable "haproxy_stick_table" is added which allows a custom
stick-table to be supplied that is used as the default stick-table
for all haproxy back-ends.

In addition, the variable service.haproxy_stick_table can be defined
for each service to allow a unique stick-table to be supplied for
a particular service.

The old default stick-table definition is removed as there was no
use case defined for it in this role before. An example is added
to defaults/main.yml to show how the custom stick-table can be used
to rate-limit requests that generate 4xx responses which commonly
occur during vulnerability scanning or credential stuffing attacks.
There are many other uses for stick-tables, consult the HAProxy
documentation for details.

Change-Id: I50daba08c10f071157d6450ea2fa97df448f99ec
2022-07-11 14:54:01 +00:00
Dmitriy Rabotyagov be9a66c280 Don't restrict haproxy tunable options
Instead of hardcoding specific supported tunable options, we
just pass key as an option to haproxy config.

This change might break deployments during upgrades, since format of
values in variable has changed, but appropriate release note was written

We also increase maxrewrite by default, as otherwise usage of CSP leads
to 500 error.

Change-Id: I949960420ed5dbd6d58f0de7dae0ac629a85b7fc
Related-Bug: https://github.com/haproxy/haproxy/issues/1597
Needed-By: https://review.opendev.org/c/openstack/openstack-ansible-os_horizon/+/844815
2022-06-20 08:27:40 +02:00
Andrew Bonney 0aeaeb590a Adjust default configuration to support TLS v1.3
This adds TLS v1.3 support to the HAProxy role by default, along
with a new variable to manage cipher suites.

The old variable for TLS v1.2 and below ciphers is renamed for
consistency, but is still supported as a default where overridden
by deployments.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible/+/823943
Change-Id: Iaf9709ac5f5ac8db281a9ec7278cef274186ba15
2022-01-10 08:57:40 +00:00
James Gibson 800254b354 Add option to use alernative CA server for certbot
This could be achieved using the
haproxy_ssl_letsencrypt_setup_extra_params variable, but this
makes it a bit neater.

Change-Id: Iee2d5a10e1762b23fcb3f3140950c76a754743b7
2021-10-18 08:50:27 +01:00
Andrew Bonney 964a33558b Add configuration option for native prometheus exporter
HAProxy added native Prometheus support from v2.0. This can be
enabled using the existing stats endpoint via an additional
/metrics path.

Change-Id: If9528969c7915db06138c0746dc419d8302f0e7c
2021-07-30 09:07:50 +01:00
Dmitriy Rabotyagov f14ba91798 Generate self-signed SSL per listen IP
We're providing an option to have an IP address per VIP
address. Currently it's used only for creating self-signed
SSLs signed with internal CA per each VIP. With follow-up
patches that will also allow to provide user certificates
per VIP, making possible to cover internal and external
endpoints with different non-wildcard certs.

Change-Id: I0a9eb7689eb42b50daf5c94c874bb7429b271efe
2021-06-25 13:30:25 +00:00
Dmitriy Rabotyagov f058cf8d61 Replace whitelist with allowlist naming
Change-Id: I568273d0ef1d5ee391a42981e66cc9895b9d71b6
2021-06-16 14:40:19 +03:00
Jonathan Rosser fd7509cd43 Use external PKI role to manage haproxy self-signed certificates
The external PKI role can generate a self signed CA and Intermediate
certificate, and then create a server certificate for haproxy if
no defaults are overridden.

The new openstack_pki_* settings allow an external self signed CA
to be used, but still create valid haproxy server certificates from
that external CA in an openstack-ansible deployment.

The original beheviour providing user supplied certificates in the
haproxy_user_ssl_* variables will still work, disabling the generation
of certificates but using the external PKI role to just install the
supplied certs and keys.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible/+/788031
Change-Id: I7482f55e991bacd9dccd2748c236dcd9d01124f3
2021-06-01 15:37:29 +00:00
Andrew Bonney 357daad5c8 Allow HAProxy stats to be pinned to one or more processes
When HAProxy is run in multi-process mode, the single stats page
shows metrics for one of the processes at a time, with a random
selection made on page reload.

Whilst a more complete solution may be to enable a stats page for
each process, this is a little cumbersome. This addition allows
the stats page to be pinned to one process, providing a partial
snapshot of the state of the instance.

Change-Id: Id9314e5b267aafeaf34c82874eb8bfe0713dfac3
2021-03-25 14:08:15 +00:00
Satish Patel 0ef22fa4df Fix HATop for haproxy
Readjust hatop installtion method, removed haproxy_hatop_downloader and
deployment-host variables. added "haproxy_hatop_install | bool" condition.

Change-Id: I51423fff67e6e427f6c7d163d8d1aac6bcd82ca9
2020-12-30 17:20:42 +00:00
Marc Gariepy ca2c011cf2 Add haproxy_frontend_only and haproxy_raw feature.
you can add prometheus metric exposed directly via haproxy if your
version is recent enough.
https://www.haproxy.com/blog/haproxy-exposes-a-prometheus-metrics-endpoint/

Change-Id: I10e7220071290301a85409a1f74fcbad2743d19d
2020-12-14 19:10:29 +00:00
Satish Patel a46106d4e7 Python3 supported version of hatop
New hatop package has python3 support.

Change-Id: I69c01f330feb67d92b6b01fea589a35969879da2
2020-12-04 14:27:42 +00:00
Dmitriy Rabotyagov 0343893881 Define http-01 params with already provided variables
There's no real need in asking user to manually provide http-01 port and
address when we already have corresponding variables we rely on.

Change-Id: Id0d2a73c863d9bbb8b6280ce42f918127baea354
2020-09-24 09:55:09 +00:00
Dmitriy Rabotyagov 6bd42911f7 Add haproxy_ssl_all_vips variable
This variable will allow to globally control if SSL should be also used
for internal/admin endpoints, or for public only

Change-Id: I1fa990bab5801a6e6fde7176b2011ab1977b30ae
2020-08-20 13:27:44 +03:00
Jonathan Rosser aa737c5c42 Allow ansible group for self signed certificate distribution to be overidden
If this role is used outside the context of openstack-ansible then the
self signed certificate distribution tasks will fail if the haproxy_all
group is not defined, even if self signed certificates are not being used.

Change-Id: Iebc4a293fa8e3566bc910de305e6519a25f2884f
2020-05-07 13:16:18 +00:00
Jonathan Rosser dbc8fe1fe2 Use a certbot pre-hook to ensure haproxy backend is up before renewal
We use the built in python3 http server to bring up a temporary backend
on the node which wants to renew a certificate. The timeout set so that
the haproxy health check has noticed the backend come up before certbot
runs.

There is otherwise a race condition between the haproxy healthcheck and
the certbot challenge request arriving at the acme-challenge endpoint.

Change-Id: I2f5f9457c43c68f2881bf9d44f43434ca7b43859
2020-05-07 13:15:54 +00:00
Jonathan Rosser ba3a89944b Allow multiple methods of installing certbot
Currently the only method is by downloading the certbot-auto script
and executing that. Some distros supply a so this patch sets up
an option for a future patch to add distro package support

Change-Id: Ie32e6f577c9aa898906ee76199fd0ebe75d5ae95
2020-05-05 14:01:23 +00:00
Jonathan Rosser 04932a7c74 Allow extra parameters to be passed to certbot
When setting up certbot for the first time, many extra parameters
are available. This new variable allows these to be passed. A typical
example is passing --staging in order to use the letsencrypt staging
endpoint rather than the production one.

Change-Id: I42f9e1f68c3a3533a3377f37063f4924cdf77bd6
2020-04-23 19:32:08 +01:00
Jonathan Rosser f35867466c Add extra controls for frontend redirects
This patch adds two new variables for a service:

* haproxy_redirect_scheme

This variable allows a custom string to be specified to override
the default condition used to redirect http to https.

* haproxy_frontend_acls

This variable works in the same way as haproxy_acls except it applies
the acl to the frontend rather than the backend configuration. This
can be required when some paths are not redirected to https but must
instead be handled by a specific backend.

Change-Id: I6b13375ba738d7659681ca773297d0b6b0fd7efb
2020-04-23 19:32:06 +01:00
Magnus Bergman 049b479b65 Add options to override which addresses haproxy binds to
Adding options to be able to override the default behaviour of
haproxy binding to external_lb_vip_address and internal_lb_vip_address.

The default behaviour stays the same after this change.

Change-Id: I76044aea498d73e97087719279ba0a37a9eb28e9
2020-03-02 14:29:12 +01:00
Magnus Bergman 693cdb1afc Align the usage of the two extra lb vip parameters
As extra_lb_tls_vip_addresses required a default due to how it's used
I'm also adding a default for extra_lb_vip_addresses and removing the if
defined for it for clarity.

Change-Id: If217f811dab9cfa2f459f5f50bc67bcf31ddbaaa
2020-02-04 11:57:05 +01:00
Magnus Bergman b7834dd051 Add support for extra VIPs with TLS enabled
The existing extra_lb_vip_addresses parameter will add extra haproxy
VIPs without TLS. This patch adds a new extra_lb_tls_vip_addresses
parameter for adding VIPs with TLS enabled.

Change-Id: Ib6f38200775d31633d57a680fae475dbf7abc6c9
2020-01-31 15:38:22 +01:00
Georgina Shippey 38f7ec04bc Make log socket available to chrooted filesystem
Had an issue where HAProxy logs could not be found.

The /dev/log socket was not available to the chrooted filesystem.
We need to mount the socket and persist it.

Change-Id: I2a1ce48f90c5f85b1238842f17ad2c9708333629
2019-12-02 14:03:33 +00:00
Zuul ca51879876 Merge "Variable to set HTTP keepalive mode" 2019-03-19 03:03:52 +00:00
Gaudenz Steinlin e911f3f2d2 Variable to set HTTP keepalive mode
The HTTP keepalive mode is currently hardcoded to "http-server-close"
for all HTTP services. This disables keepalive for HAProxy to backend
connections, but leaves it enabled for client connections to HAProxy.
This is problematic especially for service to service calls (e.g.
nova-api to neutron). If a request is made at the same time the HAProxy
keepalive timeout expires, the result of the request is undefined. This
leads to code 500 error responses from the nova-api because the request
from nova-api to neutron failed. "Connection aborted" error messages in
the logs are an indication of this issue.

There is also a bug report[1] about the same issue in devstack which was
solved by disabling keepalive and a script[2] to reproduce the issue in
devstack.

This adds a default and per service variables to set the HTTP keepalive
mode used by HAProxy. The default value is changed to "forceclose" to
disable HTTP keepalive on the server and client side. With HTTP
keepalive disabled the issue can no longer be reproduced.

[1] https://bugs.launchpad.net/devstack/+bug/1630664
[2] https://github.com/JordanP/openstack-snippets/blob/master/keepalive-race/keep-alive-race.py

Change-Id: If819912873270f0568974925490023310f9cbd66
2019-03-04 18:29:25 +01:00
Frank Kloeker b9cb133bb0 Fix venv installation of Letsencrypt certbot
certbot-auto wants to install depedencies which are possibly
not fulfilled by the repo-server - so bypass installation here.
Use the venv bin later for the renew script.
Minor errors are also fixed.

Change-Id: I4087bbcb4fe6182cb090a5b6b85bea36768b4f4f
2019-02-02 01:14:18 +01:00
Frank Kloeker 4fb2059a3b Add feature Letsencrypt SSL certification
- installs certbot-auto
- generates and validates ssl cert
- installs cert in haproxy settings
- renew cert with cron

Change-Id: Iea59ec2893a988b184ca8bc70e1d273ac071551e
2019-01-17 17:54:50 +01:00
Zuul 7d8b9f31ad Merge "Force force-tlsv12 only" 2018-12-17 17:16:45 +00:00
Matthew Thode 547d7f91be
Force force-tlsv12 only
Secure by default

Change-Id: I70007af94bfd5e482662ab72d25bf090cf5d0834
2018-12-13 14:20:37 -06:00