Skip to content

Java sdk doesn't work with alpine #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
adam-brusselback opened this issue Feb 24, 2025 · 1 comment
Open
1 task done

Java sdk doesn't work with alpine #1218

adam-brusselback opened this issue Feb 24, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@adam-brusselback
Copy link

Steps To Reproduce

Use an Alpine Linux-based Java container
Include the Bitwarden Java SDK as a dependency
Initialize the BitwardenClient in your application
Start the application

Expected Result

No errors on startup.

Actual Result

When starting we get the error:

Caused by: java.lang.UnsatisfiedLinkError: Error loading shared library libgcc_s.so.1: No such file or directory (needed by /root/.cache/JNA/temp/jna14893307320661373708.tmp)

After adding libgcc to the image:

Caused by: java.lang.UnsatisfiedLinkError: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /root/.cache/JNA/temp/jna9475222242932529641.tmp)

Screenshots or Videos

No response

Additional Context

The BitwardenService fails to initialize in Alpine Linux containers due to JNA compatibility issues with musl libc. The application crashes on startup with native library loading errors.

Operating System

Linux

Operating System Version

docker.io/eclipse-temurin:21-jre-alpine

Build Version

1.0.1

Issue Tracking Info

  • I understand that work is tracked outside of Github. A PR will be linked to this issue should one be opened to address it, but Bitwarden doesn't use fields like "assigned", "milestone", or "project" to track progress.
@adam-brusselback adam-brusselback added the bug Something isn't working label Feb 24, 2025
@McSwindler
Copy link

I ran into this same issue, and found a solution for myself by building a custom native library.

What the issue is

Alpine uses musl instead of gnu. The rust build does not produce a *.so file for the musl version of the library, only *.a. Java native interfaces expects a *.so file for Linux based OSes. Java will only use a *.a library for AIX based systems. ref

There is currently an open issue on rust about generating the dylib on musl systems: rust-lang/rust#59302
This is what I used to get my build working.

Work Around

The work around is to do a custom build for musl based systems, this will overwrite the gnu version of the *.so file and allow your application to run in Alpine, but probably won't run in GNU based containers.

First I pulled the latest built jar from the GitHub Actions to ensure compatibility with my freshly built library: https://github.com/bitwarden/sdk-sm/actions/workflows/build-java.yml?query=branch%3Amain

Then, I ran a custom build of bitwarden-c inside of an Alpine image.

You may need to adjust the docker command to fit your needs, but here are the commands I ran:

docker run -it --rm --platform linux/amd64 -v $(pwd)/target:/workdir alpine:latest
cd /workdir
apk add git rustup g++
/usr/bin/rustup-init
source "$HOME/.cargo/env"
git clone https://github.com/bitwarden/sdk-sm && cd sdk-sm
RUSTFLAGS="-C target-feature=-crt-static" cargo build -p bitwarden-c --target x86_64-unknown-linux-musl --release

Now, copy target/sdk-sm/target/x86_64-unknown-linux-musl/release/libbitwarden_c.so to
src/main/resources/linux-x86-64/libbitwarden_c.so

Your application should be able to run now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants