]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: jwt: Do not keep ckch_store if jwt tree entry creation failed
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Thu, 26 Nov 2026 10:11:54 +0000 (11:11 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 26 Nov 2026 13:14:09 +0000 (14:14 +0100)
When a full certificate is provided directly as a second argument of the
"jwt_verify_cert" converter, we create the corresponding ckch_store and
insert it in the ckch_store tree so that it's treated as a regular
certificate. This helps in certificate management since that way the
certificate can be updated via the CLI.
With the latest changes in the JWT tree, we now always have a
corresponding JWT tree entry for every ckch_store, regardless of whether
they set the jwt flag or not. And in every other part of the ckch_store
building process apart the one modified in this patch, we were raising
an error and removing the new ckch_store if an error occurred during the
corresponding JWT tree entry creation.
This patch keeps this logic in the 'jwt_tree_load_cert' function as
well.

This patch can be backported to 3.4.

src/jwt.c

index ed70c5bd2095c5f0c84cb3747e5e91907d52d877..78576a1a7cc365e76e782bbc7ee3809f560c9a51 100644 (file)
--- a/src/jwt.c
+++ b/src/jwt.c
@@ -432,16 +432,32 @@ int jwt_tree_load_cert(char *path, int pathlen, const char *file, int line, char
                        goto end;
                }
 
+               store->conf.jwt = 1;
+               retval = jwt_tree_create_entry_from_store(store, err);
+               if (retval) {
+                       /* Something went wrong during the JWT tree entry
+                        * creation, likely an OOM, no point in inserting the
+                        * ckch_store in the tree if we cannot use it for JWT
+                        * validation. */
+                       ckch_store_free(store);
+                       HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);
+                       goto end;
+               }
+
                if (ebst_insert(&ckchs_tree, &store->node) != &store->node) {
+                       /* The ckch_store was not inserted in the tree so the
+                        * corresponding jwt tree entry would not be removed in
+                        * ckch_store_free. */
+                       jwt_tree_delete_entry(store->path);
                        ckch_store_free(store);
                        HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);
                        goto end;
                }
+       } else {
+               store->conf.jwt = 1;
+               retval = jwt_tree_create_entry_from_store(store, err);
        }
 
-       store->conf.jwt = 1;
-
-       retval = jwt_tree_create_entry_from_store(store, err);
 
        HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);