Closed jrandall closed 5 years ago
Chiming in here, I'm also seeing this issue. I read Seth Vargo's comment in #461 suggesting that consul-client respects file ownership. However, I am fairly certain it does not, as the above commenter has described.
I've just finished going through the code and it does not do anything to maintain ownership of existing files, though there is code to maintain the mode of an existing file.
It would be an easy fix to add code to renderer.go
to Chown the newly created file to the same uid and gid of the existing file, but using core go libraries finding the uid/gid is platform dependent. Should be pretty easy to do for all posix systems, but probably wouldn't do the right thing on windows. However, I think it would be an improvement to add this functionality even if it only works on some systems.
That said, if all we want to do is set ownership of a templated file to a particular user and group, a workaround to consul-template not being able to do that is just to include a call to chown
in the command
run when the template destination changes.
For example, the toy example given above could become:
template {
destination = "/tmp/munge.key"
contents = "test"
command = "chown munge:munge /tmp/munge.key"
}
What I've done for my real templates (which are running as non-root and also had an existing restart command) is something more like:
template {
destination = "/tmp/munge.key"
contents = "test"
command = "sudo bash -c 'chown munge:munge /tmp/munge.key && systemctl restart munge'"
}
@jrandall That would work, but the use case here is where consul-template is an unprivileged user.
Consul Template version
consul-template v0.19.4 (68b1da2)
Configuration
Command
Debug output
Expected behavior
The destination file should still be owned by user munge and group munge after consul-template runs.
Actual behavior
The ownership of the destination file is changed to root:root (in this case, since consul-template is run as root, but the destination file will be owned by whatever user and default group consul-template is run as).
Steps to reproduce
CAP_DAC_OVERRIDE
)References