From a8152cf0b7a7c4fba9d2c15de4efe6c0ec91718e Mon Sep 17 00:00:00 2001 From: Jose Castillo Date: Fri, 11 Oct 2024 13:31:16 +0100 Subject: [PATCH] [ssh] Stop collecting 'ls' information from non-local home dirs Commands like 'ls -laZ' can take some time to run in remote filesystems, for example NFS. When you have hundreds of them, sos can take a long time to walk through it, and could be even worse if we use the option 'recursive'. For ssh home dirs, we don't need the listing, so in this patch we detect the type of filesystem and run the command only on local ones. Related: RHEL-22389, SUPDEV-156 Signed-off-by: Jose Castillo --- sos/report/plugins/ssh.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sos/report/plugins/ssh.py b/sos/report/plugins/ssh.py index 7e426f31fc..13b53c226c 100644 --- a/sos/report/plugins/ssh.py +++ b/sos/report/plugins/ssh.py @@ -80,8 +80,25 @@ def user_ssh_files_permissions(self): """ users_data = pwd.getpwall() + fs_mount_info = {} + try: + with open('/proc/mounts', "r", encoding='UTF-8') as mounts_file: + for line in mounts_file: + (fs_file, fs_vstype) = line.split()[1:3] + fs_mount_info[fs_file] = fs_vstype + except Exception: + self._log_error("Couldn't read /proc/mounts") + return + non_local_fs = {'nfs', 'nfs4', 'autofs'} # Read the home paths of users in the system and check the ~/.ssh dirs for user in users_data: + if user.pw_dir in fs_mount_info and \ + fs_mount_info[user.pw_dir] in non_local_fs: + self._log_info( + f"Skipping capture in {user.pw_dir}" + " because it's a remote directory" + ) + continue home_dir = self.path_join(user.pw_dir, '.ssh') self.add_dir_listing(home_dir)