Commit Graph

14799 Commits

Author SHA1 Message Date
Remi Tricot-Le Breton
653a16769a DOC: internals: update the SSL architecture schema
Add the new relation between the CA file tree entries and the ckch
instances introduced during CA file hot update implementation (see
GitHub #1057).
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
e88a2caf9c DOC: ssl: Add documentation about CA file hot update commands
Add documentations for "abort/commit/del/new/set/show ssl ca-file" CLI
commands.

These commands were added to answer to GitHub #1057.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
efcc5b28d1 REGTESTS: ssl: Add "new/del ssl ca-file" tests
This vtc tests the "new ssl ca-file" which allows to create a new empty
CA file that can then be set through a "set+commit ssl ca-file" command
pair. It also tests the "del ssl ca-file" command which allows to delete
an unused CA file.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
c3a8477776 MINOR: ssl: Add "del ssl ca-file" CLI command
This patch adds the "del ssl ca-file <cafile>" CLI command which can be
used to delete an unused CA file.
The CA file will be considered unused if its list of ckch instances is
empty. This command cannot be used to delete the uncommitted CA file of
a previous "set ssl ca-file" without commit. It only acts on
CA file entries already inserted in the CA file tree.

This fixes a subpart of GitHub issue #1057.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
9f40fe0202 MEDIUM: ssl: Add "new ssl ca-file" CLI command
This patch adds the "new ssl ca-file <cafile>" CLI command. This command
can be used to create a new empty CA file that can be filled in thanks
to a "set ssl ca-file" command. It can then be used in a new crt-list
line.
The newly created CA file is added directly in the cafile tree so any
following "show ssl ca-file" call will display its name.

This fixes a subpart of GitHub issue #1057.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
2a22e16cb8 MEDIUM: ssl: Add "show ssl ca-file" CLI command
This patch adds the "show ssl ca-file [<cafile>[:index]]" CLI command.
This command can be used to display the list of all the known CA files
when no specific file name is specified, or to display the details of a
specific CA file when a name is given. If an index is given as well, the
command will only display the certificate having the specified index in
the CA file (if it exists).
The details displayed for each certificate are the same as the ones
showed when using the "show ssl cert" command on a single certificate.

This fixes a subpart of GitHub issue #1057.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
523f0e483a MINOR: ssl: Refactorize the "show certificate details" code
Move all the code that dumps the details of a specific certificate into
a dedicated function so that it can be used elsewhere.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
0bb482436c MINOR: ssl: Add a cafile_entry type field
The CA files and CRL files are stored in the same cafile_tree so this
patch adds a new field the the cafile_entry structure that specifies the
type of the entry. Since a ca-file can also have some CRL sections, the
type will be based on the option used to load the file and not on its
content (ca-file vs crl-file options).
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
d5fd09d339 MINOR: ssl: Add "abort ssl ca-file" CLI command
The "abort" command aborts an ongoing transaction started by a "set ssl
ca-file" command. Since the updated CA file data is not pushed into the
cafile tree until a "commit ssl ca-file" call is performed, the abort
command simply clears the new cafile_entry that was stored in the
cafile_transaction.

This fixes a subpart of GitHub issue #1057.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
2db6101ed7 REGTESTS: ssl: Add new ca-file update tests
This vtc tests the "set ssl ca-file" and "commit ssl ca-file" cli
commands. Those commands allow the hot update of CA files through cli
commands.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
a32a68bd3b MEDIUM: ssl: Add "set+commit ssl ca-file" CLI commands
This patch adds the "set ssl ca-file" and "commit ssl ca-file" commands,
following the same logic as the certificate update equivalents.
When trying to update a ca-file entry via a "set" command, we start by
looking for the entry in the cafile_tree and then building a new
cafile_entry out of the given payload. This new object is not added to
the cafile_tree until "commit" is called.
During a "commit" command, we insert the newly built cafile_entry in the
cafile_tree, while keeping the previous entry as well. We then iterate
over all the instances linked in the old cafile_entry and rebuild a new
ckch instance for every one of them. The newly inserted cafile_entry is
used for all those new instances and their respective SSL contexts.
When all the contexts are properly created, the old instances get
replaced by the new ones and the old cafile_entry is removed from the
tree.

This fixes a subpart of GitHub issue #1057.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
bfadc02f34 MINOR: ssl: Ckch instance rebuild and cleanup factorization in CLI handler
The process of rebuilding a ckch_instance when a certificate is updated
through a cli command will be roughly the same when a ca-file is updated
so this factorization will avoid code duplication.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
38c999b11c MINOR: ssl: Add helper function to add cafile entries
Adds a way to insert a new uncommitted cafile_entry in the tree. This
entry will be the one fetched by any lookup in the tree unless the
oldest cafile_entry is explicitely looked for. This way, until a "commit
ssl ca-file" command is completed, there could be two cafile_entries
with the same path in the tree, the original one and the newly updated
one.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
383fb1472e MEDIUM: ssl: Add a way to load a ca-file content from memory
The updated CA content coming from the CLI during a ca-file update will
directly be in memory and not on disk so the way CAs are loaded in a
cafile_entry for now (via X509_STORE_load_locations calls) cannot be
used.
This patch adds a way to fill a cafile_entry directly from memory and to
load the contained certificate and CRL sections into an SSL store.
CRL sections are managed as well as certificates in order to mimic the
way CA files are processed when specified in an option. Indeed, when
parsing a CA file given through a ca-file or ca-verify-file option, we
iterate over the different sections in ssl_set_cert_crl_file and load
them regardless of their type. This ensures that a file that was
properly parsed when given as an option will also be accepted by the
CLI.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
5daff3c8ab MINOR: ssl: Add helper functions to create/delete cafile entries
Add ssl_store_create_cafile_entry and ssl_store_delete_cafile_entry
functions.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
40ddea8222 MINOR: ssl: Add reference to default ckch instance in bind_conf
In order for the link between the cafile_entry and the default ckch
instance to be built, we need to give a pointer to the instance during
the ssl_sock_prepare_ctx call.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
4458b9732d MEDIUM: ssl: Chain ckch instances in ca-file entries
Each ca-file entry of the tree will now hold a list of the ckch
instances that use it so that we can iterate over them when updating the
ca-file via a cli command. Since the link between the SSL contexts and
the CA file tree entries is only built during the ssl_sock_prepare_ctx
function, which are called after all the ckch instances are created, we
need to add a little post processing after each ssl_sock_prepare_ctx
that builds the link between the corresponding ckch instance and CA file
tree entries.
In order to manage the ca-file and ca-verify-file options, any ckch
instance can be linked to multiple CA file tree entries and any CA file
entry can link multiple ckch instances. This is done thanks to a
dedicated list of ckch_inst references stored in the CA file tree
entries over which we can iterate (during an update for instance). We
avoid having one of those instances go stale by keeping a list of
references to those references in the instances.
When deleting a ckch_inst, we can then remove all the ckch_inst_link
instances that reference it, and when deleting a cafile_entry, we
iterate over the list of ckch_inst reference and clear the corresponding
entry in their own list of ckch_inst_link references.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
9f0c936057 MINOR: ssl: Allow duplicated entries in the cafile_tree
In order to ease ca-file hot update via the CLI, the ca-file tree will
need to allow duplicate entries for a given path. This patch simply
enables it and offers a way to select either the oldest entry or the
latest entry in the tree for a given path.
2021-05-17 10:50:24 +02:00
Remi Tricot-Le Breton
af8820a9a5 CLEANUP: ssl: Move ssl_store related code to ssl_ckch.c
This patch moves all the ssl_store related code to ssl_ckch.c since it
will mostly be used there once the CA file update CLI commands are all
implemented. It also makes the cafile_entry structure visible as well as
the cafile_tree.
2021-05-17 10:50:24 +02:00
Willy Tarreau
1f97306ecc [RELEASE] Released version 2.5-dev0
Released version 2.5-dev0 with the following main changes :
    - MINOR: version: it's development again
2021-05-14 09:36:37 +02:00
Willy Tarreau
1cb9fe7a75 MINOR: version: it's development again
this essentially reverts 46fb37c70c.
2021-05-14 09:36:08 +02:00
Willy Tarreau
6cbbecf097 [RELEASE] Released version 2.4.0
Released version 2.4.0 with the following main changes :
    - BUG/MINOR: http_fetch: fix possible uninit sockaddr in fetch_url_ip/port
    - CLEANUP: cli/activity: Remove double spacing in set profiling command
    - CI: Build VTest with clang
    - CI: extend spellchecker whitelist, add "ists" as well
    - CLEANUP: assorted typo fixes in the code and comments
    - BUG/MINOR: memprof: properly account for differences for realloc()
    - MINOR: memprof: also report the method used by each call
    - MINOR: memprof: also report the totals and delta alloc-free
    - CLEANUP: pattern: remove the unused and dangerous pat_ref_reload()
    - BUG/MINOR: http_act: Fix normalizer names in error messages
    - MINOR: uri_normalizer: Add `fragment-strip` normalizer
    - MINOR: uri_normalizer: Add `fragment-encode` normalizer
    - IMPORT: slz: use the generic function for the last bytes of the crc32
    - IMPORT: slz: do not produce the crc32_fast table when CRC is natively supported
    - BUILD/MINOR: opentracing: fixed compilation with filter enabled
    - BUILD: makefile: add a few popular ARMv8 CPU targets
    - BUG/MEDIUM: stick_table: fix crash when using tcp smp_fetch_src
    - REGTESTS: stick-table: add src_conn_rate test
    - CLEANUP: stick-table: remove a leftover of an old keyword declaration
    - BUG/MINOR: stats: fix lastchk metric that got accidently lost
    - EXAMPLES: add a "basic-config-edge" example config
    - EXAMPLES: add a trivial config for quick testing
    - DOC: management: Correct example reload command in the document
    - Revert "CI: Build VTest with clang"
    - MINOR: activity/cli: optionally support sorting by address on "show profiling"
    - DEBUG: ssl: export ssl_sock_close() to see its symbol resolved in profiling
    - BUG/MINOR: lua/vars: prevent get_var() from allocating a new name
    - DOC: config: Fix configuration example for mqtt
    - BUG/MAJOR: config: properly initialize cpu_map.thread[] up to MAX_THREADS
    - BUILD: config: avoid a build warning on numa_detect_topology() without threads
    - DOC: update min requirements in INSTALL
    - IMPORT: slz: use inttypes.h instead of stdint.h
    - BUILD: sample: use strtoll() instead of atoll()
    - MINOR: version: mention that it's LTS now.
2021-05-14 09:03:30 +02:00
Willy Tarreau
46fb37c70c MINOR: version: mention that it's LTS now.
The version will be maintained up to around Q2 2026. Let's
also update the INSTALL file to mention this.
2021-05-14 09:02:22 +02:00
Willy Tarreau
fb601956db BUILD: sample: use strtoll() instead of atoll()
atoll() is not portable, but strtoll() is more common. We must pass NULL
to the end pointer however since the parser must consume digits and stop
at the first non-digit char. No backport is needed as this was introduced
in 2.4-dev17 with commit 51c8ad45c ("MINOR: sample: converter: Add json_query
converter").
2021-05-14 08:51:53 +02:00
Willy Tarreau
388fc25915 IMPORT: slz: use inttypes.h instead of stdint.h
stdint.h is not as portable as inttypes.h. It doesn't exist at least
on AIX 5.1 and Solaris 7, while inttypes.h is present there and does
include stdint.h on platforms supporting it.

This is equivalent to libslz upstream commit e36710a ("slz: use
inttypes.h instead of stdint.h")
2021-05-14 08:44:52 +02:00
Willy Tarreau
c5aa060643 DOC: update min requirements in INSTALL
gcc 11 was tested, and the build dir now needs more like 60 MB than 15 MB.
2021-05-14 08:36:16 +02:00
Willy Tarreau
6bfc10c392 BUILD: config: avoid a build warning on numa_detect_topology() without threads
The function is defined when using linux+cpu affinity but is only used
if threads are enabled, so let's add this condition to avoid aa build
warning about an unused function when building with thread disabled.
This came in 2.4-dev17 with commit b56a7c89a ("MEDIUM: cfgparse: detect
numa and set affinity if needed") so no backport is needed.
2021-05-14 08:30:46 +02:00
Willy Tarreau
26f42a0779 BUG/MAJOR: config: properly initialize cpu_map.thread[] up to MAX_THREADS
A mistake was introduced in 2.4-dev17 by commit 982fb5339 ("MEDIUM:
config: use platform independent type hap_cpuset for cpu-map"), it
initializes cpu_map.thread[] from 0 to MAX_PROCS-1 instead of
MAX_THREADS-1 resulting in crashes when the two differ, e.g. when
building with USE_THREAD= but still with USE_CPU_AFFINITY=1.

No backport is needed.
2021-05-14 08:26:38 +02:00
Daniel Corbett
cc9d9b0906 DOC: config: Fix configuration example for mqtt
This patch fixes the example for mqtt_is_valid(), it was missing
curly braces within the ACL.
2021-05-13 18:10:35 +02:00
Willy Tarreau
89f6dedf48 BUG/MINOR: lua/vars: prevent get_var() from allocating a new name
Variable names are stored into a unified list that helps compare them
just based on a pointer instead of duplicating their name with every
variable. This is convenient for those declared in the configuration
but this started to cause issues with Lua when random names would be
created upon each access, eating lots of memory and CPU for lookups,
hence the work in 2.2 with commit 4e172c93f ("MEDIUM: lua: Add
`ifexist` parameter to `set_var`") to address this.

But there remains a corner case with get_var(), which also allocates
a new variables. After a bit of thinking and discussion, it never
makes sense to allocate a new variable name on get_var():
  - if the name exists, it will be returned ;
  - if it does not exist, then the only way for it to appear will
    be that some code calls set_var() on it
  - a call to get_var() after a careful set_var(ifexist) ruins the
    effort on set_var().

For this reason, this patch addresses this issue by making sure that
get_var() will never cause a variable to be allocated. This is done
by modifying vars_get_by_name() to always call register_name() with
alloc=0, since vars_get_by_name() is exclusively used by Lua and the
new CLI's "get/set var" which also benefit from this protection.

It probably makes sense to backport this as far as 2.2 after some
observation period and feedback from users.

For more context and discussions about the issues this was causing,
see https://www.mail-archive.com/haproxy@formilux.org/msg40451.html
and in issue #664.
2021-05-13 13:44:32 +02:00
Willy Tarreau
832e242b1f DEBUG: ssl: export ssl_sock_close() to see its symbol resolved in profiling
This function is one of the few high-profile, unresolved ones in the memory
profile output, let's have it resolve to ease matching of SSL allocations,
which are not easy to follow.
2021-05-13 10:11:03 +02:00
Willy Tarreau
f1c8a3846c MINOR: activity/cli: optionally support sorting by address on "show profiling"
"show profiling" by default sorts by usage/counts, which is suitable for
occasional use. But when called from scripts to monitor/search variations,
this is not very convenient. Let's add a new "byaddr" option to support
sorting the output by address. It also eases matching alloc/free calls
from within a same library, or reading grouped tasks costs by library.
2021-05-13 10:00:17 +02:00
Tim Duesterhus
b38b5c3d0d Revert "CI: Build VTest with clang"
The issue with VTest not building properly in gcc is fixed since commit
vtest/VTest@0730540c43. Revert the patch to keep
the CI configuration simple.

This reverts commit e61f53eb44.
2021-05-12 21:28:08 +02:00
varnav
5a3fe9fcbf DOC: management: Correct example reload command in the document
Current example is:

  `echo "reload" | socat /var/run/haproxy-master.sock`

it will cause socat error:

  `exactly 2 addresses required (there are 1); use option "-h" for help`

Correct working command is:

  `echo "reload" | socat /var/run/haproxy-master.sock stdin`
2021-05-12 20:35:41 +02:00
Willy Tarreau
89da7cf5d5 EXAMPLES: add a trivial config for quick testing
This config was taken from the example provided in the dpbench project.
It uses minimalistic keywords and is trivial to setup and adapt on any
test machine for a quick test. It can be convenient when comparing
different server platforms to pick the one delivering the best
performance in various dimensions (conn rate, req rate, ssl rate,
bit rate). It uses a single listener (optionally a second one with
SSL), a single server, power-of-two-choices (random(2)) algorithm,
and no privileged directive.
2021-05-12 17:54:56 +02:00
Willy Tarreau
71c5f6d477 EXAMPLES: add a "basic-config-edge" example config
This config uses TLS, HSTS, redirects, cache, compression, stats,
log to stderr, and simple load balancing in a simple and commented
config which could be used as a starter for many other ones,
especially in containers.
2021-05-12 17:50:16 +02:00
Willy Tarreau
973a937c5f BUG/MINOR: stats: fix lastchk metric that got accidently lost
Commit d3a9a4992 ("MEDIUM: stats: allow to select one field in
`stats_fill_sv_stats`") left one occurrence of a direct assignment
of stats[] instead of placing it into the <metric> variable, and it
was on ST_F_CHECK_STATUS. This resulted in the field being overwritten
with an empty one immediately after being set in stats_fill_sv_stats()
and the field to appear empty on the stats page.

No backport is needed as this was only for 2.4.
2021-05-12 17:50:16 +02:00
Willy Tarreau
4263f68b65 CLEANUP: stick-table: remove a leftover of an old keyword declaration
There was a leftover of an antique declaration commented out that has
now been superseded by new ones, let's remove it.
2021-05-12 17:50:16 +02:00
Amaury Denoyelle
94fd1339e7 REGTESTS: stick-table: add src_conn_rate test
Add a simple test which uses src_conn_rate stick table fetch. Limit the
connection rate to 3. The 4th connection should return a 403.
2021-05-12 15:30:03 +02:00
Amaury Denoyelle
c460c70ab7 BUG/MEDIUM: stick_table: fix crash when using tcp smp_fetch_src
Since the introduction of bc_src, smp_fetch_src from tcp_sample inspect
the kw argument to choose between the frontend or the backend source
address. However, for the stick tables, the argument is left to NULL.
This causes a segfault.

Fix the crash by explicitely set the kw argument to "src" to retrieve
the source address of the frontend side.

This bug was introduced by the following commit :
  7d081f02a4
  MINOR: tcp_samples: Add samples to get src/dst info of the backend connection

It does not need a backport as it is integrated in the current 2.4-dev
branch.

To reproduce the crash, I used the following config :

frontend fe
	bind :20080
	http-request track-sc0 src table foo
	http-request reject if { src_conn_rate(foo) gt 10 }
	use_backend h1

backend foo
	stick-table type ip size 200k expire 30s store conn_rate(60s)

backend h1
	server nginx 127.0.0.1:30080 check

This should fix the github issue #1247.
2021-05-12 15:30:03 +02:00
Willy Tarreau
40a871f09d BUILD: makefile: add a few popular ARMv8 CPU targets
This adds the following CPUs to the makefile:
  - armv81    : modern ARM cores (Cortex A55/A75/A76/A78/X1, Neoverse, Graviton2)
  - a72       : ARM Cortex-A72 or A73 (e.g. RPi4, Odroid N2, VIM3, AWS Graviton)
  - a53       : ARM Cortex-A53 or any of its successors in 64-bit mode (e.g. RPi3)
  - armv8-auto: both older and newer ARMv8 cores, with a minor runtime penalty

The reasons for these ones are:
  - a53 is the common denominator of all of its successors, and does
    support CRC32 which is used by the gzip compression, that the generic
    armv8-a does not ;

  - a72 supports the same features but is an out-of-order one that deserves
    better optimizations; it's found in a number of high-performance
    multi-core CPUs mainly oriented towards I/O and network processing
    (Armada 8040, NXP LX2160A, AWS Graviton), and more recently the
    Raspberry Pi 4. The A73 found in VIM3 and Odroid-N2 can use the same
    optimizations ;

  - armv81 is for generic ARMv8.1-A and above, automatically enables LSE
    atomics which are way more scalable, and CRC32. This one covers modern
    ARMv8 cores such as Cortex A55/A75/A76/A77/A78/X1 and the Neoverse
    family such as found in AWS's Graviton2. The LSE instructions are
    essential for large numbers of cores (8 and above).

  - armv8-auto dynamically enables support for LSE extensions when
    detected while still being compatible with older cores. There is a
    small performance penalty in doing this (~3%) but a same executable
    will perform optimally on a wider range of hardware. This should be
    the best option for distros. It requires gcc-10 or gcc-9.4 and above.

When no CPU is specified, GCC version 10.2 and above will automatically
implement the wrapper used to detect the LSE extensions.
2021-05-12 14:23:22 +02:00
Miroslav Zagorac
d2acd0b3a7 BUILD/MINOR: opentracing: fixed compilation with filter enabled
The inclusion of header files proxy.h and tools.h was added to the
addons/ot/include/include.h file.  Without this HAProxy cannot be
compiled if the OpenTracing filter is to be used.
2021-05-12 09:45:16 +02:00
Willy Tarreau
9e274280a4 IMPORT: slz: do not produce the crc32_fast table when CRC is natively supported
On ARM with native CRC support, no need to inflate the executable with
a 4kB CRC table, let's just drop it.

This is slz upstream commit d8715db20b2968d1f3012a734021c0978758f911.
2021-05-12 09:29:33 +02:00
Willy Tarreau
027fdcb168 IMPORT: slz: use the generic function for the last bytes of the crc32
This is the only place where we conditionally use the crc32_fast table,
better call the crc32_char inline function for this. This should also
reduce by ~1kB the L1 cache footprint of the compression when dealing
with small blocks, and at least shows a consistent 0.5% perf improvement.

This is slz upstream commit 075351b6c2513b548bac37d6582e46855bc7b36f.
2021-05-12 09:29:29 +02:00
Tim Duesterhus
dec1c36b3a MINOR: uri_normalizer: Add fragment-encode normalizer
This normalizer encodes '#' as '%23'.

See GitHub Issue #714.
2021-05-11 17:24:32 +02:00
Tim Duesterhus
c9e05ab2de MINOR: uri_normalizer: Add fragment-strip normalizer
This normalizer strips the URI's fragment component which should never be sent
to the server.

See GitHub Issue #714.
2021-05-11 17:23:46 +02:00
Tim Duesterhus
2f413136e9 BUG/MINOR: http_act: Fix normalizer names in error messages
These places were forgotten when the normalizers were renamed.

Bug introduced in 5be6ab269e, which is 2.4.
No backport needed.
2021-05-11 17:21:53 +02:00
Willy Tarreau
da7f11bfb5 CLEANUP: pattern: remove the unused and dangerous pat_ref_reload()
This function was not used anymore after the atomic updates were
implemented in 2.3, and it must not be used given that it does not
yield and can easily make the process hang for tens of seconds on
large acls/maps. Let's remove it before someone uses it as an
example to implement something else!
2021-05-11 16:49:55 +02:00
Willy Tarreau
f5fb858bb7 MINOR: memprof: also report the totals and delta alloc-free
Already had to perform too many additions by external scripts, it's
time to add the totals and delay alloc-free as a last line in the
output of the "show memory profiling".
2021-05-11 14:21:18 +02:00
Willy Tarreau
616491b7f7 MINOR: memprof: also report the method used by each call
This was planned but missing in the previous attempt, we really need to
see what is used at each place, especially due to realloc(). Now we
print the function used in front of the caller's address, as well as
the average alloc/free size per call.
2021-05-11 14:14:30 +02:00