A. Vreeswijk
A. Vreeswijk

Reputation: 954

Plugin caching_sha2_password could not be loaded in Rust Diesel with MySQL Using Musl?

I am working on a Rust application built using musl to achieve a statically linked binary for a small Docker image. I managed to manually recompile the mysqlclient library for musl, and I thought everything was set up correctly.

However, when trying to connect to a MySQL 8.0 database, I encounter the following error:

gateway     | thread 'main' panicked at src/db/setup.rs:25:10:
gateway     | Failed to create DB Pool: Error(Some("Plugin caching_sha2_password could not be loaded: Dynamic loading not supported"))
gateway     | note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I am using the Diesel ORM with the MySQL backend in my Rust application.

The Dockerfile for the application uses musl for static linking. Here is the relevant part of my Dockerfile:

FROM messense/rust-musl-cross:${BUILD_PLATFORM}-musl AS builder
...
# Manually compile MariaDB client library for musl
WORKDIR /tmp
RUN curl -LO https://downloads.mariadb.com/Connectors/c/connector-c-3.3.4/mariadb-connector-c-3.3.4-src.tar.gz
RUN tar xzf mariadb-connector-c-3.3.4-src.tar.gz
RUN mkdir build
WORKDIR /tmp/build
RUN sed 's/STRING(STRIP ${extra_dynamic_LDFLAGS} extra_dynamic_LDFLAGS)//' -i ../mariadb-connector-c-3.3.4-src/mariadb_config/CMakeLists.txt
RUN sed 's/LIST(REMOVE_DUPLICATES extra_dynamic_LDFLAGS)//' -i ../mariadb-connector-c-3.3.4-src/mariadb_config/CMakeLists.txt
RUN CC=aarch64-unknown-linux-musl-gcc \
    LDFLAGS=-L/usr/local/musl/lib \
    cmake \
    -DWITH_SSL=OPENSSL \
    -DWITH_TLS=OPENSSL \
    -DOPENSSL_ROOT_DIR=/usr/local/musl \
    -DOPENSSL_USE_STATIC_LIBS=1 \
    -DWITH_CURL=0 \
    ../mariadb-connector-c-3.3.4-src
RUN make mariadbclient
RUN cp libmariadb/libmariadbclient.a /usr/local/musl/lib/libmysqlclient.a
...

The error seems to be related to MySQL's caching_sha2_password plugin, which is the default authentication mechanism for MySQL 8.0. I suspect the issue arises from dynamic loading being unsupported due to the static linking with musl.

I manually compiled mariadbclient with static linking as shown in the Dockerfile. Verified that the compiled binary runs successfully, except for this database connection issue.

How can I resolve the caching_sha2_password plugin error when using Diesel with MySQL and a statically linked Rust binary built with musl? Is there a way to ensure compatibility with MySQL 8.0, or do I need to change something in my setup to make the plugin work?

Any guidance or suggestions are highly appreciated!

UPDATE

I have tried to switch from MariaDB to the MySQL Client Library, by using the following code block:

# Manually compile MySQL client library for musl
WORKDIR /tmp
RUN curl -LO https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.36.tar.gz
RUN tar xzf mysql-8.0.36.tar.gz
RUN mkdir build
WORKDIR /tmp/build
RUN CC=aarch64-unknown-linux-musl-gcc \
    LDFLAGS="-L/usr/local/musl/lib" \
    cmake \
    -DDOWNLOAD_BOOST=1 \
    -DWITH_BOOST=/tmp/boost \
    -DWITH_SSL=system \
    -DOPENSSL_ROOT_DIR=/usr/local/musl \
    -DOPENSSL_USE_STATIC_LIBS=1 \
    -DWITHOUT_SERVER=ON \
    -DWITH_UNIT_TESTS=OFF \
    -DWITH_SYSTEMD=OFF \
    -DWITH_ROUTER=OFF \
    -DFORCE_UNSUPPORTED_COMPILER=ON \
    ../mysql-8.0.36

But by doing so I run into a lot of compiling errors. One of them for example is:

2.312 -- cd /tmp/boost; tar xfj /tmp/boost/boost_1_77_0.tar.bz2
2.322 CMake Error: Problem with archive_read_open_file(): Unrecognized archive format
2.322 CMake Error: Problem extracting tar: /tmp/boost/boost_1_77_0.tar.bz2
2.323 CMake Error at cmake/boost.cmake:256 (MESSAGE):
2.323   Giving up.
2.323 Call Stack (most recent call first):
2.323   CMakeLists.txt:1550 (INCLUDE)
2.323
2.323
2.323 -- WITH_BOOST /tmp/boost.
2.323 -- Failed to extract files.
2.323    Please try downloading and extracting yourself.
2.323    The url is: https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.bz2
2.323 -- Configuring incomplete, errors occurred!

I have also seen the error:

LIBEVENT version must be at least 2.1, found No such file or directory.

And:

Not a supported openssl version in WITH_SSL=system.
Make sure you have specified a supported SSL version.

Isn't there already a musl package for MySQL so I can statically link my Rust application to that one?

If not, can someone steer me into the right direction?

Upvotes: 0

Views: 50

Answers (0)

Related Questions