diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e783d81 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +# Copyright 2024, Usman Saleem. +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +# Exclude everything +* + +# Include specific files and directories needed for the build +!docker/scripts/entrypoint.sh +!Dockerfile +!build/libs/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index ab5e240..82718d3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ build .idea + +# Ignore data and tokens in volume directory +docker/volumes/data +docker/volumes/tokens diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6c93d13 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +# syntax=docker/dockerfile:1 +# Copyright 2024, Usman Saleem. +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +# Start from the latest Hyperledger Besu image +FROM hyperledger/besu:latest + +# Switch to root to install packages +USER 0 + +# Install additional packages for SoftHSM2 and OpenSC +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + openssl \ + libssl3 \ + softhsm2 \ + opensc \ + gnutls-bin && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Create a directory for SoftHSM2 tokens. This can be overridden using a volume mount to persist. +RUN mkdir -p /var/lib/tokens && chmod 755 /var/lib/tokens && chown besu:besu /var/lib/tokens + +# Switch back to the besu user +USER besu + +# Update workdir to Besu home directory +WORKDIR /opt/besu + +# Set environment variables for SoftHSM2 configuration +ENV SOFTHSM2_CONF=/opt/besu/softhsm2.conf + +# Copy the PKCS11 plugin JAR to the plugins directory +COPY --chown=besu:besu ./build/libs/besu-pkcs11-plugin-*.jar ./plugins/ + +# Copy the initialization script +COPY --chown=besu:besu --chmod=755 ./docker/scripts/entrypoint.sh ./entrypoint.sh + +# Create a custom SoftHSM2 configuration file in besu home directory +RUN echo "directories.tokendir = /var/lib/tokens" > ./softhsm2.conf + +# Set the entrypoint to our new script +ENTRYPOINT ["/opt/besu/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 5846c0e..1ec150a 100644 --- a/README.md +++ b/README.md @@ -37,14 +37,61 @@ The plugin jar will be available at `build/libs/besu-pkcs11-plugin-.jar Drop the `besu-pkcs11-plugin-.jar` in the `/plugins` folder under Besu installation. This plugin will expose following additional cli options: -`TBA` +```shell +--plugin-pkcs11-hsm-config-path= + Path to the PKCS11 configuration file +--plugin-pkcs11-hsm-key-alias=