Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFTP user chroot shell path update & ls addition #2863

Closed
phillxnet opened this issue Jul 3, 2024 · 7 comments
Closed

SFTP user chroot shell path update & ls addition #2863

phillxnet opened this issue Jul 3, 2024 · 7 comments
Assignees

Comments

@phillxnet
Copy link
Member

During #2858's development, it was noted that we have the following shell setup enforced for SFTP users:

run_command([USERMOD, "-s", "/bin/bash", user], log=True)

I.e. we modify the SFTP user's shell to /bin/bash which is likely now inconsistent with the new chroot environment setup by way of SFTP configuration.


Reproducer of consequent behaviour to follow.

@phillxnet phillxnet added this to the 5.1.X-X Stable release milestone Jul 3, 2024
@phillxnet phillxnet self-assigned this Jul 8, 2024
@phillxnet
Copy link
Member Author

Post having enabled sftp we have the following config for the specific user (owner of the share we sftp export):
via:

cat /etc/ssh/sshd_config

###BEGIN: Rockstor SFTP CONFIG. DO NOT EDIT BELOW THIS LINE###
Subsystem       sftp    internal-sftp
AllowUsers root sftp-user
Match User sftp-user
        ForceCommand internal-sftp
        ChrootDirectory /mnt3/sftp-user
        X11Forwarding no
        AllowTcpForwarding no

With a necessary minor edit (remarking out) above this re the sftp subsystem line:

#Subsystem sftp /usr/lib/ssh/sftp-server

@phillxnet
Copy link
Member Author

phillxnet commented Jul 8, 2024

Once we setup a proposed sftp-user, and a SFTP share owned by them, i.e. sftp-share and enable the export of this share we have the setup used during the final testing of #2858 (#2858 (comment)):

As per documented setup:
"Secure File Transport Protocol (SFTP)"
https://rockstor.com/docs/interface/storage/file_sharing/sftp.html

  1. create sftp-user
  2. create sftp-share
  3. Edit sftp-share Access control to owner=sftp-user
  4. Add SFTP Share sftp-share

If we then attempt to ssh in as this user:

ssh [email protected]
Password: 

The result we receive is, as per our "ForceCommand internal-sftp" configuration":

This service allows sftp connections only.
Connection to rleap15-6.lan closed.

See PR: "Configure SFTP server at buildtime and update customization settings. Fixes #2168" #2173 for the origin of this config development:

In addition, this PR also takes the opportunity to add per-user customization settings to be in accordance with the settings recommended on hte openSUSE wiki:
https://en.opensuse.org/SDB:SFTP_server_with_Chroot#Match_rule_block

@phillxnet
Copy link
Member Author

phillxnet commented Jul 8, 2024

So given the last comment, our now inconsistent bash path, given the changes to our chroot introduced in #2858, has no current artifacts as we "ForceCommand" the internal-sftp as the user's 'shell'. However we may want to accommodate custom behaviour in the future that utilises our chroot setup. Doing a quick investigation of this now re:

# Set options for each user according to openSUSE's defaults:
# https://en.opensuse.org/SDB:SFTP_server_with_Chroot#Match_rule_block
# TODO: implement webUI element to re-enable rsync over ssh by omitting
# the `ForceCommand internal-sftp` line below.
for user in input_map:
tfo.write("Match User {}\n".format(user))
tfo.write("\tForceCommand internal-sftp\n")
tfo.write("\tChrootDirectory {}\n".format(input_map[user]))
tfo.write("\tX11Forwarding no\n")
tfo.write("\tAllowTcpForwarding no\n")
move(npath, SSHD_CONFIG[distro_id].sftp)

@phillxnet
Copy link
Member Author

phillxnet commented Jul 8, 2024

By way of testing a future modification re no or custom ForceCommand, if we remove the ForceCommand line, and stop/start all rockstor* services; then wipe/re-enable the same sftp-share export we end-up with the following config:

###BEGIN: Rockstor SFTP CONFIG. DO NOT EDIT BELOW THIS LINE###
Subsystem       sftp    internal-sftp
AllowUsers root sftp-user
Match User sftp-user
        ChrootDirectory /mnt3/sftp-user
        X11Forwarding no
        AllowTcpForwarding no

We end-up running into the issue anticipated bash path fail within our chroot:

ssh [email protected]
Password: 
Have a lot of fun...
Last login: -----------------------------
/bin/bash: No such file or directory
Connection to rleap15-6.lan closed.

@phillxnet
Copy link
Member Author

phillxnet commented Jul 8, 2024

If we correct the sftp-user shell path, stop/start all rockstor* services and exercise our proposed custom sftp/ssh config with the ForceCommand line removed from the referenced code above (restoring a chroot bash shell) we have a successful ssh login for the same sftp-user:

ssh [email protected]
Password: 
Have a lot of fun...
Last login: Mon Jul  8 18:26:30 2024 from 192.168.2.172
-bash-4.4$

This is a highly constrained shell, as intended, as we have only bash and rsync binaries (plus lib dependencies) accessible: but that is outside the scope of this issue. I.e.:

-bash-4.4$ ls
-bash: ls: command not found
-bash-4.4$

but we have our intended rsync binary available:

-bash-4.4$ rsync --version
rsync  version 3.2.7  protocol version 31
...

We also see in our Web-UI the sftp-user's Shell entry as follows:

Username UID Group GID Shell
sftp-user 1006 users 100 /usr/bin/bash

@phillxnet
Copy link
Member Author

phillxnet commented Jul 8, 2024

By way of providing at least ls if we add this to our PROGS_IN_CHROOT , along with our user Shell path correction, we can see at least our chroot's \ thus:

ssh [email protected]
Password: 
Have a lot of fun...
Last login: ...
-bash-4.4$ ls -la
total 0
drwxr-xr-x 1    0 0  42 Jul  8 17:48 .
drwxr-xr-x 1    0 0  42 Jul  8 17:48 ..
drwxr-xr-x 1    0 0   0 Jun 28 17:01 lib
drwxr-xr-x 1    0 0 182 Jun 28 10:23 lib64
drwxr-xr-x 1 1006 0   0 Jul  8 16:05 sftp-share
drwxr-xr-x 1    0 0  16 Jun 28 10:23 usr

Assuming the proposed user intervention of removing our overarching constraint of the "ForcedCommand" limitation for all SFTP users.

@phillxnet phillxnet changed the title SFTP user chroot shell path SFTP user chroot shell path update & ls addition Jul 8, 2024
phillxnet added a commit to phillxnet/rockstor-core that referenced this issue Jul 8, 2024
Correct currently ineffectual BASH path in SFTP chroot setup.
Default sshd user specific config: via SFTP Share export,
enforces `ForceCommand internal-sftp`, however future
enhancements (or current by-hand "ForceCommand ..." removal)
results in a chroot failure for SFTP enabled users accessing
via SSH.
phillxnet added a commit that referenced this issue Jul 9, 2024
…ath-update-&-ls-addition

SFTP user chroot shell path update & ls addition #2863
@phillxnet
Copy link
Member Author

Closing as:
Fixed by #2865

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant