]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: server: reject from/name in peers section
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 1 Dec 2026 12:58:55 +0000 (13:58 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 1 Dec 2026 15:01:28 +0000 (16:01 +0100)
The new positional keywords 'from' and 'name' were introduced to extend
server inheritance. However, nothing was implemented to ensure they were
rejected in a peers section.

Thus, it would be possible for a peer server to inherit from a
default-server in a standard backend. This could cause unexpected
behavior as a peer server does not support the full keyword range of the
instances declared in standard proxies.

Clarify this situation by rejecting usage of these keywords in a peers
section. A fatal error is reported if this is encountered.

Note that _srv_parse_from() is still called for peers server and
default-server, as it is necessary to preserve the original unnamed
default-server overloading mechanism. The new error is only reported if
'from' is found.

This is not a breaking change since 'from' and 'name' were implemented
in the current dev branch.

No need to backport.

src/server.c

index 5407915414c7d366672b3d729ab508ec266c11d1..35e97a4e62c2762b7b095511a86a37c94d659269 100644 (file)
@@ -991,8 +991,13 @@ static int srv_parse_error_limit(char **args, int *cur_arg,
 static int srv_parse_from(char **args, int *cur_arg,
                           struct proxy *curproxy, struct server *newsrv, char **err)
 {
-       memprintf(err, "'%s' is a positional keyword. It must be specified"
-                      " before any other server setting", args[*cur_arg]);
+       if (curproxy->mode == PR_MODE_PEERS) {
+               memprintf(err, "'%s' not supported in a peers section", args[*cur_arg]);
+       }
+       else {
+               memprintf(err, "'%s' is a positional keyword. It must be specified"
+                              " before any other server setting", args[*cur_arg]);
+       }
        return ERR_ALERT | ERR_FATAL;
 }
 
@@ -4001,6 +4006,12 @@ static int _srv_parse_init(struct server **srv, char **args, int *cur_arg,
        else {
                /* Parse optional "name" default-server keyword. */
                if (*args[1] && strcmp(args[1], "name") == 0) {
+                       if (parse_flags & SRV_PARSE_IN_PEER_SECTION) {
+                               ha_alert("named default-server are not supported in a peers section.\n");
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
+
                        if (!*args[2]) {
                                ha_alert("default-server name: missing value.\n");
                                err_code |= ERR_ALERT | ERR_FATAL;
@@ -4130,6 +4141,12 @@ static int _srv_parse_from(struct server *srv, char **args, int *cur_arg,
        int err_code = ERR_NONE;
 
        if (strcmp(args[*cur_arg], "from") == 0) {
+               if (parse_flags & SRV_PARSE_IN_PEER_SECTION) {
+                       ha_alert("'%s' not supported in a peers section.\n", args[*cur_arg]);
+                       err_code |= ERR_FATAL | ERR_ALERT;
+                       goto out;
+               }
+
                if (!*args[*cur_arg + 1]) {
                        ha_alert("from: missing value.\n");
                        err_code |= ERR_FATAL | ERR_ALERT;