运行 使用 RBAC 的性能工具

Running performance tools using RBAC

我最近开始了一项涉及大量性能调整的工作。

我想知道像eBPF 和perf 这样的工具是否可以与RBAC 一起使用?还是需要完全的 root 访问权限?获得根访问权限可能很困难。我们主要使用相当旧的 Linux 机器 - RHEL 6.5。我对 RBAC 不太熟悉。我在 Solaris、macOS 和 FreeBSD 上使用过 Dtrace,但我有 root 密码。

RHEL 列出了几个针对 RHEL6 的分析和跟踪解决方案,其中包括 perf Performance Tuning Guide and Developer Guide: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/performance_tuning_guide/s-analyzperf-perf https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/developer_guide/perf-using

Chapter 3. Monitoring and Analyzing System Performance of Performance Tuning Guide 提到了几个工具:Gnome System Monitor、KDE ​​System Guard、Performance Co-Pilot (PCP)、top/ps/vmstat/sar、tuned 和 ktune、MRG Tuna 以及应用程序分析器 SystemTap、Oprofile、 Valgrind(这不是真正的分析器,而是 cpu 具有指令和缓存事件计数的模拟器),perf.

Chapter 5. Profiling of Developer Guide 列出 Valgrind、oprofile、SystemTap、perf 和 ftrace。

通常只允许对 root 或具有 CAP_SYS_ADMIN 能力的用户进行内核或整个系统的分析。某些分析受限于 sysctl 变量

perf_event_paranoid:

Controls use of the performance events system by unprivileged users (without CAP_SYS_ADMIN). The default value is 2.

 -1: Allow use of (almost) all events by all users
     Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK
>=0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN
     Disallow raw tracepoint access by users without CAP_SYS_ADMIN
>=1: Disallow CPU event access by users without CAP_SYS_ADMIN
>=2: Disallow kernel profiling by users without CAP_SYS_ADMIN
kptr_restrict:

This toggle indicates whether restrictions are placed on
exposing kernel addresses via /proc and other interfaces.

ubuntu 和 rhel (7.4) 的更新版本也 kernel.yama.ptrace_scope http://security-plus-data-science.blogspot.com/2017/09/some-security-updates-in-rhel-74.html

... use kernel.yama.ptrace_scope to set who can ptrace. The different values have the following meaning:

# 0 - Default attach security permissions.
# 1 - Restricted attach. Only child processes plus normal permissions.
# 2 - Admin-only attach. Only executables with CAP_SYS_PTRACE.
# 3 - No attach. No process may call ptrace at all. Irrevocable until next boot.

You can temporarily set it like this:

 echo 2 > /proc/sys/kernel/yama/ptrace_scope

要分析一个程序,您应该有权调试它,例如附加 gdb(ptrace 功能)或 strace。我不知道 RHEL 或 its RBAC 所以你应该检查一下你可以使用什么。通常,在更多情况下可以对自己的用户空间程序进行软件事件性能分析。访问每个进程 cpu 硬件计数器,分析其他用户的程序,分析内核更受限制。我可以预期正确启用的 RBAC 不应允许您或 root 分析内核,因为 perf 可以注入跟踪探测器并从内核或其他用户泄漏信息。

Qeole 在 that eBPF is not implemented for RHEL6 (added in RHEL7.6; with XDP - eXpress Data Path in RHEL8) 中说,因此您只能尝试使用 ftrace 进行跟踪或使用 stap (SystemTap) 进行高级跟踪。