Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions contrib/rrsync/05-hostkeys.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Host keys are generated at container start (see entrypoint.sh) into a
# dedicated directory rather than baked into the image or the default
# /etc/ssh location.
HostKey /etc/ssh/keys/ssh_host_rsa_key
HostKey /etc/ssh/keys/ssh_host_ecdsa_key
HostKey /etc/ssh/keys/ssh_host_ed25519_key
6 changes: 6 additions & 0 deletions contrib/rrsync/10-rsync.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Restrict all SSH sessions to rsync-over-ssh; no interactive shell access.
ForceCommand /usr/bin/rrsync /data
PermitTTY no
X11Forwarding no
AllowTcpForwarding no
AllowAgentForwarding no
21 changes: 21 additions & 0 deletions contrib/rrsync/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM almalinux:9

LABEL maintainer="OSG Software <help@osg-htc.org>"

RUN --mount=type=cache,id=dnf-9,target=/var/cache/dnf,sharing=locked \
dnf install -y openssh-server rsync-rrsync

RUN mkdir /data

RUN mkdir -p -m0755 /run/sshd && \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to create /run/sshd in the entryping, since /run can be a tmpfs.

mkdir -p -m0700 /root/.ssh && \
mkdir -p -m0700 /etc/ssh/keys

COPY --chown=root:root --chmod=0644 10-rsync.conf /etc/ssh/sshd_config.d/10-rsync.conf
COPY --chown=root:root --chmod=0644 05-hostkeys.conf /etc/ssh/sshd_config.d/05-hostkeys.conf
COPY --chown=root:root --chmod=0755 entrypoint.sh /entrypoint.sh

CMD ["/entrypoint.sh"]

EXPOSE 22/tcp
VOLUME /data
25 changes: 25 additions & 0 deletions contrib/rrsync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
rsync-over-ssh sidecar
======================

Runs an sshd server intended to be deployed as a sidecar container in a
Kubernetes Pod, allowing external clients to write to a shared volume via
rsync over ssh.

To permit login, volume-mount an `authorized_keys` file into
`/root/.ssh/authorized_keys`.
Mount the target data volume into `/data`.

sshd is configured (see `10-rsync.conf`) to reject interactive shell
access: every session is forced through [`rrsync`](https://download.samba.org/pub/rsync/rrsync.1).
which restricts the client to rsync operations rooted at `/data` and
rejects anything else.

Example usage:

```
docker run --detach --name rrsync \
-v ~/authorized_keys:/root/.ssh/authorized_keys \
-v ~/mydata:/data \
-p2222:22 rrsync
rsync -e "ssh -p 2222" myfile.txt root@localhost:/
```
12 changes: 12 additions & 0 deletions contrib/rrsync/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set -e

KEY_DIR=/etc/ssh/keys

if [ ! -f "$KEY_DIR/ssh_host_rsa_key" ]; then
for type in rsa ecdsa ed25519; do
ssh-keygen -q -t "$type" -f "$KEY_DIR/ssh_host_${type}_key" -N ''
done
fi

exec /usr/sbin/sshd -D -e
Loading