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

Leap 15.6: SFTP share error - library paths changed #2856

Closed
Hooverdan96 opened this issue Jun 21, 2024 · 4 comments · Fixed by #2858
Closed

Leap 15.6: SFTP share error - library paths changed #2856

Hooverdan96 opened this issue Jun 21, 2024 · 4 comments · Fixed by #2858
Assignees

Comments

@Hooverdan96
Copy link
Member

Hooverdan96 commented Jun 21, 2024

Thanks to forum user mpidala, the following issue was reported during sftp share creation on a Leap 15.6 Rockstor instance (https://forum.rockstor.com/t/error-adding-sftp-share/9548/):
the following error message is thrown when trying to create an sftp share:

            Traceback (most recent call last):
  File "/opt/rockstor/src/rockstor/rest_framework_custom/generic_view.py", line 41, in _handle_exception
    yield
  File "/opt/rockstor/src/rockstor/storageadmin/views/sftp.py", line 82, in post
    rsync_for_sftp(chroot_loc)
  File "/opt/rockstor/src/rockstor/system/ssh.py", line 303, in rsync_for_sftp
    copy(l, "{}{}".format(chroot_loc, l))
  File "/usr/lib64/python3.11/shutil.py", line 431, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib64/python3.11/shutil.py", line 256, in copyfile
    with open(src, 'rb') as fsrc:
         ^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/lib64/libz.so.1'

As @FroggyFlox already identified, some of the shared libraries that are symbolically linked during the sftp process can't be found because their physical location has changed with the Leap 15.6 release. Within the Rockstor code base they are maintained here:

"opensuse-leap": [
"/lib64/libacl.so.1",
"/lib64/libz.so.1",
"/usr/lib64/libpopt.so.0",
"/usr/lib64/libslp.so.1",
"/lib64/libc.so.6",
"/lib64/libattr.so.1",
"/usr/lib64/libcrypto.so.1.1",
"/lib64/libpthread.so.0",
ld_linux_so,
"/lib64/libdl.so.2",
"/lib64/libreadline.so.7",
"/lib64/libtinfo.so.6",

the one that triggered the above error is assumed to be located in:
/lib64/libz.so.1

In Leap 15.6 the location has changed to:
/usr/lib64/libz.so.1

This likely has to be updated. The decision here is whether to remain backwards compatible to at least Leap 15.5 or not.

If no, then an update of the paths in the above code snippet should be sufficient.
If yes, we will need an additional way of identifying which Leap release is currently being used during the execution of the program.

Unfortunately, in the copying process only the distribution ID (OS_DISTRO_ID) from the settings file is used to validate:

for l in libs_d[settings.OS_DISTRO_ID]:
copy(l, "{}{}".format(chroot_loc, l))
run_command([USERMOD, "-s", "/bin/bash", user], log=True)

As one can see, in the settings file the values for OS_DISTRO_ID do not distinguish by distribution release

# Establish our OS base id, name, and version:
# Use id for code path decisions. Others are for Web-UI display purposes.
# Examples given are for CentOS Rockstor variant, Leap 15, and Tumblweed.
OS_DISTRO_ID = distro.id() # rockstor, opensuse-leap/opensuse, opensuse-tumbleweed
OS_DISTRO_NAME = distro.name() # Rockstor, openSUSE Leap, openSUSE Tumbleweed
# Note that the following will capture the build os version.
# For live updates (running system) we call distro.version() directly in code.
OS_DISTRO_VERSION = distro.version() # 3, 15.0 ,20181107

Unfortunately, just replacing the OS_DISTRO_ID with 'OS_DISTRO_VERSION' would likely break the "rolling" Tumbleweed version in this case. Since the version under Tumbleweed changes with every release which are very frequent (daily/weekly). Updating Rockstor that frequently is neither practical nor sustainable.

One approach could be to add another condition that essentially checks whether the Rockstor instance runs on Leap, and if so, check whether it's version 15.6 or earlier. If earlier the current definition shown above would be used, and if 15.6 (and presumably later) select a newly created section that contains the altered paths to create symbolic links from. If 15.6 or higher, concatenate ID and Version and the section the copy process refers would also have the concatenated version (e.g. opensuse-leap15.6+ and for other leap flavors it remains what it was, opensuse-leap). That way, other Leap flavors are not impacted. Once support for 15.5 is dropped, that section can be dropped, and it can be similarly managed if a change comes with a 15.7 (if ever released) version ...

Or a completely different approach, of course.

Finally, I am surprised that the testing library would not have caught this, but I did not take a closer look at the unit tests. When fixing this, the unit test should probably be corrected, or if it doesn't exist should be created, since I suspect this will not be the last time that the location of these types of files will change. For reference:

https://github.com/rockstor/rockstor-core/blob/testing/src/rockstor/storageadmin/tests/test_sftp.py

happy path (which should be unhappy on 15.6 in my opinion):

# Create sftp for user-owned share - happy path
data = {
"shares": ("share_user_owned",),
"read_only": "true",
}
response = self.client.post(self.BASE_URL, data=data)
self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.data)

@Hooverdan96
Copy link
Member Author

I can confirm that the above file, /lib64/libz.so.1, seems to be the only one with a new path (/usr/lib64/libz.so.1). Furthermore, in a proof-of-concept I updated the new (no other code) in the leap section of the above code manually and executed systemctl restart rockstor.

Et voila, the sftp share could be created (non root-user owned). I just wanted to confirm that there aren't any follow-on errors during the sftp export creation, and it seem that there aren't.

@phillxnet phillxnet changed the title [t] 5.0.10-0 Rockstor on Leap 15.6: sftp share creation errors out due to changed shared library paths Leap 15.6: sftp share creation errors out due to changed shared library paths Jun 22, 2024
@phillxnet phillxnet self-assigned this Jun 22, 2024
@phillxnet
Copy link
Member

Currently working on this issue, and I have begun a minor modernisation of sorts. Way back we just grabbed these library dependencies from ldd bash and ldd rsync to enable both within the chroot we setup when establishing the sftp access. So I'm preparing a PR that dynamically retrieves the required dependencies per host OS and architecture. We likely also have some ARM issue also now. Plus the TW list is now out-of-date as well. Test of ldd wrapper used to be submitted with the associated PR.
Nearly there now.

@phillxnet phillxnet changed the title Leap 15.6: sftp share creation errors out due to changed shared library paths Leap 15.6: SFTP share error - library paths changed Jun 22, 2024
phillxnet added a commit to phillxnet/rockstor-core that referenced this issue Jun 22, 2024
Move to dynamic discovery of bash & rsync libraries when
populating ssh / sftp share chroot.
@Hooverdan96
Copy link
Member Author

way more elegant, actually :).

phillxnet added a commit to phillxnet/rockstor-core that referenced this issue Jun 25, 2024
Osi get_libs() was developed on test data void of
tab characters. Instantiation these surfaced a bug
re line (pre strip()) vs line field (stripped) use.
phillxnet added a commit to phillxnet/rockstor-core that referenced this issue Jun 25, 2024
phillxnet added a commit to phillxnet/rockstor-core that referenced this issue Jun 26, 2024
Move to dynamic discovery of bash & rsync libraries when
populating ssh / sftp share chroot. Incidental dropping
of the redundant chroot `bin` dir, we now use only
`/usr/bin` for both the `bash`, and `rsync` binaries.
@FroggyFlox FroggyFlox linked a pull request Jun 27, 2024 that will close this issue
phillxnet added a commit to phillxnet/rockstor-core that referenced this issue Jun 28, 2024
Ldd reports /lib for ld-linux-aarch64.so.1, this needs
to exist for our chroot copy to work. Previously we sourced
a link from /lib64 which we do already create.
phillxnet added a commit that referenced this issue Jul 3, 2024
…or---library-paths-changed

Leap 15.6: SFTP share error - library paths changed #2856
@phillxnet
Copy link
Member

Closing as:
Fixed by #2858

@phillxnet phillxnet added this to the 5.1.X-X Stable release milestone Jul 3, 2024
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

Successfully merging a pull request may close this issue.

2 participants