Skip to content

Commit

Permalink
MDEV-33420: HASHICORP_KEY_MANAGEMENT fails on Windows with libcurl in…
Browse files Browse the repository at this point in the history
…stalled

- 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>
  • Loading branch information
an3l authored and sysprg committed Apr 17, 2024
1 parent 6815ab8 commit 11aeef2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 70 deletions.
6 changes: 2 additions & 4 deletions plugin/hashicorp_key_management/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
INCLUDE(FindCURL)
FIND_PACKAGE(CURL)
IF(NOT CURL_FOUND)
# Can't build plugin
RETURN()
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_DESCRIPTION "This encryption plugin uses Hashicorp Vault for storing encryption
keys for MariaDB Data-at-Rest encryption." PARENT_SCOPE)

MYSQL_ADD_PLUGIN(HASHICORP_KEY_MANAGEMENT
hashicorp_key_management_plugin.cc
LINK_LIBRARIES ${CURL_LIBRARIES}
LINK_LIBRARIES CURL::libcurl
CONFIG hashicorp_key_management.cnf
COMPONENT hashicorp-key-management
MODULE_ONLY)
Expand Down
65 changes: 0 additions & 65 deletions plugin/hashicorp_key_management/hashicorp_key_management_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
#include <unordered_map>
#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 PLUGIN_ERROR_HEADER "hashicorp: "
Expand Down Expand Up @@ -208,23 +202,13 @@ unsigned int
if (key_version == ENCRYPTION_KEY_VERSION_INVALID)
{
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);
if (ver_iter != latest_version_cache.end())
{
version = ver_iter->second.key_version;
timestamp = ver_iter->second.timestamp;
}
else
#endif
{
mtx.unlock();
return ENCRYPTION_KEY_VERSION_INVALID;
Expand All @@ -245,21 +229,13 @@ unsigned int
}
}
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_info_cache.find(KEY_ID_AND_VERSION(key_id, version));
if (key_iter != key_info_cache.end())
{
info = key_iter->second;
}
else
#endif
{
mtx.unlock();
return ENCRYPTION_KEY_VERSION_INVALID;
Expand Down Expand Up @@ -304,20 +280,12 @@ unsigned int HCData::cache_get_version (unsigned int key_id)
{
unsigned int version;
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);
if (ver_iter != latest_version_cache.end())
{
version = ver_iter->second.key_version;
}
else
#endif
{
version = ENCRYPTION_KEY_VERSION_INVALID;
}
Expand All @@ -330,23 +298,13 @@ unsigned int HCData::cache_check_version (unsigned int key_id)
unsigned int version;
clock_t timestamp;
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);
if (ver_iter != latest_version_cache.end())
{
version = ver_iter->second.key_version;
timestamp = ver_iter->second.timestamp;
}
else
#endif
{
mtx.unlock();
#if HASHICORP_DEBUG_LOGGING
Expand Down Expand Up @@ -977,29 +935,6 @@ struct st_mariadb_encryption hashicorp_key_management_plugin= {
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

int HCData::init ()
Expand Down
2 changes: 1 addition & 1 deletion win/packaging/CPackWixConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SET(CPACK_COMPONENT_GROUP_MYSQLSERVER_DESCRIPTION "Install server")


#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)
SET(CPACK_COMPONENT_${comp}_GROUP "MySQLServer")
SET(CPACK_COMPONENT_${comp}_HIDDEN 1)
Expand Down

0 comments on commit 11aeef2

Please sign in to comment.