-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support for "rootless" ping #642
Conversation
This works for Linux and Darwin. On Linux the user running the exporter needs to be a member of a group with an ID in the range specified in the sysctl net.ipv4.ping_group_range. Signed-off-by: David Leadbeater <[email protected]>
Update some comments and mention that dont_fragment needs raw sockets. Signed-off-by: David Leadbeater <[email protected]>
Thanks for the review, I've updated some comments, also added a note about dont_fragment in the configuration doc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this is great!
Thanks! |
Did a little more investigation into where ping_group_range is set on Linux, as on several machines I was seeing It turns out as of systemd/systemd#13141 (via https://fedoraproject.org/wiki/Changes/EnableSysctlPingGroupRange) if you're using systemd then this is set by it; the relevant file ends up not in /etc, but somewhere like Not sure it's worth documenting the intricacies of systemd in the blackbox_exporter README, but maybe this helps someone understand what's going on. |
I think mentioning the standard sysctl.conf location is fine, rather than getting into per-distro stuff. |
`net.ipv4.ping_group_range = 0 2147483647` to allow any user the ability | ||
to use ping. | ||
* Alternatively the capability can be set by executing `setcap cap_net_raw+ep | ||
blackbox_exporter` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way is to do it in the systemd unit which starts blackbox_exporter:
[Service]
...
AmbientCapabilities=CAP_NET_RAW
This works for Linux and Darwin.
On Linux the user running the exporter needs to be a member of a group
with an ID in the range specified in the sysctl
net.ipv4.ping_group_range.
Fixes #147.
I've tested this on:
Darwin, macOS 10.15.4
Works, able to set ID and confirmed with tcpdump the ID is the same on outgoing
packets.
Linux 5.4.43 (NixOS)
Kernel always overwrites ID, e.g.:
tcpdump:
The code takes this into account.
Works when:
Example log:
Fails when running as user with:
Example log:
Succeeds using raw sockets when run as user with CAP_NET_RAW but not in ping_group_range:
Example log:
Succeeds when run as root with (non default):
Example log:
Note this uses "udp" sockets when run as root, if they work (no fallback
output). The thinking being root in a Docker container may not have CAP_NET_RAW
but may be able to use ping sockets.
Succeeds using raw sockets when run as root with ping_group_range disabled
(this is the default Linux kernel setting, but overridden via sysctl.conf on
many recent distributions default configuration):
Example log:
Prober configured with
dont_fragment: true
, fails running as normal user asit must use raw sockets: