-
Notifications
You must be signed in to change notification settings - Fork 59
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
Run without sudo? #905
Comments
We can definitely make gProfiler run without root. It will require some iterative work of encountering problems, fixing them (by making them handle the lack of permissions gracefully) and continuing. Things I already have on my mind:
If you're working on eliminating the root requirement, you can write thoughts here about how to handle particular parts being blocked due to underprivilege, and I'll help addressing. I'm also open to a Zoom discussion over it :) |
There has been more requirements to make this happen. Some answers inline:
|
@Jongy, I'm working with @hsane2001 on this issue assuming the use case you mentioned where "running gProfiler w/o root is to profile applications running in the same mount/pid namespace". I've been bypassing the checks for run_in_ns when not in root, and redirecting some of the files to user writeable locations (such as with --log-file, --pid-file). One issue I've encountered where sudo is currently required (where it probably doesn't have to be) is this function: mkdir_owned_root https://github.com/Granulate/gprofiler/blob/9da69dbcbed9a378e042c35e9b3af21060e2a77f/gprofiler/utils/fs.py#L79 which ensures that a directory is owned by root when it is created to ensure other users cannot alter these files (for example for temporary files in /tmp). One potential approach, when running without sudo, is to redirect temporary files from /tmp to a per user temp directory, that can be deleted upon termination of gprofiler. Does this seem to be the right approach to you? Is there a better way you'd recommend for handling this function for "sudoless" execution? |
Hi @pcarella1 :) As for As for |
Hi @Jongy, I agree, run_in_ns_wrapper makes the most sense. I will take that approach. I've implemented changing self._ap_dir_base to resource_path as you suggested. I have found a new issue, in the pgrep_maps function, which runs this command ""grep -lE '{match}' /proc/*/maps"" while searching for the process memory maps of various libraries such as ruby, libjvm, etc.. This returns an error as some of the processes under /proc are not readable by non-root user. What do you suggest as the workaround for this? Error is here: |
Hi @pcarella1 , sorry for my late reply. I think that in this mode of operation, we can fix |
@Jongy It seems the main use for this function (pgrep_maps, as mentioned in my last message) is to find the process ID for python, ruby, java, and dotnet, so it get select those profilers rather than perf if they are used. Is this correct? I've tried reading these function using the grep command located in pgrep_maps, and they all return permissions errors. This would make it impossible for gprofiler to detect if python, ruby, java, or dotnet are being used to select those profilers. What is the correct solution for this? Should I try to use another command other than greping proc/*/maps (such as ps -aux | grep python) to get the PID for these? Do any of these profilers require sudo anyway, so we should just set a limitation that sudoless can't be used with them? (Amusingly, I found an issue on the py-spy repo where you advise on ptrace_scope value to run py-spy without root :), so it looks like it should be possible for python at least) Please advise. |
Correct. Let me elaborate on my reply from 2 weeks ago. The access to
To run any profiler (gProfiler or not) that needs ptrace access, you can either run as root, which gives you |
@Jongy I submitted PR drafts for this, please review and respond if you get a chance. I mention some issues in the PR, but we can discuss here if that's a better place. |
Can we allow gprofiler to run without sudo? There are many instances where sudo is not possible and it would be great to get app level stacks even if in a limited manner. Besides perf which would require sudo (although can be made to run otherwise), there are many cases where the code internally uses root access to the filesystem for namespaces and storing intermediate data.
The text was updated successfully, but these errors were encountered: