MDEV-33420: HASHICORP_KEY_MANAGEMENT fails on Windows with libcurl installed

- When `libcurl` is installed in path out of default path, like on
Windows, `include_directories` failed to find `curl/curl.h`.
- Fix `cmake` by using modern syntax with imported target and
`find_package`
- Fix warnings treated as the errors
  - Remove `HASHICORP_HAVE_EXCEPTIONS` macro and related code
- Add package to `Server` component in Windows
- Tested with `$ ./mysql-test/mtr --suite=vault`
- Closes PR #3068
- Reviewer: <wlad@mariadb.com>
            <julius.goryavsky@mariadb.com>
This commit is contained in:
Anel Husakovic
2024-04-12 08:55:27 +02:00
committed by Julius Goryavsky
parent 6815ab86d0
commit 11aeef2aa2
3 changed files with 3 additions and 70 deletions

View File

@ -1,18 +1,16 @@
INCLUDE(FindCURL) FIND_PACKAGE(CURL)
IF(NOT CURL_FOUND) IF(NOT CURL_FOUND)
# Can't build plugin # Can't build plugin
RETURN() RETURN()
ENDIF() ENDIF()
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
set(CPACK_RPM_hashicorp-key-management_PACKAGE_SUMMARY "Hashicorp Key Management plugin for MariaDB" PARENT_SCOPE) set(CPACK_RPM_hashicorp-key-management_PACKAGE_SUMMARY "Hashicorp Key Management plugin for MariaDB" PARENT_SCOPE)
set(CPACK_RPM_hashicorp-key-management_PACKAGE_DESCRIPTION "This encryption plugin uses Hashicorp Vault for storing encryption set(CPACK_RPM_hashicorp-key-management_PACKAGE_DESCRIPTION "This encryption plugin uses Hashicorp Vault for storing encryption
keys for MariaDB Data-at-Rest encryption." PARENT_SCOPE) keys for MariaDB Data-at-Rest encryption." PARENT_SCOPE)
MYSQL_ADD_PLUGIN(HASHICORP_KEY_MANAGEMENT MYSQL_ADD_PLUGIN(HASHICORP_KEY_MANAGEMENT
hashicorp_key_management_plugin.cc hashicorp_key_management_plugin.cc
LINK_LIBRARIES ${CURL_LIBRARIES} LINK_LIBRARIES CURL::libcurl
CONFIG hashicorp_key_management.cnf CONFIG hashicorp_key_management.cnf
COMPONENT hashicorp-key-management COMPONENT hashicorp-key-management
MODULE_ONLY) MODULE_ONLY)

View File

@ -28,12 +28,6 @@
#include <unordered_map> #include <unordered_map>
#include <mutex> #include <mutex>
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)
#define HASHICORP_HAVE_EXCEPTIONS 1
#else
#define HASHICORP_HAVE_EXCEPTIONS 0
#endif
#define HASHICORP_DEBUG_LOGGING 0 #define HASHICORP_DEBUG_LOGGING 0
#define PLUGIN_ERROR_HEADER "hashicorp: " #define PLUGIN_ERROR_HEADER "hashicorp: "
@ -208,15 +202,6 @@ unsigned int
if (key_version == ENCRYPTION_KEY_VERSION_INVALID) if (key_version == ENCRYPTION_KEY_VERSION_INVALID)
{ {
clock_t timestamp; clock_t timestamp;
#if HASHICORP_HAVE_EXCEPTIONS
try
{
VER_INFO &ver_info = latest_version_cache.at(key_id);
version = ver_info.key_version;
timestamp = ver_info.timestamp;
}
catch (const std::out_of_range &e)
#else
VER_MAP::const_iterator ver_iter = latest_version_cache.find(key_id); VER_MAP::const_iterator ver_iter = latest_version_cache.find(key_id);
if (ver_iter != latest_version_cache.end()) if (ver_iter != latest_version_cache.end())
{ {
@ -224,7 +209,6 @@ unsigned int
timestamp = ver_iter->second.timestamp; timestamp = ver_iter->second.timestamp;
} }
else else
#endif
{ {
mtx.unlock(); mtx.unlock();
return ENCRYPTION_KEY_VERSION_INVALID; return ENCRYPTION_KEY_VERSION_INVALID;
@ -245,13 +229,6 @@ unsigned int
} }
} }
KEY_INFO info; KEY_INFO info;
#if HASHICORP_HAVE_EXCEPTIONS
try
{
info = key_info_cache.at(KEY_ID_AND_VERSION(key_id, version));
}
catch (const std::out_of_range &e)
#else
KEY_MAP::const_iterator key_iter = KEY_MAP::const_iterator key_iter =
key_info_cache.find(KEY_ID_AND_VERSION(key_id, version)); key_info_cache.find(KEY_ID_AND_VERSION(key_id, version));
if (key_iter != key_info_cache.end()) if (key_iter != key_info_cache.end())
@ -259,7 +236,6 @@ unsigned int
info = key_iter->second; info = key_iter->second;
} }
else else
#endif
{ {
mtx.unlock(); mtx.unlock();
return ENCRYPTION_KEY_VERSION_INVALID; return ENCRYPTION_KEY_VERSION_INVALID;
@ -304,20 +280,12 @@ unsigned int HCData::cache_get_version (unsigned int key_id)
{ {
unsigned int version; unsigned int version;
mtx.lock(); mtx.lock();
#if HASHICORP_HAVE_EXCEPTIONS
try
{
version = latest_version_cache.at(key_id).key_version;
}
catch (const std::out_of_range &e)
#else
VER_MAP::const_iterator ver_iter = latest_version_cache.find(key_id); VER_MAP::const_iterator ver_iter = latest_version_cache.find(key_id);
if (ver_iter != latest_version_cache.end()) if (ver_iter != latest_version_cache.end())
{ {
version = ver_iter->second.key_version; version = ver_iter->second.key_version;
} }
else else
#endif
{ {
version = ENCRYPTION_KEY_VERSION_INVALID; version = ENCRYPTION_KEY_VERSION_INVALID;
} }
@ -330,15 +298,6 @@ unsigned int HCData::cache_check_version (unsigned int key_id)
unsigned int version; unsigned int version;
clock_t timestamp; clock_t timestamp;
mtx.lock(); mtx.lock();
#if HASHICORP_HAVE_EXCEPTIONS
try
{
VER_INFO &ver_info = latest_version_cache.at(key_id);
version = ver_info.key_version;
timestamp = ver_info.timestamp;
}
catch (const std::out_of_range &e)
#else
VER_MAP::const_iterator ver_iter = latest_version_cache.find(key_id); VER_MAP::const_iterator ver_iter = latest_version_cache.find(key_id);
if (ver_iter != latest_version_cache.end()) if (ver_iter != latest_version_cache.end())
{ {
@ -346,7 +305,6 @@ unsigned int HCData::cache_check_version (unsigned int key_id)
timestamp = ver_iter->second.timestamp; timestamp = ver_iter->second.timestamp;
} }
else else
#endif
{ {
mtx.unlock(); mtx.unlock();
#if HASHICORP_DEBUG_LOGGING #if HASHICORP_DEBUG_LOGGING
@ -977,29 +935,6 @@ struct st_mariadb_encryption hashicorp_key_management_plugin= {
0, 0, 0, 0, 0 0, 0, 0, 0, 0
}; };
#ifdef _MSC_VER
static int setenv (const char *name, const char *value, int overwrite)
{
if (!overwrite)
{
size_t len= 0;
int rc= getenv_s(&len, NULL, 0, name);
if (rc)
{
return rc;
}
if (len)
{
errno = EINVAL;
return EINVAL;
}
}
return _putenv_s(name, value);
}
#endif
#define MAX_URL_SIZE 32768 #define MAX_URL_SIZE 32768
int HCData::init () int HCData::init ()

View File

@ -63,7 +63,7 @@ SET(CPACK_COMPONENT_GROUP_MYSQLSERVER_DESCRIPTION "Install server")
#Miscellaneous (hidden) components, part of server / or client programs #Miscellaneous (hidden) components, part of server / or client programs
FOREACH(comp connect-engine ClientPlugins gssapi-server gssapi-client aws-key-management rocksdb-engine) FOREACH(comp connect-engine ClientPlugins gssapi-server gssapi-client aws-key-management rocksdb-engine plugin-hashicorp-key-management)
STRING(TOUPPER "${comp}" comp) STRING(TOUPPER "${comp}" comp)
SET(CPACK_COMPONENT_${comp}_GROUP "MySQLServer") SET(CPACK_COMPONENT_${comp}_GROUP "MySQLServer")
SET(CPACK_COMPONENT_${comp}_HIDDEN 1) SET(CPACK_COMPONENT_${comp}_HIDDEN 1)