From 1a8e59d7733e420a56bf587fec0978fb892ff8bd Mon Sep 17 00:00:00 2001 From: nold Date: Tue, 24 Mar 2020 16:00:00 +0100 Subject: [PATCH 01/13] Created Init-Container that pulls pubkeys from git, creates authorized_keys, ssh-host-keys and backup-repo folders --- .gitignore | 1 + Dockerfile | 31 ---------- build.sh | 2 + data/run.sh | 95 ------------------------------- docker-compose.yml | 58 +++++++++++++------ env.example | 2 + init/Dockerfile | 13 +++++ init/entrypoint.sh | 107 +++++++++++++++++++++++++++++++++++ server/Dockerfile | 36 ++++++++++++ server/entrypoint.sh | 64 +++++++++++++++++++++ {data => server}/sshd_config | 10 ++-- 11 files changed, 273 insertions(+), 146 deletions(-) delete mode 100644 Dockerfile create mode 100644 build.sh delete mode 100755 data/run.sh create mode 100644 env.example create mode 100644 init/Dockerfile create mode 100755 init/entrypoint.sh create mode 100644 server/Dockerfile create mode 100755 server/entrypoint.sh rename {data => server}/sshd_config (69%) diff --git a/.gitignore b/.gitignore index ae9c630..60ba08a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /backup /sshkeys +.env diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index a682457..0000000 --- a/Dockerfile +++ /dev/null @@ -1,31 +0,0 @@ -############################################################ -# Dockerfile to build borgbackup server images -# Based on Debian -############################################################ -FROM debian:buster-slim - -# Volume for SSH-Keys -VOLUME /sshkeys - -# Volume for borg repositories -VOLUME /backup - -ENV DEBIAN_FRONTEND noninteractive - -RUN apt-get update && apt-get -y --no-install-recommends install \ - borgbackup openssh-server && apt-get clean && \ - useradd -s /bin/bash -m -U borg && \ - mkdir /home/borg/.ssh && \ - chmod 700 /home/borg/.ssh && \ - chown borg:borg /home/borg/.ssh && \ - mkdir /run/sshd && \ - rm -f /etc/ssh/ssh_host*key* && \ - rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/* - -COPY ./data/run.sh /run.sh -COPY ./data/sshd_config /etc/ssh/sshd_config - -ENTRYPOINT /run.sh - -# Default SSH-Port for clients -EXPOSE 22 diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..f4f38e6 --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +docker build -t borg:git server +docker build -t borg:init init diff --git a/data/run.sh b/data/run.sh deleted file mode 100755 index e794704..0000000 --- a/data/run.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash -# Start Script for docker-borgserver - -PUID=${PUID:-1000} -PGID=${PGID:-1000} - -usermod -o -u "$PUID" borg &>/dev/null -groupmod -o -g "$PGID" borg &>/dev/null - -BORG_DATA_DIR=/backup -SSH_KEY_DIR=/sshkeys -BORG_CMD='cd ${BORG_DATA_DIR}/${client_name}; borg serve --restrict-to-path ${BORG_DATA_DIR}/${client_name} ${BORG_SERVE_ARGS}' -AUTHORIZED_KEYS_PATH=/home/borg/.ssh/authorized_keys - -# Append only mode? -BORG_APPEND_ONLY=${BORG_APPEND_ONLY:=no} - -echo "########################################################" -echo -n " * Docker BorgServer powered by " -borg -V -echo "########################################################" -echo " * User id: $(id -u borg)" -echo " * Group id: $(id -g borg)" -echo "########################################################" - - -# Precheck if BORG_ADMIN is set -if [ "${BORG_APPEND_ONLY}" == "yes" ] && [ -z "${BORG_ADMIN}" ] ; then - echo "WARNING: BORG_APPEND_ONLY is active, but no BORG_ADMIN was specified!" -fi - -# Precheck directories & client ssh-keys -for dir in BORG_DATA_DIR SSH_KEY_DIR ; do - dirpath=$(eval echo '$'${dir}) - echo " * Testing Volume ${dir}: ${dirpath}" - if [ ! -d "${dirpath}" ] ; then - echo "ERROR: ${dirpath} is no directory!" - exit 1 - fi - - if [ "$(find ${SSH_KEY_DIR}/clients ! -regex '.*/\..*' -a -type f | wc -l)" == "0" ] ; then - echo "ERROR: No SSH-Pubkey file found in ${SSH_KEY_DIR}" - exit 1 - fi -done - -# Create SSH-Host-Keys on persistent storage, if not exist -mkdir -p ${SSH_KEY_DIR}/host 2>/dev/null -echo " * Checking / Preparing SSH Host-Keys..." -for keytype in ed25519 rsa ; do - if [ ! -f "${SSH_KEY_DIR}/host/ssh_host_${keytype}_key" ] ; then - echo " ** Creating SSH Hostkey [${keytype}]..." - ssh-keygen -q -f "${SSH_KEY_DIR}/host/ssh_host_${keytype}_key" -N '' -t ${keytype} - fi -done - -echo "########################################################" -echo " * Starting SSH-Key import..." - -# Add every key to borg-users authorized_keys -rm ${AUTHORIZED_KEYS_PATH} &>/dev/null -for keyfile in $(find "${SSH_KEY_DIR}/clients" ! -regex '.*/\..*' -a -type f); do - client_name=$(basename ${keyfile}) - mkdir ${BORG_DATA_DIR}/${client_name} 2>/dev/null - echo " ** Adding client ${client_name} with repo path ${BORG_DATA_DIR}/${client_name}" - - # If client is $BORG_ADMIN unset $client_name, so path restriction equals $BORG_DATA_DIR - # Otherwise add --append-only, if enabled - borg_cmd=${BORG_CMD} - if [ "${client_name}" == "${BORG_ADMIN}" ] ; then - echo " ** Client '${client_name}' is BORG_ADMIN! **" - unset client_name - elif [ "${BORG_APPEND_ONLY}" == "yes" ] ; then - borg_cmd="${BORG_CMD} --append-only" - fi - - echo -n "command=\"$(eval echo -n \"${borg_cmd}\")\" " >> ${AUTHORIZED_KEYS_PATH} - cat ${keyfile} >> ${AUTHORIZED_KEYS_PATH} -done - -echo " * Validating structure of generated ${AUTHORIZED_KEYS_PATH}..." -ERROR=$(ssh-keygen -lf ${AUTHORIZED_KEYS_PATH} 2>&1 >/dev/null) -if [ $? -ne 0 ]; then - echo "ERROR: ${ERROR}" - exit 1 -fi - -chown -R borg:borg ${BORG_DATA_DIR} -chown borg:borg ${AUTHORIZED_KEYS_PATH} -chmod 600 ${AUTHORIZED_KEYS_PATH} - -echo "########################################################" -echo " * Init done! Starting SSH-Daemon..." - -/usr/sbin/sshd -D -e diff --git a/docker-compose.yml b/docker-compose.yml index aabaf84..2f02b4f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,46 @@ version: '3' services: - borgserver: - image: nold360/borgserver - #build: . - volumes: - - ./backup:/backup - - ./sshkeys:/sshkeys - ports: - - "2222:22" - environment: - BORG_SERVE_ARGS: "" + init: + image: borg:init + env_file: .env + volumes: + - borg-home:/home/borg/.ssh:rw + - host-keys:/sshkeys:rw - # If set to "yes", only the BORG_ADMIN - # can delete/prune the all clients archives/repos - BORG_APPEND_ONLY: "no" + # FIXME: i want to get rid of that.. + - backup:/backup:rw + restart: "no" - # Hostname of Admin's SSH-Key - BORG_ADMIN: "" - restart: unless-stopped + borgserver: + #image: nold360/borgserver + image: borg:git + user: 1000:1000 + volumes: + # generated authorized_keys by init + - borg-home:/home/borg/.ssh:ro + + # only contains host-keys now + - host-keys:/sshkeys:ro + + # Backup repository for borg + - backup:/backup:rw + ports: + - "2222:2222" + environment: + BORG_SERVE_ARGS: "" + + # If set to "yes", only the BORG_ADMIN + # can delete/prune the all clients archives/repos + BORG_APPEND_ONLY: "no" + + # Hostname of Admin's SSH-Key + BORG_ADMIN: "" + depends_on: + - init + restart: unless-stopped + +# Shared volume to exchange authorized_keys between init & server +volumes: + borg-home: + host-keys: + backup: diff --git a/env.example b/env.example new file mode 100644 index 0000000..7ff0b3e --- /dev/null +++ b/env.example @@ -0,0 +1,2 @@ +KEY_GIT_URL=https://github.com/yourName/your-ssh-pub-keys.git +KEY_GIT_BRANCH=master diff --git a/init/Dockerfile b/init/Dockerfile new file mode 100644 index 0000000..35b333f --- /dev/null +++ b/init/Dockerfile @@ -0,0 +1,13 @@ +# Borgserver Init-Container, simply replace entrypoiny and install git +#FROM nold360/borgserver:latest +FROM borg:git + +USER root +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt-get update && \ + apt-get -y --no-install-recommends install \ + git ca-certificates && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/* + +COPY ./entrypoint.sh /entrypoint.sh diff --git a/init/entrypoint.sh b/init/entrypoint.sh new file mode 100755 index 0000000..c0df36e --- /dev/null +++ b/init/entrypoint.sh @@ -0,0 +1,107 @@ +#!/bin/bash +# Init-Start Script for docker-borgserver +# Will pull ssh-keys from git specified via KEY_GIT_URL and KEY_GIT_BRANCH [default: master] +# and merge them into a single [openssh] authorized_keys file. +PUID=${PUID:-1000} +PGID=${PGID:-1000} + +usermod -o -u "$PUID" borg &>/dev/null +groupmod -o -g "$PGID" borg &>/dev/null + +# FIXME: Is this changeable? guess it should be.. should move it to some kind of +# build-env file +BORG_DATA_DIR=${BORG_DATA_DIR:-/backup} + +BORG_CMD='cd ${BORG_DATA_DIR}/${client_name}; borg serve --restrict-to-path ${BORG_DATA_DIR}/${client_name} ${BORG_SERVE_ARGS}' +KEY_GIT_BRANCH=${KEY_GIT_BRANCH:-master} + +# This is the path where the final authorized_keys will be written: +AUTHORIZED_KEYS_PATH=${AUTHORIZED_KEYS_PATH:-/home/borg/.ssh/authorized_keys} + +# This will only contain host-keys now +SSH_KEY_DIR=${SSH_KEY_DIR:-/sshkeys} + +# This is no volume anymore, only temporary during init +GIT_KEY_DIR=/tmp/gitkeys +echo "########################################################" +echo " * Docker BorgServer | Git Init-Container *" +echo " * $(id)" + +if [ ! -z "${KEY_GIT_URL}" ] ; then + # FIXME: Should the container die here, in case of error? + # To workaround the limitations of docker-compose we could just loop here like.. forever + + # INFO: simle git clone would be enouth, but you can also use a volume for SSH_KEY_DIR if you like + echo " * Cloning '${KEY_GIT_URL}' into '${GIT_KEY_DIR}/clients'" + if [ ! -d "${GIT_KEY_DIR}/clients/.git" ] ; then + git clone -b ${KEY_GIT_BRANCH} --depth=1 "${KEY_GIT_URL}" "${GIT_KEY_DIR}/clients" + else + git -C "${GIT_KEY_DIR}/clients" pull + fi +else + echo " ! FATAL ERROR: KEY_GIT_URL is not set! Can't continue." + exit 1 +fi + +if [ "$(find ${GIT_KEY_DIR}/clients ! -regex '.*/\..*' -a -type f | wc -l)" == "0" ] ; then + echo " ! FATAL ERROR: No SSH-Pubkey file found in ${GIT_KEY_DIR}. Can't continue." + exit 2 +fi + +# Create SSH-Host-Keys on persistent storage, if not exist +# This also means that `${SSH_KEY_DIR}` has to be a shared volume +echo " * Checking / Preparing SSH Host-Keys..." +for keytype in ed25519 rsa ; do + if [ ! -f "${SSH_KEY_DIR}/ssh_host_${keytype}_key" ] ; then + echo " ** Creating SSH Hostkey [${keytype}]..." + ssh-keygen -q -f "${SSH_KEY_DIR}/ssh_host_${keytype}_key" -N '' -t ${keytype} + fi +done + +echo "########################################################" +echo " * Starting SSH-Key import..." + +# Add every key to borg-users authorized_keys +# FIXME: mkdir of filestructure must still be done by server-container +# since we shouldn't have access to the backup-data volume in init +rm -f ${AUTHORIZED_KEYS_PATH} &>/dev/null +for keyfile in $(find "${GIT_KEY_DIR}" ! -regex '.*/\..*' -a -type f); do + client_name=$(basename ${keyfile}) + + # check if file is a valid openssh public key + if ! ssh-keygen -lf $keyfile &>/dev/null ; then + echo " ! WARNING: '$keyfile' is not a valid [open]ssh-public-key. Will continue anyway." + continue + fi + + # If client is $BORG_ADMIN unset $client_name, so path restriction equals $BORG_DATA_DIR + # Otherwise add --append-only, if enabled + borg_cmd=${BORG_CMD} + if [ "${client_name}" == "${BORG_ADMIN}" ] ; then + echo " ** Client '${client_name}' is BORG_ADMIN! **" + unset client_name + elif [ "${BORG_APPEND_ONLY}" == "yes" ] ; then + borg_cmd="${BORG_CMD} --append-only" + fi + + echo -n "command=\"$(eval echo -n \"${borg_cmd}\")\" " >> ${AUTHORIZED_KEYS_PATH} + cat ${keyfile} >> ${AUTHORIZED_KEYS_PATH} +done + +# This will also fail if there wasn't a single valid pubkey found +echo " * Validating structure of generated ${AUTHORIZED_KEYS_PATH}..." +if ! ssh-keygen -lf ${AUTHORIZED_KEYS_PATH} >/dev/null ; then + echo " ! FATAL ERROR: ${AUTHORIZED_KEYS_PATH} is no valid authorized_keys file. Can't continue." + exit 3 +fi + +echo " * Correcting Permissions..." +chown borg:borg ${AUTHORIZED_KEYS_PATH} +chown -R borg:borg ${SSH_KEY_DIR}/* +chown borg:borg ${BORG_DATA_DIR} +chmod 600 ${AUTHORIZED_KEYS_PATH} + +echo "########################################################" +echo " * Init done! Ready to fire up your borgserver!" + +exit 0 diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..829ec5d --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,36 @@ +############################################################ +# Dockerfile to build borgbackup server images +# Based on Debian +############################################################ +FROM debian:buster-slim + +# Volume for SSH-Host-Keys +VOLUME /sshkeys + +# Volume for borg repositories +VOLUME /backup + +# Volume for authorized_keys exchange from init +VOLUME /home/borg + +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt-get update && \ + apt-get -y --no-install-recommends install \ + borgbackup openssh-server iputils-ping && \ + apt-get clean && \ + useradd -s /bin/bash -m -U borg && \ + mkdir /home/borg/.ssh && \ + chmod 700 /home/borg/.ssh && \ + touch /home/borg/.ssh/authorized_keys && \ + chown -R borg:borg /home/borg /backup && \ + mkdir /run/sshd && \ + rm -f /etc/ssh/ssh_host*key* && \ + rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/* + +COPY ./entrypoint.sh /entrypoint.sh +COPY ./sshd_config /etc/ssh/sshd_config + +USER borg +EXPOSE 2222 + +ENTRYPOINT /entrypoint.sh diff --git a/server/entrypoint.sh b/server/entrypoint.sh new file mode 100755 index 0000000..ab5b38f --- /dev/null +++ b/server/entrypoint.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# Start Script for docker-borgserver + +PUID=${PUID:-1000} +PGID=${PGID:-1000} + +usermod -o -u "$PUID" borg &>/dev/null +groupmod -o -g "$PGID" borg &>/dev/null + +BORG_DATA_DIR=${BORG_DATA_DIR:-/backup} +SSH_KEY_DIR=${SSH_KEY_DIR:-/sshkeys} +BORG_CMD='cd ${BORG_DATA_DIR}/${client_name}; borg serve --restrict-to-path ${BORG_DATA_DIR}/${client_name} ${BORG_SERVE_ARGS}' +AUTHORIZED_KEYS_PATH=/home/borg/.ssh/authorized_keys + +# Append only mode? +BORG_APPEND_ONLY=${BORG_APPEND_ONLY:=no} + +echo "########################################################" +echo " * Docker BorgServer powered by $(borg -V)" +echo "########################################################" +echo " * $(id)" +echo "########################################################" + +echo -n "Waiting for init-container to finish..." +sleep 5 +while ping -c2 init >/dev/null 2>/dev/null ; do + echo . + sleep 3 +done +echo " done" + +# Precheck if BORG_ADMIN is set +if [ "${BORG_APPEND_ONLY}" == "yes" ] && [ -z "${BORG_ADMIN}" ] ; then + echo "WARNING: BORG_APPEND_ONLY is active, but no BORG_ADMIN was specified!" +fi + +# Precheck directories & client ssh-keys +for dir in BORG_DATA_DIR SSH_KEY_DIR ; do + dirpath=$(eval echo '$'${dir}) + echo " * Testing Volume ${dir}: ${dirpath}" + if [ ! -d "${dirpath}" ] ; then + echo " ! ERROR: ${dirpath} is no directory!" + exit 1 + fi +done + +for keytype in ed25519 rsa ; do + if [ ! -f "${SSH_KEY_DIR}/ssh_host_${keytype}_key" ] ; then + echo " ! WARNING: SSH-Host-Key $keytype doesn't exist!" + continue + fi +done + +echo "########################################################" +echo " * Checking authorized_keys file..." +# Check if authorzied_keys is valid +if ! ssh-keygen -lf ${AUTHORIZED_KEYS_PATH} >/dev/null; then + echo " ! ERROR: '${AUTHORIZED_KEYS_PATH}' is not a valid authorized_keys-file." + exit 1 +fi + +echo "########################################################" +echo " * Init done! Starting SSH-Daemon..." +/usr/sbin/sshd -D -e diff --git a/data/sshd_config b/server/sshd_config similarity index 69% rename from data/sshd_config rename to server/sshd_config index b1c2206..4cbdc79 100644 --- a/data/sshd_config +++ b/server/sshd_config @@ -1,17 +1,19 @@ -Port 22 +Port 2222 AddressFamily any ListenAddress 0.0.0.0 ListenAddress :: -HostKey /sshkeys/host/ssh_host_rsa_key -HostKey /sshkeys/host/ssh_host_ed25519_key +HostKey /sshkeys/ssh_host_rsa_key +HostKey /sshkeys/ssh_host_ed25519_key + +PidFile /tmp/sshd.pid PermitRootLogin no StrictModes yes MaxSessions 20 PubkeyAuthentication yes -AuthorizedKeysFile .ssh/authorized_keys +AuthorizedKeysFile /home/borg/.ssh/authorized_keys LogLevel INFO From 674b4d8757365e9f64a9d163511c5b997647239d Mon Sep 17 00:00:00 2001 From: nold Date: Fri, 13 Aug 2021 12:50:23 +0200 Subject: [PATCH 02/13] Add: drone.yml --- .drone.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..efcda51 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,18 @@ +--- +kind: pipeline +name: build +type: kubernetes + +steps: +- name: build-image + image: plugins/buildah-docker + settings: + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: nold360/borgserver + dockerfile: Dockerfile + tags: + - latest + - buster From 7d29e33747a51bb24a43ae840241d72b15e061ca Mon Sep 17 00:00:00 2001 From: nold Date: Mon, 29 Nov 2021 17:39:31 +0100 Subject: [PATCH 03/13] Fix: drone - use kaniko for building --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index efcda51..e79c02f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,7 +5,7 @@ type: kubernetes steps: - name: build-image - image: plugins/buildah-docker + image: plugins/kaniko settings: username: from_secret: docker_username From 7b241c142bd30d5c0b2a76d2bd7239265879a005 Mon Sep 17 00:00:00 2001 From: nold Date: Fri, 21 Jan 2022 10:02:01 +0100 Subject: [PATCH 04/13] Update: README & docker-compose example --- README.md | 18 +----------------- docker-compose.yml | 5 +++-- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 0560555..a0d7eec 100644 --- a/README.md +++ b/README.md @@ -112,23 +112,7 @@ In this directory will borg write all the client data to. It's best to start wit ## Example Setup ### docker-compose.yml -Here is a quick example, how to run borgserver using docker-compose: -``` -services: - borgserver: - image: nold360/borgserver - volumes: - - /backup:/backup - - ./sshkeys:/sshkeys - ports: - - "2222:22" - environment: - BORG_SERVE_ARGS: "" - BORG_APPEND_ONLY: "no" - BORG_ADMIN: "" - PUID: 1000 - PGID: 1000 -``` +Here is a quick example, how to run borgserver using docker-compose: [docker-compose.yml](https://github.com/Nold360/docker-borgserver/blob/master/docker-compose.yml) ### ~/.ssh/config for clients With this configuration (on your borg client) you can easily connect to your borgserver. diff --git a/docker-compose.yml b/docker-compose.yml index aabaf84..e66b4cd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,12 +9,13 @@ services: ports: - "2222:22" environment: + # Additional Arguments, see https://borgbackup.readthedocs.io/en/stable/usage/serve.html BORG_SERVE_ARGS: "" # If set to "yes", only the BORG_ADMIN - # can delete/prune the all clients archives/repos + # can delete/prune the other clients archives/repos BORG_APPEND_ONLY: "no" - # Hostname of Admin's SSH-Key + # Filename of Admins SSH-Key; has full access to all repos BORG_ADMIN: "" restart: unless-stopped From 0b641a82539a473ae861dbc21981f717425749cc Mon Sep 17 00:00:00 2001 From: Nold Date: Fri, 21 Jan 2022 10:33:54 +0100 Subject: [PATCH 05/13] Upgrade: bullseye & borgbackup 1.1.16 (#13) * Upgrade to bullseye-slim image * Fix(run.sh): authorized_keys permissions * Change(run.sh): Add restrict to client keys & output debian version * Change(Dockerfile): Allow different base images * Update(drone): Build buster & bullseye images * Update README --- .drone.yml | 20 +++++++++++++++++++- Dockerfile | 3 ++- README.md | 6 ++++++ data/run.sh | 5 ++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index e79c02f..f204aa3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,7 +4,7 @@ name: build type: kubernetes steps: -- name: build-image +- name: build-bullseye image: plugins/kaniko settings: username: @@ -13,6 +13,24 @@ steps: from_secret: docker_password repo: nold360/borgserver dockerfile: Dockerfile + build_args: + - BASE_IMAGE=debian:bullseye-slim tags: - latest + - bullseye + - 1.1.16 + +- name: build-buster + image: plugins/kaniko + settings: + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: nold360/borgserver + dockerfile: Dockerfile + build_args: + - BASE_IMAGE=debian:buster-slim + tags: - buster + - 1.1.9 diff --git a/Dockerfile b/Dockerfile index a682457..a7cd5d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,8 @@ # Dockerfile to build borgbackup server images # Based on Debian ############################################################ -FROM debian:buster-slim +ARG BASE_IMAGE=debian:bullseye-slim +FROM $BASE_IMAGE # Volume for SSH-Keys VOLUME /sshkeys diff --git a/README.md b/README.md index a0d7eec..e381cdc 100644 --- a/README.md +++ b/README.md @@ -132,3 +132,9 @@ And create your first backup! ``` $ borg create backup:my_first_borg_repo::documents-2017-11-01 /home/user/MyImportentDocs ``` + +## Tags + +All images are freshly built every week & published as `nold360/borgserver` with the following tags: + - Latest / Stable [borg 1.1.16]: `bullseye`, `1.1.16`, `latest` + - Legacy / Buster [borg 1.1.9 ]: `buster`, `1.1.9` diff --git a/data/run.sh b/data/run.sh index e794704..63ec0eb 100755 --- a/data/run.sh +++ b/data/run.sh @@ -15,9 +15,11 @@ AUTHORIZED_KEYS_PATH=/home/borg/.ssh/authorized_keys # Append only mode? BORG_APPEND_ONLY=${BORG_APPEND_ONLY:=no} +source /etc/os-release echo "########################################################" echo -n " * Docker BorgServer powered by " borg -V +echo " * Based on ${PRETTY_NAME}" echo "########################################################" echo " * User id: $(id -u borg)" echo " * Group id: $(id -g borg)" @@ -74,9 +76,10 @@ for keyfile in $(find "${SSH_KEY_DIR}/clients" ! -regex '.*/\..*' -a -type f); d borg_cmd="${BORG_CMD} --append-only" fi - echo -n "command=\"$(eval echo -n \"${borg_cmd}\")\" " >> ${AUTHORIZED_KEYS_PATH} + echo -n "restrict,command=\"$(eval echo -n \"${borg_cmd}\")\" " >> ${AUTHORIZED_KEYS_PATH} cat ${keyfile} >> ${AUTHORIZED_KEYS_PATH} done +chmod 0600 "${AUTHORIZED_KEYS_PATH}" echo " * Validating structure of generated ${AUTHORIZED_KEYS_PATH}..." ERROR=$(ssh-keygen -lf ${AUTHORIZED_KEYS_PATH} 2>&1 >/dev/null) From 95ec06eb800e5a8925e900873a56fb793d7f2429 Mon Sep 17 00:00:00 2001 From: Gerrit Pannek Date: Sat, 5 Feb 2022 18:12:37 +0100 Subject: [PATCH 06/13] Fix(run.sh): Add new line in authorized_keys [Fixes #12] --- data/run.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/run.sh b/data/run.sh index 63ec0eb..215cbe6 100755 --- a/data/run.sh +++ b/data/run.sh @@ -76,8 +76,9 @@ for keyfile in $(find "${SSH_KEY_DIR}/clients" ! -regex '.*/\..*' -a -type f); d borg_cmd="${BORG_CMD} --append-only" fi - echo -n "restrict,command=\"$(eval echo -n \"${borg_cmd}\")\" " >> ${AUTHORIZED_KEYS_PATH} - cat ${keyfile} >> ${AUTHORIZED_KEYS_PATH} + echo -n "restrict,command=\"$(eval echo -n \"${borg_cmd}\")\" " >> ${AUTHORIZED_KEYS_PATH} + cat ${keyfile} >> ${AUTHORIZED_KEYS_PATH} + echo >> ${AUTHORIZED_KEYS_PATH} done chmod 0600 "${AUTHORIZED_KEYS_PATH}" From ea677a7da9b6b037dd01ce35967511e74e4e0f62 Mon Sep 17 00:00:00 2001 From: nold Date: Wed, 11 May 2022 18:53:24 +0200 Subject: [PATCH 07/13] Add(drone): Build Bookworm --- .drone.yml | 15 +++++++++++++++ README.md | 1 + 2 files changed, 16 insertions(+) diff --git a/.drone.yml b/.drone.yml index f204aa3..56aceab 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,6 +4,21 @@ name: build type: kubernetes steps: +- name: build-bookworm + image: plugins/kaniko + settings: + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: nold360/borgserver + dockerfile: Dockerfile + build_args: + - BASE_IMAGE=debian:bookworm-slim + tags: + - bookworm + - 1.2.0 + - name: build-bullseye image: plugins/kaniko settings: diff --git a/README.md b/README.md index e381cdc..5b4defd 100644 --- a/README.md +++ b/README.md @@ -136,5 +136,6 @@ And create your first backup! ## Tags All images are freshly built every week & published as `nold360/borgserver` with the following tags: + - Next / Unstable [borg 1.2.0]: `bookworm`, `1.2.0` - Latest / Stable [borg 1.1.16]: `bullseye`, `1.1.16`, `latest` - Legacy / Buster [borg 1.1.9 ]: `buster`, `1.1.9` From 2c76a45aca8e864da665eccbf43e33a9f9243aad Mon Sep 17 00:00:00 2001 From: Nold Date: Wed, 20 Jul 2022 11:01:57 +0200 Subject: [PATCH 08/13] Update: bookworm image version 1.2.1 --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 56aceab..25c3848 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,7 +17,7 @@ steps: - BASE_IMAGE=debian:bookworm-slim tags: - bookworm - - 1.2.0 + - 1.2.1 - name: build-bullseye image: plugins/kaniko From 57ed075e223aa6af4a6faba5bcc5cf1043661da3 Mon Sep 17 00:00:00 2001 From: nold Date: Tue, 20 Sep 2022 09:06:17 +0200 Subject: [PATCH 09/13] Update(drone): Image tag for bookwork v1.2 & v1.2.2 --- .drone.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 25c3848..e41176d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,7 +17,8 @@ steps: - BASE_IMAGE=debian:bookworm-slim tags: - bookworm - - 1.2.1 + - 1.2 + - 1.2.2 - name: build-bullseye image: plugins/kaniko From ef02f845dc12fa46a3ec1e3ab9daf493100f198a Mon Sep 17 00:00:00 2001 From: nold Date: Tue, 22 Nov 2022 22:15:49 +0100 Subject: [PATCH 10/13] add(ci): woodpecker.yml --- .drone.yml | 52 ------------------------------------------------- .woodpecker.yml | 30 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 52 deletions(-) delete mode 100644 .drone.yml create mode 100644 .woodpecker.yml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index e41176d..0000000 --- a/.drone.yml +++ /dev/null @@ -1,52 +0,0 @@ ---- -kind: pipeline -name: build -type: kubernetes - -steps: -- name: build-bookworm - image: plugins/kaniko - settings: - username: - from_secret: docker_username - password: - from_secret: docker_password - repo: nold360/borgserver - dockerfile: Dockerfile - build_args: - - BASE_IMAGE=debian:bookworm-slim - tags: - - bookworm - - 1.2 - - 1.2.2 - -- name: build-bullseye - image: plugins/kaniko - settings: - username: - from_secret: docker_username - password: - from_secret: docker_password - repo: nold360/borgserver - dockerfile: Dockerfile - build_args: - - BASE_IMAGE=debian:bullseye-slim - tags: - - latest - - bullseye - - 1.1.16 - -- name: build-buster - image: plugins/kaniko - settings: - username: - from_secret: docker_username - password: - from_secret: docker_password - repo: nold360/borgserver - dockerfile: Dockerfile - build_args: - - BASE_IMAGE=debian:buster-slim - tags: - - buster - - 1.1.9 diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..5cd8b9e --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,30 @@ +--- +variables: + - &kaniko_plugin 'plugins/kaniko:1.6' + +matrix: + include: + - BASE: bookworm-slim + TAGS: '[ "bookwork", "1.2", "1.2.2" ]' + - BASE: bullseye-slim + TAGS: '[ "bullseye", "latest", "1.1.16" ]' + - BASE: buster-slim + TAGS: '[ "buster", "1.1.9" ]' + +pipeline: + build: + image: *kaniko_plugin + group: build + settings: + repo: nold360/borgserver + dockerfile: Dockerfile + build_args: + - BASE_IMAGE=debian:${BASE} + tags: ${TAGS} + username: + from_secret: docker_username + password: + from_secret: docker_password + when: + - branch: master + - event: cron From 45e8883cae9a844ba93baeed252bda6bdb3b5ac2 Mon Sep 17 00:00:00 2001 From: nold Date: Thu, 24 Nov 2022 16:22:39 +0100 Subject: [PATCH 11/13] fix(sshd_config): recommended keepalive values --- data/sshd_config | 3 +++ 1 file changed, 3 insertions(+) diff --git a/data/sshd_config b/data/sshd_config index b1c2206..29e39c3 100644 --- a/data/sshd_config +++ b/data/sshd_config @@ -25,3 +25,6 @@ PermitTTY no PrintMotd no PermitTunnel no Subsystem sftp /bin/false + +ClientAliveInterval 10 +ClientAliveCountMax 30 From 49b78cf10f85a10dd006c5b80dce8c05c77446e4 Mon Sep 17 00:00:00 2001 From: Andreas Mieke Date: Sat, 13 Jan 2024 03:14:36 +0100 Subject: [PATCH 12/13] feat(platforms): Add ARM support --- .woodpecker.yml | 63 ++++++++++++++++++++++++++-------------------- Dockerfile | 3 +-- README.md | 13 +++------- docker-compose.yml | 2 +- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 5cd8b9e..75acfa0 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,30 +1,39 @@ ---- -variables: - - &kaniko_plugin 'plugins/kaniko:1.6' - -matrix: - include: - - BASE: bookworm-slim - TAGS: '[ "bookwork", "1.2", "1.2.2" ]' - - BASE: bullseye-slim - TAGS: '[ "bullseye", "latest", "1.1.16" ]' - - BASE: buster-slim - TAGS: '[ "buster", "1.1.9" ]' - -pipeline: +steps: build: - image: *kaniko_plugin - group: build + image: woodpeckerci/plugin-docker-buildx settings: - repo: nold360/borgserver - dockerfile: Dockerfile - build_args: - - BASE_IMAGE=debian:${BASE} - tags: ${TAGS} - username: - from_secret: docker_username - password: - from_secret: docker_password + dry-run: true + repo: git.merp.digital/${CI_REPO_OWNER}/borgserver + platforms: linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x + registry: git.merp.digital when: - - branch: master - - event: cron + - event: push + branch: + exclude: [develop, master] + + publish-nightly: + image: woodpeckerci/plugin-docker-buildx + settings: + repo: git.merp.digital/${CI_REPO_OWNER}/borgserver + platforms: linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x + registry: git.merp.digital + tags: develop-${CI_COMMIT_SHA} + username: ${CI_REPO_OWNER} + password: + from_secret: cb_token + when: + - event: push + branch: develop + + publish-release: + image: woodpeckerci/plugin-docker-buildx + settings: + repo: git.merp.digital/${CI_REPO_OWNER}/borgserver + platforms: linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x + registry: git.merp.digital + tags: ${CI_COMMIT_TAG} + username: ${CI_REPO_OWNER} + password: + from_secret: cb_token + when: + - event: tag \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a7cd5d1..893a84c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,7 @@ # Dockerfile to build borgbackup server images # Based on Debian ############################################################ -ARG BASE_IMAGE=debian:bullseye-slim -FROM $BASE_IMAGE +FROM debian:12.4-slim # Volume for SSH-Keys VOLUME /sshkeys diff --git a/README.md b/README.md index 5b4defd..2ae399d 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ docker run -td \ -p 2222:22 \ --volume ./borg/sshkeys:/sshkeys \ --volume ./borg/backup:/backup \ - nold360/borgserver:latest + git.merp.digital/eranmorkon/borgserver:1.0.0 ``` @@ -45,7 +45,7 @@ See the the documentation for all available arguments: [borgbackup.readthedocs.i ##### Example ``` -docker run --rm -e BORG_SERVE_ARGS="--progress --debug" (...) nold360/borgserver +docker run --rm -e BORG_SERVE_ARGS="--progress --debug" (...) git.merp.digital/eranmorkon/borgserver ``` #### BORG_APPEND_ONLY @@ -62,7 +62,7 @@ To declare a client as admin, set this variable to the name of the client/sshkey ##### Example ``` -docker run --rm -e BORG_APPEND_ONLY="yes" -e BORG_ADMIN="nolds_notebook" (...) nold360/borgserver +docker run --rm -e BORG_APPEND_ONLY="yes" -e BORG_ADMIN="nolds_notebook" (...) git.merp.digital/eranmorkon/borgserver ``` To prune repos from another client, you have to add the path to the repository in the clients directory: @@ -132,10 +132,3 @@ And create your first backup! ``` $ borg create backup:my_first_borg_repo::documents-2017-11-01 /home/user/MyImportentDocs ``` - -## Tags - -All images are freshly built every week & published as `nold360/borgserver` with the following tags: - - Next / Unstable [borg 1.2.0]: `bookworm`, `1.2.0` - - Latest / Stable [borg 1.1.16]: `bullseye`, `1.1.16`, `latest` - - Legacy / Buster [borg 1.1.9 ]: `buster`, `1.1.9` diff --git a/docker-compose.yml b/docker-compose.yml index e66b4cd..6557ab3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: borgserver: - image: nold360/borgserver + image: git.merp.digital/eranmorkon/borgserver #build: . volumes: - ./backup:/backup From 397f800372c87d8ea45b682f4762da78a5842943 Mon Sep 17 00:00:00 2001 From: Andreas Mieke Date: Sat, 13 Jan 2024 03:17:42 +0100 Subject: [PATCH 13/13] fix(platforms): Remove useless platforms --- .woodpecker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 75acfa0..b765cde 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -4,7 +4,7 @@ steps: settings: dry-run: true repo: git.merp.digital/${CI_REPO_OWNER}/borgserver - platforms: linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x + platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64/v8 registry: git.merp.digital when: - event: push @@ -15,7 +15,7 @@ steps: image: woodpeckerci/plugin-docker-buildx settings: repo: git.merp.digital/${CI_REPO_OWNER}/borgserver - platforms: linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x + platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64/v8 registry: git.merp.digital tags: develop-${CI_COMMIT_SHA} username: ${CI_REPO_OWNER} @@ -29,7 +29,7 @@ steps: image: woodpeckerci/plugin-docker-buildx settings: repo: git.merp.digital/${CI_REPO_OWNER}/borgserver - platforms: linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x + platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64/v8 registry: git.merp.digital tags: ${CI_COMMIT_TAG} username: ${CI_REPO_OWNER}