Skip to content

About

Minimal BorgBackup SSH service with least-privilege access and persistent storage

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

borg-ssh-server

Dockerfile and associated scripts to facilitate build of a Docker image for OpenSSH + BorgBackup.

BorgBackup is a deduplicating backup program with a client-server model capable of hosting repositories on remote servers.

The borg-ssh-sever image, when run as a container, provides a remote server for BorgBackup clients.

The Basics

  • built on the debian bookworm release
  • has a single user account named borg
  • runs sshd as PID 1 with logging on stderr
  • accepts only public-key authentication
  • map container TCP port 22 to an available port on your host, e.g. port 2222
  • bind mount /repos for BorgBackup repositories
  • bind mount /etc/ssh/ssh_host_ed25519_key and /etc/ssh/ssh_host_ed25519_key.pub ED25519 host keys generated by ssh-keygen
  • bind mount /home/borg/.ssh/authorized_keys with command restricted to 'borg serve'; see config/authorized_keys_template
  • entrypoint script is used to coerce the borg account's UID and GID to match those of the bind-mounted /home/borg/.ssh/authorized_keys prior to sshd startup, within Debian policy manual guidelines
  • authorized_keys files are discussed in the OpenSSH sshd man page
  • BorgBackup's sshd configuration guidelines are implemented

Image on docker hub: chadly314/borg-ssh-server

Background

This image was inspired by a desire to overcome SSH authentication limitations on a Synology Diskstation NAS, and turned out to be educational for the author to learn more about how BorgBackup's architecture decouples decouples networking, authorization, and transport security from the application itself. It is possible that this image could be used as a OpenSSH container 'pattern' for applications which follow BorgBackup's design model.

BorgBackup's authorization and transport security properties are inherited from SSH and the configuration of the SSH client and the SSH server -- Borg RPC does not contain any networking code. 1

The container exposes a single-purpose service (borg serve) over SSH without granting an interactive shell. OpenSSH provides authentication + encryption + transport; authorization is enforced via authorized_keys restrictions and a forced command.

By running sshd inside the container with commands restricted by authorized_keys:

  • a dedicated unprivileged user (borg) is enforced
  • no shell access is granted
  • no Docker control or host namespace access is possible
  • the authentication boundary aligns exactly with the service boundary
  • SSH is used purely as a transport and authentication mechanism, not as a general login facility

The intended use model is to leverage SSH’s forced-command mechanism in /home/borg/.ssh/authorized_keys to restrict the borg user to running borg serve only. Interactive shells, port forwarding, and agent forwarding are disabled via authorized_keys options so that:

  • the SSH session cannot be repurposed
  • authentication success does not imply general execution capability
  • the Borg repository interface is the only exposed API

SSH host identity is managed explicitly:

  • Only ED25519 host keys are used
  • Host keys are generated prior to container runtime if missing
  • Keys are not baked into the image to avoid shared identities across deployments

All sensitive state is externalized via bind mounts:

  • Borg repositories: /repos
  • sshd host keys: /etc/ssh/ssh_host_ed25519_key, /etc/ssh/ssh_host_ed25519_key.pub
  • borg user authorized_keys: /home/borg/.ssh/authorized_keys

The container image itself is treated as stateless. Recreating the container does not rotate identities or destroy data.

Further Reading

About

Minimal BorgBackup SSH service with least-privilege access and persistent storage

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages