]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4599] Checkpoint: should work
authorFrancis Dupont <fdupont@isc.org>
Wed, 5 Aug 2026 19:57:12 +0000 (21:57 +0200)
committerFrancis Dupont <fdupont@isc.org>
Mon, 10 Aug 2026 21:11:26 +0000 (23:11 +0200)
changelog_unreleased/4599-HA-listener-auth-implement [new file with mode: 0644]
src/hooks/dhcp/high_availability/ha_config.cc
src/hooks/dhcp/high_availability/ha_config.h
src/hooks/dhcp/high_availability/ha_config_parser.cc
src/hooks/dhcp/high_availability/ha_service.cc

diff --git a/changelog_unreleased/4599-HA-listener-auth-implement b/changelog_unreleased/4599-HA-listener-auth-implement
new file mode 100644 (file)
index 0000000..6caf56c
--- /dev/null
@@ -0,0 +1,4 @@
+[bug]          fdupont
+       Implemented HTTP basic authentication for HA dedicated
+       listener, before such configuration was silently ignored.
+       (Gitlab #4599)
index 00c4e635a7eb54e34cbb2272e4aa8efbaa400f99..d7e9afe69a55c95aa2b1c88f5610dc9a248492c7 100644 (file)
@@ -32,7 +32,8 @@ namespace ha {
 
 HAConfig::PeerConfig::PeerConfig()
     : tls_context_(), name_(), url_(""), trust_anchor_(), cert_file_(),
-      key_file_(), role_(STANDBY), auto_failover_(false), basic_auth_() {
+      key_file_(), role_(STANDBY), auto_failover_(false), basic_auth_(),
+      basic_auth_config_() {
 }
 
 void
index d3f0e4835c4d9216363f81fcc20148fad4edc74e..b21f68b5cdc1c212cbcbc985becf25b70ae3d714 100644 (file)
@@ -11,7 +11,7 @@
 #include <asiolink/crypto_tls.h>
 #include <dhcpsrv/subnet.h>
 #include <exceptions/exceptions.h>
-#include <http/basic_auth.h>
+#include <http/basic_auth_config.h>
 #include <http/post_request_json.h>
 #include <http/url.h>
 #include <util/optional.h>
@@ -220,6 +220,16 @@ public:
         /// when credentials are specified.
         void addBasicAuthHttpHeader(http::PostHttpRequestJsonPtr request) const;
 
+        /// @brief Returns non-const basic HTTP authentication configuration.
+        http::BasicHttpAuthConfigPtr& getBasicAuthConfig() {
+            return (basic_auth_config_);
+        }
+
+        /// @brief Returns const basic HTTP authentication configuration.
+        const http::BasicHttpAuthConfigPtr& getBasicAuthConfig() const {
+            return (basic_auth_config_);
+        }
+
         /// @brief Server TLS context.
         ///
         /// @note: if you make it protected or private please make
@@ -236,6 +246,7 @@ public:
         Role role_;                                 ///< Server role.
         bool auto_failover_;                        ///< Auto failover state.
         http::BasicHttpAuthPtr basic_auth_;         ///< Basic HTTP authentication.
+        http::BasicHttpAuthConfigPtr basic_auth_config_; ///< Basic HTTP authentication configuration.
     };
 
     /// @brief Pointer to the server's configuration.
index febb761a883add7d36d304d4f8abddfcb3fe16e2..d4608228bb13ecb8aaa85c27adaef2e8cc7caa59 100644 (file)
@@ -323,9 +323,9 @@ HAConfigParser::parseOne(const HAConfigMapperPtr& config_storage,
             }
             password = getString(p, "basic-auth-password");
         }
+        std::string password_file;
         if (p->contains("basic-auth-password-file")) {
-            std::string password_file =
-                getString(p, "basic-auth-password-file");
+            password_file = getString(p, "basic-auth-password-file");
             try {
                 password = util::file::getContent(password_file);
             } catch (const std::exception& ex) {
@@ -348,9 +348,9 @@ HAConfigParser::parseOne(const HAConfigMapperPtr& config_storage,
             user = getString(p, "basic-auth-user");
             do_auth = true;
         }
+        std::string user_file;
         if (p->contains("basic-auth-user-file")) {
-            std::string user_file =
-                getString(p, "basic-auth-user-file");
+            user_file = getString(p, "basic-auth-user-file");
             try {
                 user = util::file::getContent(user_file);
                 do_auth = true;
@@ -361,10 +361,13 @@ HAConfigParser::parseOne(const HAConfigMapperPtr& config_storage,
         }
         if (do_auth) {
             BasicHttpAuthPtr& auth = cfg->getBasicAuth();
+            BasicHttpAuthConfigPtr& auth_config = cfg->getBasicAuthConfig();
             try {
                 if (!user.empty()) {
                     // Validate the user id value.
                     auth.reset(new BasicHttpAuth(user, password));
+                    auth_config.reset(new BasicHttpAuthConfig);
+                    auth_config->add(user, user_file, password, password_file);
                 }
             } catch (const std::exception& ex) {
                 isc_throw(dhcp::DhcpConfigError, ex.what() << " in peer '"
index 7cca885e75983303c8ed8c37bb4706c85371ac8f..30c3049bcfb60f4fd87a2d2e6299378dc17d0b33 100644 (file)
@@ -123,9 +123,8 @@ HAService::HAService(const unsigned int id, const IOServicePtr& io_service,
             auto tls_context = config_->getThisServerConfig()->getTlsContext();
 
             // Set the HTTP basic authentication.
-            HttpAuthConfigPtr auth_config;
-            // Wrong type: BasicHttpAuthPtr vs BasicHttpAuthConfigPtr
-            // auth_config = config_->getThisServerConfig()->getBasicAuth();
+            HttpAuthConfigPtr auth_config =
+                config_->getThisServerConfig()->getBasicAuthConfig();
 
             // Set the command filter when enabled.
             std::unordered_set<std::string> command_accept_list;