]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: proxy: Warn about ambiguous use of named defaults sections
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 12 Oct 2021 16:57:43 +0000 (18:57 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 15 Oct 2021 12:12:19 +0000 (14:12 +0200)
It is now possible to designate the defaults section to use by adding a name
of the corresponding defaults section and referencing it in the desired
proxy section. However, this introduces an ambiguity. This named defaults
section may still be implicitly used by other proxies if it is the last one
defined. In this case for instance:

  default common
    ...

  default frt from common
    ...

  default bck from common
    ...

  frontend fe from frt
    ...

  backend be from bck
    ...

  listen stats
    ...

Here, it is not really obvious the last section will use the 'bck' defaults
section. And it is probably not the expected behaviour. To help users to
properly configure their haproxy, a warning is now emitted if a defaults
section is explicitly AND implicitly used. The configuration manual was
updated accordingly.

Because this patch adds a warning, it should probably not be backported to
2.4. However, if is is backported, it depends on commit "MINOR: proxy:
Introduce proxy flags to replace disabled bitfield".

doc/configuration.txt
include/haproxy/proxy-t.h
src/cfgparse-listen.c

index 5884507b51956f6b7e9d0432808e9a3781267897..01cf3192d17d38115d62451f412765b0442547b7 100644 (file)
@@ -3509,7 +3509,11 @@ any other section, its name must comply with the syntax imposed on all proxy
 names, and this name must be unique among the defaults sections. Please note
 that regardless of what is currently permitted, it is recommended to avoid
 duplicate section names in general and to respect the same syntax as for proxy
-names. This rule might be enforced in a future version.
+names. This rule might be enforced in a future version. In addition, a warning
+is emitted if a defaults section is explicitly used by a proxy while it is also
+implicitly used by another one because it is the last one defined. It is highly
+encouraged to not mix both usages by always using explicit references or by
+adding a last common defaults section reserved for all implicit uses.
 
 Note that it is even possible for a defaults section to take its initial
 settings from another one, and as such, inherit settings across multiple levels
index c38c339c8c856623be891544825348f644d8acef..b2285bbebd7198ead158cf98103d53ac8e954b97 100644 (file)
@@ -203,6 +203,8 @@ enum PR_SRV_STATE_FILE {
 /* Proxy flags */
 #define PR_FL_DISABLED           0x01  /* The proxy was disabled in the configuration (not at runtime) */
 #define PR_FL_STOPPED            0x02  /* The proxy was stopped */
+#define PR_FL_EXPLICIT_REF       0x08  /* The default proxy is explicitly referenced by another proxy */
+#define PR_FL_IMPLICIT_REF       0x10  /* The default proxy is implicitly referenced by another proxy */
 
 struct stream;
 
index f6589d18b84d35c9690b7b30382333b60d88b144..cd3f92b621906fe3bae06b39f8bc9ccff237f45f 100644 (file)
@@ -316,6 +316,16 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                         file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line);
                                err_code |= ERR_ALERT | ERR_FATAL;
                        }
+                       curr_defproxy->flags |= PR_FL_EXPLICIT_REF;
+               }
+               else if (curr_defproxy)
+                       curr_defproxy->flags |= PR_FL_IMPLICIT_REF;
+
+               if (curr_defproxy && (curr_defproxy->flags & (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) == (PR_FL_EXPLICIT_REF|PR_FL_IMPLICIT_REF)) {
+                       ha_alert("parsing [%s:%d] : defaults section '%s' (declared at %s:%d) is explicitly referenced by another proxy and implicitly used here."
+                                " To avoid any ambiguity don't mix both usage. Add a last defaults section not explicitly used or always use explicit references.\n",
+                                file, linenum, curr_defproxy->id, curr_defproxy->conf.file, curr_defproxy->conf.line);
+                       err_code |= ERR_WARN;
                }
 
                curproxy = parse_new_proxy(name, rc, file, linenum, curr_defproxy);