-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ansible: Add restricted rsync endpoint
- Loading branch information
1 parent
fd976f5
commit 2516684
Showing
5 changed files
with
199 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[Unit] | ||
Description=SSH Server for RSync push | ||
After=network.target | ||
|
||
[Service] | ||
ExecStartPre=/usr/sbin/sshd -t | ||
ExecStart=/usr/sbin/sshd -f /var/lib/rsync-ssh/sshd_config | ||
ExecReload=/usr/sbin/sshd -t | ||
ExecReload=/bin/kill -HUP $MAINPID | ||
KillMode=process | ||
Restart=on-failure | ||
RestartPreventExitStatus=255 | ||
Type=notify | ||
RuntimeDirectory=rsync-sshd | ||
RuntimeDirectoryMode=0755 | ||
|
||
# Sandboxing | ||
RestrictSUIDSGID=true | ||
RestrictRealtime=true | ||
PrivateDevices=true | ||
PrivateTmp=true | ||
ProtectHostname=true | ||
NoNewPrivileges=true | ||
ProtectKernelTunables=true | ||
ProtectKernelModules=true | ||
ProtectKernelLogs=true | ||
ProtectControlGroups=true | ||
MemoryDenyWriteExecute=true | ||
ProtectSystem=full | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $ | ||
|
||
# This is the sshd server system-wide configuration file. See | ||
# sshd_config(5) for more information. | ||
|
||
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin | ||
|
||
# The strategy used for options in the default sshd_config shipped with | ||
# OpenSSH is to specify options with their default value where | ||
# possible, but leave them commented. Uncommented options override the | ||
# default value. | ||
|
||
Port 222 | ||
#AddressFamily any | ||
#ListenAddress 0.0.0.0 | ||
#ListenAddress :: | ||
|
||
HostKey /etc/ssh/ssh_host_rsa_key | ||
HostKey /etc/ssh/ssh_host_ecdsa_key | ||
HostKey /etc/ssh/ssh_host_ed25519_key | ||
|
||
# Ciphers and keying | ||
#RekeyLimit default none | ||
|
||
# Logging | ||
#SyslogFacility AUTH | ||
#LogLevel INFO | ||
|
||
# Authentication: | ||
|
||
#LoginGraceTime 2m | ||
PermitRootLogin no | ||
#StrictModes yes | ||
#MaxAuthTries 6 | ||
#MaxSessions 10 | ||
|
||
#PubkeyAuthentication yes | ||
|
||
# Disable .ssh/authorized_keys2 | ||
AuthorizedKeysFile .ssh/authorized_keys | ||
|
||
#AuthorizedPrincipalsFile none | ||
|
||
#AuthorizedKeysCommand none | ||
#AuthorizedKeysCommandUser nobody | ||
|
||
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts | ||
#HostbasedAuthentication no | ||
# Change to yes if you don't trust ~/.ssh/known_hosts for | ||
# HostbasedAuthentication | ||
#IgnoreUserKnownHosts no | ||
# Don't read the user's ~/.rhosts and ~/.shosts files | ||
#IgnoreRhosts yes | ||
|
||
# To disable tunneled clear text passwords, change to no here! | ||
PasswordAuthentication no | ||
PermitEmptyPasswords no | ||
|
||
# Change to yes to enable challenge-response passwords (beware issues with | ||
# some PAM modules and threads) | ||
ChallengeResponseAuthentication no | ||
|
||
# Kerberos options | ||
#KerberosAuthentication no | ||
#KerberosOrLocalPasswd yes | ||
#KerberosTicketCleanup yes | ||
#KerberosGetAFSToken no | ||
|
||
# GSSAPI options | ||
#GSSAPIAuthentication no | ||
#GSSAPICleanupCredentials yes | ||
#GSSAPIStrictAcceptorCheck yes | ||
#GSSAPIKeyExchange no | ||
|
||
# Set this to 'yes' to enable PAM authentication, account processing, | ||
# and session processing. If this is enabled, PAM authentication will | ||
# be allowed through the ChallengeResponseAuthentication and | ||
# PasswordAuthentication. Depending on your PAM configuration, | ||
# PAM authentication via ChallengeResponseAuthentication may bypass | ||
# the setting of "PermitRootLogin without-password". | ||
# If you just want the PAM account and session checks to run without | ||
# PAM authentication, then enable this but set PasswordAuthentication | ||
# and ChallengeResponseAuthentication to 'no'. | ||
UsePAM yes | ||
|
||
AllowAgentForwarding no | ||
AllowTcpForwarding no | ||
GatewayPorts no | ||
X11Forwarding no | ||
X11UseLocalhost no | ||
PermitTTY no | ||
PrintMotd no | ||
#PrintLastLog yes | ||
#TCPKeepAlive yes | ||
PermitUserEnvironment yes | ||
PermitUserRC no | ||
#Compression delayed | ||
#ClientAliveInterval 0 | ||
#ClientAliveCountMax 3 | ||
#UseDNS no | ||
#PidFile /var/run/sshd.pid | ||
#MaxStartups 10:30:100 | ||
PermitTunnel no | ||
#ChrootDirectory none | ||
#VersionAddendum none | ||
|
||
# no default banner path | ||
#Banner none | ||
|
||
# Allow client to pass locale environment variables | ||
AcceptEnv LANG LC_* | ||
|
||
# override default of no subsystems | ||
Subsystem sftp /usr/lib/openssh/sftp-server | ||
|
||
Match Address 127.0.0.1 | ||
AuthorizedKeysCommand /etc/ssh/local-login/key-command | ||
AuthorizedKeysCommandUser nobody |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-FileCopyrightText: 2024 Jonah Brüchert <[email protected]> | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
- name: Install rsync | ||
apt: | ||
name: | ||
- rsync | ||
- bubblewrap | ||
- dash | ||
- openssh-server | ||
|
||
- name: Create user for rsync upload | ||
user: | ||
name: rsync | ||
shell: /usr/bin/dash | ||
create_home: true | ||
home: /var/lib/rsync-ssh | ||
|
||
- name: Copy custom sshd_config | ||
copy: | ||
src: sshd_config | ||
dest: /var/lib/rsync-ssh/sshd_config | ||
|
||
- name: Install rsync-ssh.service | ||
copy: | ||
src: rsync-ssh.service | ||
dest: /etc/systemd/system/ | ||
|
||
- name: Create rsync target directory | ||
file: | ||
path: /srv/rsync/transitous/ | ||
state: directory | ||
owner: rsync | ||
|
||
- name: Add restricted authorized key for rsync | ||
authorized_key: | ||
user: rsync | ||
state: present | ||
key: 'command="bwrap --new-session --die-with-parent --cap-drop ALL --unshare-all --ro-bind /usr/lib/ /usr/lib/ --ro-bind /usr/bin/env /usr/bin/env --ro-bind /usr/bin/python3 /usr/bin/python3 --ro-bind /usr/bin/rrsync /usr/bin/rrsync --ro-bind /usr/bin/rsync /usr/bin/rsync --ro-bind /lib/ /lib/ --ro-bind /lib64/ /lib64 --bind /srv/rsync/transitous/ /srv/rsync/transitous/ -- /usr/bin/rrsync -wo /srv/rsync/transitous/",restrict {{ transitous_rsync_public_key }}' | ||
|
||
- name: Enable rsync-ssh.service | ||
systemd: | ||
name: rsync-ssh | ||
enabled: true | ||
masked: false | ||
state: running |