Skip to content

Commit d7fe675

Browse files
authored
Make jail for work sftp by using the binary sftp-server (hestiacp#4803)
* Make jail work with sftp by using the binary sftp-server The internal-sftp server doesn't start a new process. This makes it improssible jail the sftp process since it's running inside sshd. By changing to the binary sftp-server the process is run inside the bubblewrap jailbash container. * Hide /usr/local/hestia and /usr/share in bubblewrap container
1 parent 8023f1f commit d7fe675

File tree

9 files changed

+26
-5
lines changed

9 files changed

+26
-5
lines changed

bin/v-add-sys-sftp-jail

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if [ "$restart" = 'yes' ]; then
6565
\n\n$(/usr/sbin/sshd -t)"
6666
echo -e "$mail_text" | $SENDMAIL -s "$subj" $email
6767
else
68-
service sshd restart > /dev/null 2>&1
68+
service ssh restart > /dev/null 2>&1
6969
fi
7070
fi
7171

bin/v-add-sys-ssh-jail

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ if [ -z "$(grep ^/usr/sbin/jailbash /etc/shells)" ]; then
5252
echo "/usr/sbin/jailbash" >> /etc/shells
5353
fi
5454

55+
# Use sftp-server binary so the sftp process can run inside jailbash
56+
if [ -z "$(grep 'Subsystem sftp /usr/lib/sftp-server' /etc/ssh/sshd_config)" ]; then
57+
sed -i -E "s/Subsystem sftp internal-sftp/Subsystem sftp \/usr\/lib\/sftp-server/g" /etc/ssh/sshd_config
58+
59+
service ssh restart > /dev/null 2>&1
60+
fi
61+
5562
#----------------------------------------------------------#
5663
# Hestia #
5764
#----------------------------------------------------------#

bin/v-add-user-sftp-jail

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ if [ "$restart" = 'no' ]; then
8686
# Skip restart of SSH daemon
8787
echo "" > /dev/null 2>&1
8888
else
89-
service sshd restart > /dev/null 2>&1
89+
service ssh restart > /dev/null 2>&1
9090
fi
9191

9292
# Logging

bin/v-delete-sys-sftp-jail

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if [ "$restart" = 'yes' ]; then
6262
\n\n$(/usr/sbin/sshd -t)"
6363
echo -e "$mail_text" | $SENDMAIL -s "$subj" $email
6464
else
65-
service sshd restart > /dev/null 2>&1
65+
service ssh restart > /dev/null 2>&1
6666
fi
6767
fi
6868

bin/v-delete-sys-ssh-jail

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ if [ -x /usr/sbin/jailbash ]; then
4040
service apparmor reload > /dev/null 2>&1
4141
fi
4242

43+
# Revert back to internal-sftp
44+
if [ -z "$(grep 'Subsystem sftp internal-sftp' /etc/ssh/sshd_config)" ]; then
45+
sed -i -E "s/Subsystem sftp \/usr\/lib\/sftp-server/Subsystem sftp internal-sftp/g" /etc/ssh/sshd_config
46+
47+
service ssh restart > /dev/null 2>&1
48+
fi
49+
4350
#----------------------------------------------------------#
4451
# Hestia #
4552
#----------------------------------------------------------#

bin/v-delete-user-sftp-jail

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ delete_chroot_jail $user
7676
#----------------------------------------------------------#
7777

7878
# Restart ssh service
79-
service sshd restart > /dev/null 2>&1
79+
service ssh restart > /dev/null 2>&1
8080

8181
# Logging
8282
log_event "$OK" "$ARGUMENTS"

install/common/bubblewrap/jailbash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ set -euo pipefail
1010
--ro-bind-try /lib64 /lib64 \
1111
--tmpfs /usr/lib/modules \
1212
--tmpfs /usr/lib/systemd \
13+
--tmpfs /usr/local/hestia \
14+
--tmpfs /usr/share \
1315
--ro-bind /bin /bin \
1416
--ro-bind /sbin /sbin \
1517
--dir /var \

install/upgrade/manual/migrate_jailkit_to_bubblewrap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ if [ -n "$ssh_i" ]; then
9090
\n\n$(/usr/sbin/sshd -t)"
9191
echo -e "$message"
9292
else
93-
service sshd restart > /dev/null 2>&1
93+
service ssh restart > /dev/null 2>&1
9494
fi
9595
fi
9696

install/upgrade/versions/1.9.3.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ upgrade_config_set_value 'UPGRADE_UPDATE_FILEMANAGER_CONFIG' 'false'
2727
if [ ! -f /etc/apparmor.d/abi/4.0 ]; then
2828
rm -f /etc/apparmor.d/bwrap-userns-restrict
2929
fi
30+
31+
if [ -x /usr/sbin/jailbash ]; then
32+
$HESTIA/bin/v-delete-sys-ssh-jail
33+
$HESTIA/bin/v-add-sys-ssh-jail
34+
fi

0 commit comments

Comments
 (0)