Skip to content
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

inputs.ping: Always SetPrivileged(true) in native mode #9072

Merged
merged 2 commits into from
Mar 30, 2021

Conversation

sspaink
Copy link
Contributor

@sspaink sspaink commented Mar 30, 2021

resolve #8919

As pointed out by the users in the above issue, the inputs.ping implementation was incomplete. The documentation made it seem you needed to set CAP_NET_RAW and set sysctl, while the CAP_NET_RAW solution wouldn't work without the call to SetPrivileged(true). As well when using FreeBSD you either need root or set CAP_NET_RAW in order to send ICMP packets, therefore requiring SetPrivileged(true).

When SetPrivileged(true) is not set the library go-ping will attempt to send a UDP ping which isn't as reliable as a ICMP ping. While a UDP ping doesn't require any permissions it will only work if the endpoint is configured to reply. This change will make using ICMP ping as the default behavior, requiring elevated permissions.

Output examples with the changes in this PR:

Example of what happens when not giving the correct permissions, it outputs an error saying the operation is not permitted:

❯ ./telegraf --config ~/Documents/Telegraf/telegraf.conf --test
2021-03-30T14:56:17Z I! Starting Telegraf 
2021-03-30T14:56:17Z E! [inputs.ping] ping failed: failed to run pinger: listen ip4:icmp : socket: operation not permitted
> ping,host=sspaink-influxdata,url=example.org result_code=2i 1617116178000000000
2021-03-30T14:56:17Z E! [telegraf] Error running agent: input plugins recorded 1 errors

Working example:

❯ sudo ./telegraf --config ~/Documents/Telegraf/telegraf.conf --test
2021-03-30T14:58:49Z I! Starting Telegraf 
> ping,host=sspaink-influxdata,url=example.org average_response_ms=13.390971,maximum_response_ms=13.390971,minimum_response_ms=13.390971,packets_received=1i,packets_transmitted=1i,percent_packet_loss=0,result_code=0i,standard_deviation_ms=0,ttl=56i 1617116330000000000

Copy link
Contributor

@telegraf-tiger telegraf-tiger bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤝 ✅ CLA has been signed. Thank you!

Copy link
Contributor

@telegraf-tiger telegraf-tiger bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@reimda reimda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi sspaink, I'd like to have telegraf give a more useful error message when the user doesn't have cap_net_raw set up yet. It will be hard especially for beginners to know that "ping failed: failed to run pinger: listen ip4:icmp : socket: operation not permitted" means they need to use run setcap on the telegraf binary.

Ideally the message should tell the user what they need to do to fix it, or at least point them to docs that tell them how to fix it. The more helpful the error message is, the fewer people will struggle to get this set up.

We would need to check the specific type of error on line 192 and return the helpful message, then let all other ping errors return the current generic "failed to run" message.

Copy link
Contributor

@telegraf-tiger telegraf-tiger bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@reimda reimda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sspaink sspaink merged commit 7d66590 into influxdata:master Mar 30, 2021
reimda pushed a commit that referenced this pull request Apr 7, 2021
* Always SetPrivileged(true)

* Improve error message

(cherry picked from commit 7d66590)
jblesener pushed a commit to jblesener/telegraf that referenced this pull request Apr 18, 2021
* Always SetPrivileged(true)

* Improve error message
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
* Always SetPrivileged(true)

* Improve error message

(cherry picked from commit 7d66590)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[[inputs.ping]] - FreeBSD 12.2 - method = "native" doesn't work with telegraf 1.17.2 and 1.17.3
3 participants