From 6d703d590b76e5f0ebac1acefe42bd5bb2f054eb Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Fri, 20 Sep 2019 17:23:32 +0900 Subject: [PATCH] Generate SSH keys in the docker container --- amd64.Dockerfile | 2 +- arm32v7.Dockerfile | 2 +- docker-entrypoint.sh | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/amd64.Dockerfile b/amd64.Dockerfile index 03dae9a40..b905a45e8 100644 --- a/amd64.Dockerfile +++ b/amd64.Dockerfile @@ -16,7 +16,7 @@ RUN cd BTCPayServer && dotnet publish --output /app/ --configuration Release FROM mcr.microsoft.com/dotnet/core/aspnet:2.1.9-alpine3.7 ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT false -RUN apk add --no-cache icu-libs +RUN apk add --no-cache icu-libs openssh-keygen ENV LC_ALL en_US.UTF-8 ENV LANG en_US.UTF-8 diff --git a/arm32v7.Dockerfile b/arm32v7.Dockerfile index c98223a36..0ef5d088d 100644 --- a/arm32v7.Dockerfile +++ b/arm32v7.Dockerfile @@ -20,7 +20,7 @@ RUN cd BTCPayServer && dotnet publish --output /app/ --configuration Release # Force the builder machine to take make an arm runtime image. This is fine as long as the builder does not run any program FROM mcr.microsoft.com/dotnet/core/aspnet:2.1.9-stretch-slim-arm32v7 COPY --from=builder /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static -RUN apt-get update && apt-get install -y --no-install-recommends iproute2 \ +RUN apt-get update && apt-get install -y --no-install-recommends iproute2 openssh-client \ && rm -rf /var/lib/apt/lists/* ENV LC_ALL en_US.UTF-8 diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2d6717d40..afc3b3532 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,4 +1,15 @@ #!/bin/sh echo "$(/sbin/ip route|awk '/default/ { print $3 }') host.docker.internal" >> /etc/hosts + +if ! [ -f "$BTCPAY_SSHKEYFILE" ]; then + echo "Creating BTCPay Server SSH key File..." + ssh-keygen -t rsa -f "$BTCPAY_SSHKEYFILE" -q -P "" -m PEM -C btcpayserver > /dev/null +fi + +if [ -f "$BTCPAY_SSHAUTHORIZEDKEYS" ] && ! grep -q "btcpayserver$" "$BTCPAY_SSHAUTHORIZEDKEYS"; then + echo "Adding BTCPay Server SSH key to authorized keys" + cat "$BTCPAY_SSHKEYFILE.pub" >> "$BTCPAY_SSHAUTHORIZEDKEYS" +fi + exec dotnet BTCPayServer.dll