-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Adding Varnish sudo rules for unprivileged users #3097
Conversation
What about adding the telegraf user to the varnish group? This would be preferable to using sudo, so if this works then we should just add something to the documentation suggesting it. |
Since some of these files are owned by root, changing the group wouldn't help much (unless a chown was done). facl's do work, but managing extended acl's recursively on any of our varnish boxes seems like a bit of a hack compared to granting sudo rights to telegraf. I'm actually a bit surprised other users haven't run into this issue before.
I noticed that one of the varnish unit tests failed. I'm looking into whats going on there now and will update once that's sorted. |
Here is my varnish directory on debian stretch. This a clean install, I haven't configured anything, but all the files you have that are owned by root are using the varnish group on my system:
|
Ok, this could be a RHEL or package version thing. Just installed the base 4.1.3-1.el7 rpm on my RHEL7 desktop and I'm still seeing group ownership as root. Is there any harm in making this sudo option available in the telegraf config? The code sets the flag as off by default, so it will only be executed if a user passes the flag. Personally, I would rather have the telegraf user execute this via sudo then altering groups or facl's. Thanks, |
plugins/inputs/varnish/varnish.go
Outdated
@@ -32,6 +33,9 @@ var defaultStats = []string{"MAIN.cache_hit", "MAIN.cache_miss", "MAIN.uptime"} | |||
var defaultBinary = "/usr/bin/varnishstat" | |||
|
|||
var sampleConfig = ` | |||
## If running as a restricted user you can prepend sudo for additional access: | |||
sudo = true |
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.
Lets call it use_sudo
to match the fail2ban plugin. Indent the line only 2 spaces, set it to false (since that's default), and comment it out with a single hash (because it is not required).
## If running as a restricted user you can prepend sudo for additional access:
# sudo = false
In the plugin README we should add a paragraph that discusses permissions and recommends adding the telegraf user to the varnish group over using sudo. It should show how to give the telegraf user password-less sudo access to the varnishstat binary.
plugins/inputs/varnish/varnish.go
Outdated
|
||
if useSudo { | ||
cmdArgs = append([]string{cmdName}, cmdArgs...) | ||
cmd = exec.Command("/bin/sudo", cmdArgs...) |
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.
Use the sudo found in path, on my system sudo is /usr/bin/sudo
, also I think we ought to run sudo with the -n
flag.
Thanks @danielnelson, updated per your request! Let me know if there is anything else you want updated. |
plugins/inputs/varnish/README.md
Outdated
[[inputs.varnish]] | ||
use_sudo = true | ||
|
||
$ echo "telegraf ALL = NOPASSWD: /usr/bin/varnishstat" >>/etc/sudoers |
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.
We should recommend using visudo to edit the sudoers file, also minor thing but I'd prefer the runas spec:
telegraf ALL=(ALL) NOPASSWD: /usr/bin/varnishstat
plugins/inputs/varnish/README.md
Outdated
It's important to note that this plugin references varnishstat, which may require additional permissions to execute successfully. | ||
Depending on the user/group permissions of the telegraf user executing this plugin, you may need to alter the group membership, set facls, or use sudo. | ||
|
||
**Group membership**: |
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 think we should recommend this method.
plugins/inputs/varnish/README.md
Outdated
@@ -7,6 +7,9 @@ This plugin gathers stats from [Varnish HTTP Cache](https://varnish-cache.org/) | |||
```toml | |||
# A plugin to collect stats from Varnish HTTP Cache | |||
[[inputs.varnish]] | |||
## If running as a restricted user you can prepend sudo for additional access: | |||
#use_sudo = false |
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.
Indention still needs worked out here, 2 spaces
plugins/inputs/varnish/varnish.go
Outdated
@@ -32,6 +33,9 @@ var defaultStats = []string{"MAIN.cache_hit", "MAIN.cache_miss", "MAIN.uptime"} | |||
var defaultBinary = "/usr/bin/varnishstat" | |||
|
|||
var sampleConfig = ` | |||
## If running as a restricted user you can prepend sudo for additional access: | |||
#use_sudo = false |
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.
Also need indention here, 2 spaces. Test with telegraf --usage varnish
@danielnelson Updated with your feedback and fixed the spacing issue
|
It looks like ci/circleci failed, but not on anything related to this PR:
|
Required for all PRs:
Varnishstat requires read access to the underlying varnish libs at /var/lib/varnish. Since some users don't run telegraf as root we either need to setfacls on this directory or enable sudo to execute this command (default is false).
Looking back in history a bit, it seems sudo is the preferred method:
https://www.varnish-cache.org/lists/pipermail/varnish-misc/2011-November/021426.html
sudo = false
sudo = true