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

Support for setting file ownership #461

Closed
blalor opened this issue Nov 12, 2015 · 8 comments
Closed

Support for setting file ownership #461

blalor opened this issue Nov 12, 2015 · 8 comments

Comments

@blalor
Copy link

blalor commented Nov 12, 2015

The issue of setting file permissions was Initially brought up in #358 and resolved in #415, but #358 also mentioned setting the ownership of a file. Obviously that's only possible when running as root, but I have a case where I need to do exactly this. Is there a reason that support wasn't added?

@sethvargo
Copy link
Contributor

Hi @blalor

The problem is that the os.Chown accepts the gid and uid, which are the integer representations of the user id and group id. So you have to make a low-level system call to convert a human username into a uid, but that will fail if the user doesn't exist, and it requires a bunch of OS-specific switch calls to make the right syscalls under the hood, especially with Windows. I would recommend just using chown as part of the script, since you'll know more about the OS that you're running on.

@darron
Copy link

darron commented Nov 23, 2015

I also don't believe there's currently a cross platform way to figure out the gid by passing a group name as a string until Go 2.0 - unless I've missed it.

On Linux you could parse the /etc/group file - but 'ew.

@sethvargo
Copy link
Contributor

Closing due to lack of response and technical limitations.

@babbottscott
Copy link

Would using the os/user package (https://golang.org/pkg/os/user/) when available be workable?

@SunSparc
Copy link

SunSparc commented Feb 6, 2017

Might be nice to at least mention something about it in the docs. Perhaps even suggest some options, such as:

  • touch the file with correct ownership before handing it to consul-template
  • use the "command" option in the template config to run "chown" on the file

@siepkes
Copy link

siepkes commented Jul 3, 2017

@SunSparc I don't see how the option: "touch the file with correct ownership before handing it to consul-template" works? Because as soon as Consul template updates the file it will change the permissions to its own UID and GID. It seems Consul template doesn't update the file; It deletes it and creates it.

@SunSparc
Copy link

SunSparc commented Jul 3, 2017

@siepkes I just double-checked and you are correct. And that is really just a side note anyway. The point of my comment was that it would really be nice if this was addressed in the documentation.

@sethvargo
Copy link
Contributor

Hi all,

Consul template preserves the file ownership if the existing file is there. It also supports specifying file permissions in the configuration via the 'perms' argument. Are you seeing different behavior? If so, could you please open a new issue and complete the issue template that pops up? This is a very old issue and a lot has changed in CT since it was created. It would be very helpful to have configuration and debug output to try and reproduce this. Thanks!

@hashicorp hashicorp locked and limited conversation to collaborators Jul 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants