abrt / retrace-server

Application for remote coredump analysis
GNU General Public License v2.0
40 stars 30 forks source link

retrace: Fix Traceback if user's home directory is unavailable #470

Closed DaveWysochanskiRH closed 2 years ago

DaveWysochanskiRH commented 2 years ago

We had an instance in production where a user's home directory was unable to be accessed and returned "permission denied". This also had the effect of a Traceback if a user tried "retrace-server-task create" or even "retrace-server-interact", since the hooks path failed with permission denied per below. Fix the Traceback by wrapping pathlib.exist() checks in try .. except clauses.

Before the patch: $ retrace-server-interact 846035327 crash Traceback (most recent call last): File "/usr/bin/retrace-server-interact", line 12, in from retrace.retrace import (ALLOWED_FILES, File "/usr/lib/python3.6/site-packages/retrace/init.py", line 18, in from . import retrace_worker File "/usr/lib/python3.6/site-packages/retrace/retrace_worker.py", line 16, in from .hooks.hooks import RetraceHook File "/usr/lib/python3.6/site-packages/retrace/hooks/init.py", line 3, in from . import hooks File "/usr/lib/python3.6/site-packages/retrace/hooks/hooks.py", line 11, in from .config import HOOK_PATH, HOOK_TIMEOUT, hooks_config File "/usr/lib/python3.6/site-packages/retrace/hooks/config.py", line 56, in hooks_config = load_hook_config() File "/usr/lib/python3.6/site-packages/retrace/hooks/config.py", line 45, in load_hook_config if USER_HOOK_CONFIGS_PATH.exists(): File "/usr/lib64/python3.6/pathlib.py", line 1336, in exists self.stat() File "/usr/lib64/python3.6/pathlib.py", line 1158, in stat return self._accessor.stat(self) File "/usr/lib64/python3.6/pathlib.py", line 387, in wrapped return strfunc(str(pathobj), *args) PermissionError: [Errno 13] Permission denied: '/home/foo/user/.config/retrace-server/hooks'

After the patch: $ retrace-server-interact 279216098 crash USER_HOOK_CONFIGS_PATH /home/foo/.config/retrace-server/hooks does not exist: [Errno 13] Permission denied: '/home/foo/.config/retrace-server/hooks' USER_CONFIG_PATH /home/foo/.config/retrace-server does not exist: [Errno 13] Permission denied: '/home/foo/.config/retrace-server' If you want to execute the command manually, you can run $ crash -i /cores/retrace/tasks/789215099/crashrc /cores/retrace/tasks/789215099/crash/vmcore /cores/retrace/repos/kernel/x86_64/usr/lib/debug/lib/modules/4.18.0-80.el8.x86_64/vmlinux ...

Signed-off-by: Dave Wysochanski dwysocha@redhat.com

lgtm-com[bot] commented 2 years ago

This pull request introduces 2 alerts when merging f1357bdff577ffe0f57d58c1e50efde69c291ca3 into 8e46e15342689dfb8153aa0044302c66bdae3fbd - view on LGTM.com

new alerts:

codecov-commenter commented 2 years ago

Codecov Report

Merging #470 (86b9a51) into master (8e46e15) will increase coverage by 0.02%. The diff coverage is 40.00%.

@@            Coverage Diff             @@
##           master     #470      +/-   ##
==========================================
+ Coverage   21.97%   22.00%   +0.02%     
==========================================
  Files          18       18              
  Lines        2853     2859       +6     
==========================================
+ Hits          627      629       +2     
- Misses       2226     2230       +4     
Flag Coverage Δ
unittests 22.00% <40.00%> (+0.02%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/retrace/hooks/config.py 76.74% <40.00%> (-7.04%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8e46e15...86b9a51. Read the comment docs.

DaveWysochanskiRH commented 2 years ago

FWIW, this can easly be reproduced with something like:

$ export HOME=/root
$ retrace-server-interact ...
OR
$ retrace-server-task create ...