The comment by @waltinator
Read man capabites and endow your userid with CAP_SYS_ADMIN
refers to capabilities(7), which currently says this:
CAP_PERFMON
(since Linux 5.8)
Employ various performance-monitoring mechanisms, including:
- call perf_event_open(2);
- employ various BPF operations that have performance implications.
This capability was added in Linux 5.8 to separate out
performance monitoring functionality from the overloaded
CAP_SYS_ADMIN
capability. See also the kernel source file
Documentation/admin-guide/perf-security.rst
.
That doesn't go into detail explaining how to do this, but gives a list of programs at the end, including getcap
(8) and setcap
(8) which can be used to inspect the capabilities added to a given file and to modify the capabilities.
OP's question is tagged for Ubuntu (i.e., Debian). For some other systems, there may be configuration files which apply these settings, e.g., How do you add cap_sys_admin
permissions to user in CentOS 7?, but in Debian, etc., that is normally done via the package install-scripts.
For example, Ubuntu 18.04 has this from running getcap /usr/bin/*
:
/usr/bin/gnome-keyring-daemon = cap_ipc_lock+ep
/usr/bin/mtr-packet = cap_net_raw+ep
mtr-tiny
is part of mtr
, and the package files for that include its postinstall
script:
#!/bin/sh
set -e
if [ "$1" = configure ]; then
# If setcap is installed, try setting cap_net_raw+ep,
# which allows us to install our binaries without the setuid
# bit.
if command -v setcap > /dev/null; then
if ! setcap cap_net_raw+ep /usr/bin/mtr-packet; then
echo "Setcap failed on /usr/bin/mtr-packet, falling back to setuid" >&2
chmod u+s /usr/bin/mtr-packet
fi
else
echo "Setcap is not installed, falling back to setuid" >&2
chmod u+s /usr/bin/mtr-packet
fi
fi
#DEBHELPER#
exit 0
In the pertinent command
setcap cap_net_raw+ep /usr/bin/mtr-packet
the cap_net_raw
should be obvious. That ep
is less apparent. Looking at the source code
printf("%s differs in [%s%s%s]\n", *argv,
CAP_DIFFERS(cmp, CAP_PERMITTED) ? "p" : "",
CAP_DIFFERS(cmp, CAP_INHERITABLE) ? "i" : "",
CAP_DIFFERS(cmp, CAP_EFFECTIVE) ? "e" : "");
helps clarify this paragraph in cap_to_text(3):
Each clause consists of a list of comma-separated capability names (or the word all
),
followed by an action-list. An action-list consists of a sequence of operator flag pairs.
Legal operators are: =
, '+', and -
. Legal flags are: e
, i
, and p
. These flags
are case-sensitive and specify the Effective, Inheritable and Permitted sets respectively.
In short, you'd use setcap
for adding whatever capabilities are needed with the kernel you're using to the perf
program file, with the appropriate flags.
man capabites
and endow your userid withCAP_SYS_ADMIN
. – waltinator Jun 14 '20 at 02:37