From c4620dcde30449323852684ae910c7263f89eed7 Mon Sep 17 00:00:00 2001 From: jean-christophe81 <98889244+jean-christophe81@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:56:13 +0200 Subject: [PATCH] * no native mysql authent * default mariadb plugins directory is configurable and set by default according to the os * no lib mariadb static link REFS: MON-120715 --- .../docker/Dockerfile.centreon-collect-alma8 | 2 +- .../docker/Dockerfile.centreon-collect-alma9 | 3 ++- ...ockerfile.centreon-collect-debian-bullseye | 3 ++- .../Dockerfile.centreon-collect-mysql-alma9 | 3 ++- ...ckerfile.centreon-collect-mysql-alma9-test | 3 ++- .github/scripts/collect-prepare-test-robot.sh | 4 ++-- .github/workflows/package-collect.yml | 2 +- CMakeLists.txt | 3 +++ broker/CMakeLists.txt | 11 +++++++--- broker/core/sql/CMakeLists.txt | 2 +- .../centreon/broker/sql/database_config.hh | 8 ++++++++ .../com/centreon/broker/sql/mysql_column.hh | 3 ++- .../centreon/broker/sql/mysql_connection.hh | 1 + broker/core/sql/src/database_config.cc | 20 ++++++++++++++----- broker/core/sql/src/mysql_connection.cc | 10 +++++++++- broker/test/CMakeLists.txt | 1 - broker/unified_sql/CMakeLists.txt | 10 ++++++++-- cmake.sh | 4 ++-- conanfile.txt | 1 - packaging/centreon-broker-core.yaml | 2 ++ tests/mysql_docker_conf/centreon16.cnf | 1 - 21 files changed, 71 insertions(+), 26 deletions(-) diff --git a/.github/docker/Dockerfile.centreon-collect-alma8 b/.github/docker/Dockerfile.centreon-collect-alma8 index 214d7e4b353..d005048a58f 100644 --- a/.github/docker/Dockerfile.centreon-collect-alma8 +++ b/.github/docker/Dockerfile.centreon-collect-alma8 @@ -56,7 +56,7 @@ dnf --best install -y cmake \ dnf update libarchive -pip3 install conan==1.62.0 --prefix=/usr --upgrade +pip3 install conan==1.64.0 --prefix=/usr --upgrade rm -rf ~/.conan/profiles/default EOF diff --git a/.github/docker/Dockerfile.centreon-collect-alma9 b/.github/docker/Dockerfile.centreon-collect-alma9 index cf4ae4073c4..31fc0f14b80 100644 --- a/.github/docker/Dockerfile.centreon-collect-alma9 +++ b/.github/docker/Dockerfile.centreon-collect-alma9 @@ -29,6 +29,7 @@ dnf --best install -y cmake \ openssh-server \ mariadb-server \ mariadb \ + mariadb-connector-c-devel \ gnutls-devel \ libgcrypt-devel \ lua-devel \ @@ -48,7 +49,7 @@ dnf --best install -y cmake \ nfpm \ sudo -pip3 install conan==1.62.0 --prefix=/usr --upgrade +pip3 install conan==1.64.0 --prefix=/usr --upgrade rm -rf ~/.conan/profiles/default EOF diff --git a/.github/docker/Dockerfile.centreon-collect-debian-bullseye b/.github/docker/Dockerfile.centreon-collect-debian-bullseye index ad84b3a0211..5b5b2cb8688 100644 --- a/.github/docker/Dockerfile.centreon-collect-debian-bullseye +++ b/.github/docker/Dockerfile.centreon-collect-debian-bullseye @@ -16,6 +16,7 @@ apt-get -y install cmake \ mariadb-server \ openssh-server \ libmariadb3 \ + libmariadb-dev \ librrd-dev \ libgnutls28-dev \ liblua5.3-dev \ @@ -50,7 +51,7 @@ localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python3 get-pip.py -pip3 install conan==1.62.0 +pip3 install conan==1.64.0 ln -s /usr/local/bin/conan /usr/bin/conan rm -rf ~/.conan/profiles/default diff --git a/.github/docker/Dockerfile.centreon-collect-mysql-alma9 b/.github/docker/Dockerfile.centreon-collect-mysql-alma9 index d548fe9c41f..b49516d8c7a 100644 --- a/.github/docker/Dockerfile.centreon-collect-mysql-alma9 +++ b/.github/docker/Dockerfile.centreon-collect-mysql-alma9 @@ -25,6 +25,7 @@ dnf --best install -y cmake \ gdb \ gettext \ git \ + mariadb-connector-c-devel \ ninja-build \ openssh-server \ mysql-server \ @@ -48,7 +49,7 @@ dnf --best install -y cmake \ nfpm \ sudo -pip3 install conan==1.62.0 --prefix=/usr --upgrade +pip3 install conan==1.64.0 --prefix=/usr --upgrade rm -rf ~/.conan/profiles/default EOF diff --git a/.github/docker/Dockerfile.centreon-collect-mysql-alma9-test b/.github/docker/Dockerfile.centreon-collect-mysql-alma9-test index 1f8b2678089..e0746f5e22c 100644 --- a/.github/docker/Dockerfile.centreon-collect-mysql-alma9-test +++ b/.github/docker/Dockerfile.centreon-collect-mysql-alma9-test @@ -20,6 +20,7 @@ dnf --best install -y gcc \ gdb \ git \ openssh-server \ + mariadb-connector-c \ mysql-server \ mysql \ gnutls \ @@ -41,7 +42,7 @@ dnf --best install -y gcc \ echo "install robot and dependencies" pip3 install -U robotframework robotframework-databaselibrary robotframework-httpctrl robotframework-examples pymysql python-dateutil psutil -pip3 install grpcio grpcio_tools py-cpuinfo cython unqlite gitpython boto3 +pip3 install grpcio grpcio_tools py-cpuinfo cython unqlite gitpython boto3 cryptography cd /tmp/collect diff --git a/.github/scripts/collect-prepare-test-robot.sh b/.github/scripts/collect-prepare-test-robot.sh index e0eb711bfb3..9ad027d2257 100755 --- a/.github/scripts/collect-prepare-test-robot.sh +++ b/.github/scripts/collect-prepare-test-robot.sh @@ -30,8 +30,8 @@ if [ $database_type == 'mysql' ]; then sleep 5 echo "########################### Init centreon database ############################" - mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED WITH mysql_native_password BY 'centreon';" - mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED WITH mysql_native_password BY 'centreon';" + mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED BY 'centreon'" + mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED BY 'centreon'" else echo "########################### Start MariaDB ######################################" if [ "$distrib" = "ALMALINUX" ]; then diff --git a/.github/workflows/package-collect.yml b/.github/workflows/package-collect.yml index e30c867ba59..0c0d7a6d010 100644 --- a/.github/workflows/package-collect.yml +++ b/.github/workflows/package-collect.yml @@ -76,7 +76,7 @@ jobs: - name: Compile sources run: | - sudo pip3 install conan==1.62.0 --prefix=/usr --upgrade + sudo pip3 install conan==1.64.0 --prefix=/usr --upgrade sudo conan install . -s compiler.cppstd=17 -s compiler.libcxx=libstdc++11 --build=missing diff --git a/CMakeLists.txt b/CMakeLists.txt index f40b3b16311..6df00302781 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,9 @@ set(CMAKE_PROGRAM_PATH ${CONAN_BIN_DIRS_PROTOBUF};${CMAKE_PROGRAM_PATH}) find_package(Protobuf REQUIRED) +include(FindPkgConfig) +pkg_check_modules(MARIADB REQUIRED libmariadb) + message(NOTICE "-- use protoc compiler: ${Protobuf_PROTOC_EXECUTABLE}") include(GNUInstallDirs) diff --git a/broker/CMakeLists.txt b/broker/CMakeLists.txt index 9462909cf3b..eec85da2593 100644 --- a/broker/CMakeLists.txt +++ b/broker/CMakeLists.txt @@ -66,12 +66,15 @@ endif() if(OS_DISTRIBUTOR STREQUAL "Debian" OR OS_DISTRIBUTOR STREQUAL "Ubuntu") message(STATUS "deb based os") add_definitions("-DMYSQL_SOCKET=\"/var/run/mysqld/mysqld.sock\"") + add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib/x86_64-linux-gnu/libmariadb3/plugin\"") elseif(OS_DISTRIBUTOR STREQUAL "CentOS" OR OS_DISTRIBUTOR STREQUAL "RedHat") message(STATUS "rpm based os") add_definitions("-DMYSQL_SOCKET=\"/var/lib/mysql/mysql.sock\"") + add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib64/mariadb/plugin\"") else() message(STATUS "other os: ${OS_DISTRIBUTOR}") - add_definitions("-DMYSQL_SOCKET=/tmp/mysql.sock") + add_definitions("-DMYSQL_SOCKET=\"/tmp/mysql.sock\"") + add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib/x86_64-linux-gnu/libmariadb3/plugin\"") endif() include_directories( @@ -79,13 +82,14 @@ include_directories( "${PROJECT_SOURCE_DIR}/neb/inc" "${CMAKE_SOURCE_DIR}/engine/inc" "${PROJECT_SOURCE_DIR}/core/multiplexing/inc" - "${PROJECT_SOURCE_DIR}/core/sql/inc") + "${PROJECT_SOURCE_DIR}/core/sql/inc" + "${MARIADB_INCLUDE_DIRS}") set(INC_DIR "${PROJECT_SOURCE_DIR}/core/inc/com/centreon/broker") set(SRC_DIR "${PROJECT_SOURCE_DIR}/core/src") set(TEST_DIR "${PROJECT_SOURCE_DIR}/core/test") add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE) -add_definitions(${spdlog_DEFINITIONS} ${mariadb-connector-c_DEFINITIONS}) +add_definitions(${spdlog_DEFINITIONS}) include_directories(${CONAN_INCLUDE_DIRS_MARIADB-CONNECTOR-C}) @@ -491,6 +495,7 @@ target_link_libraries( "-Wl,--no-whole-archive" CONAN_PKG::spdlog CONAN_PKG::grpc + ${MARIADB_LIBRARIES} stdc++fs) # Centreon Broker Watchdog diff --git a/broker/core/sql/CMakeLists.txt b/broker/core/sql/CMakeLists.txt index afb4d4340f2..2adb8cfcdbb 100644 --- a/broker/core/sql/CMakeLists.txt +++ b/broker/core/sql/CMakeLists.txt @@ -81,7 +81,7 @@ set(SOURCES add_library(sql STATIC ${SOURCES}) set_target_properties(sql PROPERTIES COMPILE_FLAGS "-fPIC") target_precompile_headers(sql PRIVATE ../precomp_inc/precomp.hpp) -target_link_libraries(sql CONAN_PKG::spdlog CONAN_PKG::mariadb-connector-c) +target_link_libraries(sql CONAN_PKG::spdlog) # if(WITH_TESTING) set( TESTS_SOURCES ${TESTS_SOURCES} # ${TESTS_DIR}/engine/start_stop.cc ${TESTS_DIR}/muxer/read.cc diff --git a/broker/core/sql/inc/com/centreon/broker/sql/database_config.hh b/broker/core/sql/inc/com/centreon/broker/sql/database_config.hh index a03a751d1d4..a36a81e0f26 100644 --- a/broker/core/sql/inc/com/centreon/broker/sql/database_config.hh +++ b/broker/core/sql/inc/com/centreon/broker/sql/database_config.hh @@ -77,6 +77,9 @@ class database_config { int get_connections_count() const; unsigned get_max_commit_delay() const; unsigned get_category() const; + const std::string& get_extension_directory() const { + return _extension_directory; + } void set_type(std::string const& type); void set_host(std::string const& host); @@ -89,6 +92,9 @@ class database_config { void set_queries_per_transaction(int qpt); void set_check_replication(bool check_replication); void set_category(unsigned category); + void set_extension_directory(std::string const& extension_directory) { + _extension_directory = extension_directory; + } database_config auto_commit_conf() const; @@ -107,6 +113,8 @@ class database_config { int _connections_count; unsigned _max_commit_delay; unsigned _category; + // where mariadb will find extension such as caching_sha2_password.so + std::string _extension_directory; }; std::ostream& operator<<(std::ostream& s, const database_config cfg); diff --git a/broker/core/sql/inc/com/centreon/broker/sql/mysql_column.hh b/broker/core/sql/inc/com/centreon/broker/sql/mysql_column.hh index f02dbac02fb..357e315bdb3 100644 --- a/broker/core/sql/inc/com/centreon/broker/sql/mysql_column.hh +++ b/broker/core/sql/inc/com/centreon/broker/sql/mysql_column.hh @@ -19,8 +19,9 @@ #ifndef CCB_DATABASE_MYSQL_COLUMN_HH #define CCB_DATABASE_MYSQL_COLUMN_HH -#include #include + +#include #include #include "com/centreon/broker/namespace.hh" diff --git a/broker/core/sql/inc/com/centreon/broker/sql/mysql_connection.hh b/broker/core/sql/inc/com/centreon/broker/sql/mysql_connection.hh index 965f4e7aa13..d67aebf9a5e 100644 --- a/broker/core/sql/inc/com/centreon/broker/sql/mysql_connection.hh +++ b/broker/core/sql/inc/com/centreon/broker/sql/mysql_connection.hh @@ -85,6 +85,7 @@ class mysql_connection { const std::string _pwd; const std::string _name; const int _port; + const std::string _extension_directory; const unsigned _max_second_commit_delay; time_t _last_commit; std::atomic _state; diff --git a/broker/core/sql/src/database_config.cc b/broker/core/sql/src/database_config.cc index 86a2aa60830..345c0b31b86 100644 --- a/broker/core/sql/src/database_config.cc +++ b/broker/core/sql/src/database_config.cc @@ -34,8 +34,9 @@ std::ostream& operator<<(std::ostream& s, const database_config cfg) { } s << "queries per transaction:" << cfg.get_queries_per_transaction() << " check replication:" << cfg.get_check_replication() - << " connnexion count:" << cfg.get_connections_count() - << " max comit delay:" << cfg.get_max_commit_delay() << 's'; + << " connection count:" << cfg.get_connections_count() + << " max commit delay:" << cfg.get_max_commit_delay() << 's' + << " extension_directory" << cfg.get_extension_directory(); return s; } @@ -48,7 +49,8 @@ database_config::database_config() : _queries_per_transaction(1), _check_replication(true), _connections_count(1), - _category(SHARED) {} + _category(SHARED), + _extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) {} /** * Constructor. @@ -89,14 +91,16 @@ database_config::database_config(const std::string& type, _check_replication(check_replication), _connections_count(connections_count), _max_commit_delay(max_commit_delay), - _category(SHARED) {} + _category(SHARED), + _extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) {} /** * Build a database configuration from a configuration set. * * @param[in] cfg Endpoint configuration. */ -database_config::database_config(config::endpoint const& cfg) { +database_config::database_config(config::endpoint const& cfg) + : _extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) { std::map::const_iterator it, end; end = cfg.params.end(); @@ -208,6 +212,11 @@ database_config::database_config(config::endpoint const& cfg) { } } else _max_commit_delay = 5; + + it = cfg.params.find("extension_directory"); + if (it != end) { + _extension_directory = it->second; + } } /** @@ -552,6 +561,7 @@ void database_config::_internal_copy(database_config const& other) { _check_replication = other._check_replication; _connections_count = other._connections_count; _max_commit_delay = other._max_commit_delay; + _extension_directory = other._extension_directory; } /** diff --git a/broker/core/sql/src/mysql_connection.cc b/broker/core/sql/src/mysql_connection.cc index 516858a3fc8..78aea399801 100644 --- a/broker/core/sql/src/mysql_connection.cc +++ b/broker/core/sql/src/mysql_connection.cc @@ -14,7 +14,8 @@ * limitations under the License. * * For more information : contact@centreon.com -*/ + */ + #include #include "com/centreon/broker/config/applier/init.hh" @@ -190,6 +191,9 @@ bool mysql_connection::_try_to_reconnect() { uint32_t timeout = 10; mysql_options(_conn, MYSQL_OPT_CONNECT_TIMEOUT, &timeout); + mysql_optionsv(_conn, MYSQL_PLUGIN_DIR, + (const void*)_extension_directory.c_str()); + if (!mysql_real_connect(_conn, _host.c_str(), _user.c_str(), _pwd.c_str(), _name.c_str(), _port, (_socket == "" ? nullptr : _socket.c_str()), @@ -837,6 +841,9 @@ void mysql_connection::_run() { uint32_t timeout = 10; mysql_options(_conn, MYSQL_OPT_CONNECT_TIMEOUT, &timeout); + mysql_optionsv(_conn, MYSQL_PLUGIN_DIR, + (const void*)_extension_directory.c_str()); + while (config::applier::mode != config::applier::finished && !mysql_real_connect(_conn, _host.c_str(), _user.c_str(), _pwd.c_str(), _name.c_str(), _port, @@ -1081,6 +1088,7 @@ mysql_connection::mysql_connection(const database_config& db_cfg, _pwd(db_cfg.get_password()), _name(db_cfg.get_name()), _port(db_cfg.get_port()), + _extension_directory(db_cfg.get_extension_directory()), _max_second_commit_delay(db_cfg.get_max_commit_delay()), _last_commit(db_cfg.get_queries_per_transaction() > 1 ? 0 diff --git a/broker/test/CMakeLists.txt b/broker/test/CMakeLists.txt index 9789e921698..b7f13c7d2d3 100644 --- a/broker/test/CMakeLists.txt +++ b/broker/test/CMakeLists.txt @@ -142,7 +142,6 @@ target_link_libraries( CONAN_PKG::fmt CONAN_PKG::spdlog CONAN_PKG::gtest - CONAN_PKG::mariadb-connector-c CONAN_PKG::openssl CONAN_PKG::grpc stdc++fs) diff --git a/broker/unified_sql/CMakeLists.txt b/broker/unified_sql/CMakeLists.txt index 91e88df946f..1b15c45b89a 100644 --- a/broker/unified_sql/CMakeLists.txt +++ b/broker/unified_sql/CMakeLists.txt @@ -63,8 +63,14 @@ set_target_properties("${UNIFIED_SQL}" PROPERTIES PREFIX "" COMPILE_FLAGS add_dependencies("${UNIFIED_SQL}" target_rebuild_message target_remove_graph_message target_neb) target_precompile_headers(${UNIFIED_SQL} PRIVATE precomp_inc/precomp.hpp) -target_link_libraries(${UNIFIED_SQL} rokerbase bbdo_storage CONAN_PKG::spdlog - CONAN_PKG::abseil pb_storage_lib) +target_link_libraries(${UNIFIED_SQL} + rokerbase + bbdo_storage + CONAN_PKG::spdlog + CONAN_PKG::abseil + pb_storage_lib + ${MARIADB_LIBRARIES} + ) # Testing. if(WITH_TESTING) diff --git a/cmake.sh b/cmake.sh index 8a1006b533e..2228e84a99b 100755 --- a/cmake.sh +++ b/cmake.sh @@ -270,8 +270,8 @@ elif [ -r /etc/issue ] ; then fi fi -if ! pip3 install conan==1.62.0 --upgrade --break-system-packages ; then - pip3 install conan==1.62.0 --upgrade +if ! pip3 install conan==1.64.0 --upgrade --break-system-packages ; then + pip3 install conan==1.64.0 --upgrade fi if which conan ; then diff --git a/conanfile.txt b/conanfile.txt index b03f140fb83..a0a51a4135c 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -6,7 +6,6 @@ grpc/1.54.3 gtest/cci.20210126 libcurl/8.0.1 libssh2/1.10.0 -mariadb-connector-c/3.3.3 nlohmann_json/3.11.2 openssl/1.1.1t opentelemetry-cpp/1.14.2 diff --git a/packaging/centreon-broker-core.yaml b/packaging/centreon-broker-core.yaml index f505fb4dd55..8eb8369b23a 100644 --- a/packaging/centreon-broker-core.yaml +++ b/packaging/centreon-broker-core.yaml @@ -43,6 +43,7 @@ overrides: - centreon-clib = ${VERSION}-${RELEASE}${DIST} - centreon-broker = ${VERSION}-${RELEASE}${DIST} - gnutls >= 3.3.29 + - mariadb-connector-c >= 3.1.10 conflicts: - centreon-broker-storage - centreon-broker-core-devel @@ -58,6 +59,7 @@ overrides: - centreon-clib (= ${VERSION}-${RELEASE}${DIST}) - centreon-broker (= ${VERSION}-${RELEASE}${DIST}) - libgnutls30 + - libmariadb3 conflicts: - centreon-broker-storage - centreon-broker-core-dev diff --git a/tests/mysql_docker_conf/centreon16.cnf b/tests/mysql_docker_conf/centreon16.cnf index 3865e9bf923..692a1e39f6c 100644 --- a/tests/mysql_docker_conf/centreon16.cnf +++ b/tests/mysql_docker_conf/centreon16.cnf @@ -1,7 +1,6 @@ [mysqld] #mariadb conf optimized for a 16Gb ram machine port = 3306 -default-authentication-plugin=mysql_native_password max_heap_table_size=1G open_files_limit = 32000