]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: config: Add "cluster-secret" new global keyword
authorFrédéric Lécaille <flecaille@haproxy.com>
Fri, 6 May 2022 06:53:16 +0000 (08:53 +0200)
committerFrédéric Lécaille <flecaille@haproxy.com>
Thu, 12 May 2022 15:48:35 +0000 (17:48 +0200)
It could be usefull to set a ASCII secret which could be used for different
usages. For instance, it will be used to derive QUIC stateless reset tokens.

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

index 23fc72b3e9bc8ec51352b6e9ad87bf202c67b1c9..d5283270c25b74202df5a96a96e7c5f0bd93be00 100644 (file)
@@ -992,6 +992,7 @@ The following keywords are supported in the "global" section :
  * Process management and security
    - ca-base
    - chroot
+   - cluster-secret
    - crt-base
    - cpu-map
    - daemon
@@ -1161,6 +1162,13 @@ chroot <jail dir>
   with superuser privileges. It is important to ensure that <jail_dir> is both
   empty and non-writable to anyone.
 
+cluster-secret <secret>
+  Define an ASCII string secret shared between several nodes belonging to the
+  same cluster. It could be used for different usages. It is at least used to
+  derive stateless reset tokens for all the QUIC connections instantiated by
+  this process. If you do not set this parameter, the stateless reset QUIC
+  feature will be silently disabled.
+
 close-spread-time <time>
   Define a time window during which idle connections and active connections
   closing is spread in case of soft-stop. After a SIGUSR1 is received and the
index 7b8c2e6b82ded1b14225fb7c0bd9e862b22cbef4..fbbc88da33db4276ec327201feefa4370624e815 100644 (file)
@@ -130,6 +130,7 @@ struct global {
        char *log_send_hostname;   /* set hostname in syslog header */
        char *server_state_base;   /* path to a directory where server state files can be found */
        char *server_state_file;   /* path to the file where server states are loaded from */
+       char *cluster_secret;      /* Secret defined as ASCII string */
        struct {
                int maxpollevents; /* max number of poll events at once */
                int maxaccept;     /* max number of consecutive accept() */
index b4dd849488839558dadde86cff58c68aefb44ccf..85b44df5ffc94b63a030dff18a320f9694c108f0 100644 (file)
@@ -45,7 +45,7 @@ static const char *common_kw_list[] = {
        "log-tag", "spread-checks", "max-spread-checks", "cpu-map", "setenv",
        "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer",
        "numa-cpu-mapping", "defaults", "listen", "frontend", "backend",
-       "peers", "resolvers",
+       "peers", "resolvers", "cluster-secret",
        NULL /* must be last */
 };
 
@@ -486,6 +486,22 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
        }
+       else if (strcmp(args[0], "cluster-secret") == 0) {
+               if (alertif_too_many_args(1, file, linenum, args, &err_code))
+                       goto out;
+               if (*args[1] == 0) {
+                       ha_alert("parsing [%s:%d] : expects an ASCII string argument.\n", file, linenum);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+               if (global.cluster_secret != NULL) {
+                       ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
+                       err_code |= ERR_ALERT;
+                       goto out;
+               }
+               ha_free(&global.cluster_secret);
+               global.cluster_secret = strdup(args[1]);
+       }
        else if (strcmp(args[0], "uid") == 0) {
                if (alertif_too_many_args(1, file, linenum, args, &err_code))
                        goto out;
index 48d588436fa0e4c74731a5d4fdea045ff34d69d1..13fda2d962c61e56cc0c883986bbc0ed40584e09 100644 (file)
@@ -2450,6 +2450,7 @@ int check_config_validity()
        struct cfg_postparser *postparser;
        struct resolvers *curr_resolvers = NULL;
        int i;
+       int diag_no_cluster_secret = 0;
 
        bind_conf = NULL;
        /*
@@ -3947,6 +3948,8 @@ out_uri_auth_compat:
 #ifdef USE_QUIC
                        /* override the accept callback for QUIC listeners. */
                        if (listener->flags & LI_F_QUIC_LISTENER) {
+                               if (!global.cluster_secret)
+                                       diag_no_cluster_secret = 1;
                                listener->accept = quic_session_accept;
                                li_init_per_thr(listener);
                        }
@@ -3987,6 +3990,10 @@ out_uri_auth_compat:
                }
        }
 
+       if (diag_no_cluster_secret)
+               ha_diag_warning("No cluster secret was set. The stateless reset feature"
+                               " is disabled for all QUIC bindings.\n");
+
        /*
         * Recount currently required checks.
         */
index 266f5552bc0f003bf8be0d28f28380d61b75cb72..d2cfbc0f30dadc1df670e8bf177363e5ef947a2f 100644 (file)
@@ -2664,6 +2664,7 @@ void deinit(void)
        ha_free(&global.log_send_hostname);
        chunk_destroy(&global.log_tag);
        ha_free(&global.chroot);
+       ha_free(&global.cluster_secret);
        ha_free(&global.pidfile);
        ha_free(&global.node);
        ha_free(&global.desc);