-
-
Notifications
You must be signed in to change notification settings - Fork 671
fix(client): update icmp/ping logic to determine pinger privileged mode #1346
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
Changes from all commits
f6485a5
b7ef582
0bccd44
34c6cbe
a749fe3
e8bd811
761e745
f8a58af
2b7cfa5
95f6a6c
54e261e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import ( | |
| "net" | ||
| "net/http" | ||
| "net/smtp" | ||
| "os" | ||
| "runtime" | ||
| "strings" | ||
| "time" | ||
|
|
@@ -343,12 +344,7 @@ func Ping(address string, config *Config) (bool, time.Duration) { | |
| pinger := ping.New(address) | ||
| pinger.Count = 1 | ||
| pinger.Timeout = config.Timeout | ||
| // Set the pinger's privileged mode to true for every GOOS except darwin | ||
| // See https://github.com/TwiN/gatus/issues/132 | ||
| // | ||
| // Note that for this to work on Linux, Gatus must run with sudo privileges. | ||
| // See https://github.com/prometheus-community/pro-bing#linux | ||
| pinger.SetPrivileged(runtime.GOOS != "darwin") | ||
| pinger.SetPrivileged(ShouldRunPingerAsPrivileged()) | ||
| pinger.SetNetwork(config.Network) | ||
| err := pinger.Run() | ||
| if err != nil { | ||
|
|
@@ -364,6 +360,25 @@ func Ping(address string, config *Config) (bool, time.Duration) { | |
| return true, 0 | ||
| } | ||
|
|
||
| // ShouldRunPingerAsPrivileged will determine whether or not to run pinger in privileged mode. | ||
| // It should be set to privileged when running as root, and always on windows. See https://pkg.go.dev/github.com/macrat/go-parallel-pinger#Pinger.SetPrivileged | ||
| func ShouldRunPingerAsPrivileged() bool { | ||
| // Set the pinger's privileged mode to false for darwin | ||
| // See https://github.com/TwiN/gatus/issues/132 | ||
| // linux should also be set to false, but there are potential complications | ||
| // See https://github.com/TwiN/gatus/pull/748 and https://github.com/TwiN/gatus/issues/697#issuecomment-2081700989 | ||
| // | ||
| // Note that for this to work on Linux, Gatus must run with sudo privileges. (in certain cases) | ||
| // See https://github.com/prometheus-community/pro-bing#linux | ||
| if runtime.GOOS == "windows" { | ||
| return true | ||
| } | ||
| // To actually check for cap_net_raw capabilities, we would need to add "kernel.org/pub/linux/libs/security/libcap/cap" to gatus. | ||
| // Or use a syscall and check for permission errors, but this requires platform specific compilation | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it architecture or os specific implementations?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The low level libraries needed for creating a raw socket on POSIX systems require C-linking. This project currently builds with CGO not enabled, and I am reluctant to make changes that would impact the build process as this will introduce some additional complexity around building for multiple systems and thus increase the scope. If you have suggestions that don't require CGO, I'm open to trying them out. |
||
| // As a backstop we can simply check the effective user id and run as privileged when running as root | ||
| return os.Geteuid() == 0 | ||
|
Comment on lines
+378
to
+379
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ok with giving this a try in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If using as a custom user ID with cap net raw, it should be running as privileged to work. I'd be curious if anyone is running it as unprivileged with CAP_NET_RAW and have it be working. I'm happy to work on something more thorough, but it will likely involve some sort of libc linking requirement unless I figure out a different approach. |
||
| } | ||
|
|
||
| // QueryWebSocket opens a websocket connection, write `body` and return a message from the server | ||
| func QueryWebSocket(address, body string, headers map[string]string, config *Config) (bool, []byte, error) { | ||
| const ( | ||
|
|
||
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.
I'm no expert in Darwin, is it guaranteed that
will always return
falseon Darwin? Otherwise this should be added as a special case here.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.
If someone is running this as root on darwin, then they'd want the Privileged mode as per my understanding.