From: Willy Tarreau Date: Sat, 21 Nov 2026 22:09:38 +0000 (+0100) Subject: MEDIUM: server: add a global setting "unresolvable-server-fqdn" X-Git-Tag: v3.5-dev14~23 X-Git-Url: https://git.kaiwu.me/http/%22../static/gitweb.js?a=commitdiff_plain;h=6da41b95f41548e1e51a966374fb8827f340afac;p=haproxy.git MEDIUM: server: add a global setting "unresolvable-server-fqdn" Recent fix 612b87e75 ("BUG/MEDIUM: resolvers: reject too long labels when encoding a name") revealed deployment bugs where users are relying on DNS labels longer than 63 chars, which have obviously never worked. The problem is that before they would fail silently and now the config refuses to start. When configs are orchestrated, often users have long lost any control on what happens and only have to endure what their orchestrator decides for them, so it can take ages before they figure how to fix that. This patch adds a global option to detect the situation at server registration time, and to emit a warning and force the server to maintenance instead of hard-failing. It is only meant to be used as a workaround for the time it takes to fix the configuration, and must never be left enabled since it will silently let broken configs start. It will help to backport this patch where the commit above was backported, i.e. 2.6, with a change to warn by default and indicating that this will change in 3.5. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 44d353595..fd50e19b2 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -1874,6 +1874,7 @@ The following keywords are supported in the "global" section : - presetenv - prealloc-fd - resetenv + - unresolvable-server-fqdn - set-dumpable - set-var - setenv @@ -4100,6 +4101,18 @@ unix-bind [ prefix ] [ mode ] [ user ] [ uid ] both are specified, the "bind" statement has priority, meaning that the "unix-bind" settings may be seen as process-wide default settings. +unresolvable-server-fqdn [ fail | warn ] + Server names with more than 63 characters per FQDN component cannot be + resolved by DNS (this is a limitation of the DNS protocol, not haproxy). Any + server with such a name will never work, and as any configuration error, will + trigger a fatal error preventing it from starting. However, some bogus + configuration generators may occasionally generate such invalid names without + checking them, preventing haproxy from starting. Similarly, hosting providers + might face the issue if their customers are free to choose any server name + without and input control. If this happens, setting this option to "warn" + will turn the error into a warning and will force the server into maintenance + mode so that it never tries to resolve. The default setting is "fail". + unsetenv [ ...] Removes environment variables specified in arguments. This can be useful to hide some sensitive information that are occasionally inherited from the diff --git a/src/server.c b/src/server.c index c67c15886..540791541 100644 --- a/src/server.c +++ b/src/server.c @@ -82,6 +82,7 @@ struct task *idle_conn_task[MAX_THREADS] __read_mostly = {}; struct list servers_to_init = LIST_HEAD_INIT(servers_to_init); static struct task *server_atomic_sync_task = NULL; static event_hdl_async_equeue server_atomic_sync_queue; +static int srv_unresolvable_fqdn_warn; /* SERVER DELETE(n)->ADD global tracker: * This is meant to provide srv->rid (revision id) value. @@ -3940,14 +3941,34 @@ static int _srv_parse_init(struct server **srv, char **args, int *cur_arg, if ((newsrv->srvrq = find_srvrq_by_name(fqdn, curproxy)) == NULL) newsrv->srvrq = new_resolv_srvrq(newsrv, fqdn); if (newsrv->srvrq == NULL) { + if (srv_unresolvable_fqdn_warn) { + ha_warning("%s %s/%s: invalid FQDN <%s>, skipping.\n", + (parse_flags & SRV_PARSE_TEMPLATE) ? "server-template" : "server", + curproxy->id, + (parse_flags & SRV_PARSE_TEMPLATE) ? args[2] : args[1], + fqdn); + (*cur_arg)++; + goto skip_addr; + } err_code |= ERR_ALERT | ERR_FATAL; goto out; } LIST_APPEND(&newsrv->srvrq->attached_servers, &newsrv->srv_rec_item); } else if (srv_prepare_for_resolution(newsrv, fqdn) == -1) { - ha_alert("Can't create DNS resolution for server '%s'\n", - newsrv->id); + if (srv_unresolvable_fqdn_warn) { + ha_warning("%s %s/%s: invalid FQDN <%s>, skipping.\n", + (parse_flags & SRV_PARSE_TEMPLATE) ? "server-template" : "server", + curproxy->id, + (parse_flags & SRV_PARSE_TEMPLATE) ? args[2] : args[1], + fqdn); + (*cur_arg)++; + goto skip_addr; + } + ha_alert("Can't create DNS resolution for server '%s' ('%s'). If you have no control " + "over the server's syntax and wish to start regardless of this error, please " + "consider setting 'unresolvable-server-fqdn' to 'warn'.\n", + newsrv->id, fqdn); err_code |= ERR_ALERT | ERR_FATAL; goto out; } @@ -8511,6 +8532,25 @@ static int cfg_parse_idle_pool_shared(char **args, int section_type, struct prox return 0; } +/* config parser for global "unresolvable-server-fqdn" */ +static int cfg_parse_unres_srv_fqdn(char **args, int section_type, struct proxy *curpx, + const struct proxy *defpx, const char *file, int line, + char **err) +{ + if (too_many_args(1, args, err, NULL)) + return -1; + + if (strcmp(args[1], "warn") == 0) + srv_unresolvable_fqdn_warn = 1; + else if (strcmp(args[1], "fail") == 0) + srv_unresolvable_fqdn_warn = 0; + else { + memprintf(err, "'%s' expects either 'warn' or 'fail'", args[0]); + return -1; + } + return 0; +} + /* config parser for global "tune.pool-{low,high}-fd-ratio" */ static int cfg_parse_pool_fd_ratio(char **args, int section_type, struct proxy *curpx, const struct proxy *defpx, const char *file, int line, @@ -8538,6 +8578,7 @@ static int cfg_parse_pool_fd_ratio(char **args, int section_type, struct proxy * /* config keyword parsers */ static struct cfg_kw_list cfg_kws = {ILH, { + { CFG_GLOBAL, "unresolvable-server-fqdn", cfg_parse_unres_srv_fqdn }, { CFG_GLOBAL, "tune.idle-pool.shared", cfg_parse_idle_pool_shared }, { CFG_GLOBAL, "tune.pool-high-fd-ratio", cfg_parse_pool_fd_ratio }, { CFG_GLOBAL, "tune.pool-low-fd-ratio", cfg_parse_pool_fd_ratio },