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

[feature]: Enable specifying user/group permissions in the template stanza #5020

Closed
danlsgiga opened this issue Dec 18, 2018 · 17 comments · Fixed by #13755
Closed

[feature]: Enable specifying user/group permissions in the template stanza #5020

danlsgiga opened this issue Dec 18, 2018 · 17 comments · Fixed by #13755

Comments

@danlsgiga
Copy link
Contributor

danlsgiga commented Dec 18, 2018

It would be great to have user and group parameters to the template stanza. This would allow us to trim down the perms of templates handling secrets to just the user/group of the user running in the container.

Use case: We have few jobs running the docker driver and we are injecting a few config files using the template stanza with secrets from Vault. Right now we have to set perms = 444 in order to allow the task to read the rendered template. From a security standpoint, this is not optimal since 444 allows anyone to read the file. So, being able to specify an user/group combination in the template stanza would make things simpler since Nomad always create the templates with user and group = root.

Having to do manual steps on a docker entrypoint script to achieve that is ugly IMO.

This is related to #2091

@preetapan
Copy link
Contributor

@danlsgiga could you not set perms=400 to restrict it to just the owner?

@danlsgiga
Copy link
Contributor Author

@preetapan not really! The template is created with user / group set to root and I run my container using nobody / nobody (best practices heh!). Setting perms = 400 (Tried that and didn't work) will make the file readable by root only.

@ccakes
Copy link

ccakes commented Sep 26, 2019

Another use case here is certain software (eg PostgreSQL) enforces certain permissions for files like TLS keys and being able to get things working under Nomad can be problematic.

Using the docker executor template files are written as root but in the container we don't know what user we're running as, although it probably shouldn't be root. Postgres enforces that key files are 0400 (or 0640) if owned by root so I've had to build a new image with postgres in the root group in make things work.

Adding simple options to set file ownership to uids would solve this

@peimanja
Copy link

peimanja commented Jan 9, 2020

Any update on this issue?

@tgross tgross added this to the unscheduled milestone Jan 10, 2020
@tgross
Copy link
Member

tgross commented Jan 10, 2020

Hi @peimanja. Sorry we don't have an update on this. I've made sure to put it onto our backlog for discussion though.

@AbhilashBalaji
Copy link

Hey , I would like to work on this issue , could someone give me any idea on where to start from ?

@AbhilashBalaji
Copy link

Would adding extra checks here make a feasible solution

@tgross tgross added this to Needs Roadmapping in Nomad - Community Issues Triage Feb 12, 2021
@tgross tgross removed this from the unscheduled milestone Feb 12, 2021
@mr-karan
Copy link
Contributor

mr-karan commented Feb 13, 2021

+1. Trying to deploy gitea and using template stanza to mount the config file. But it gets mounted as a root user. Since gitea is started with a non root user, it's effectively unable to read the file.

@tgross tgross removed this from Needs Roadmapping in Nomad - Community Issues Triage Mar 4, 2021
@johnalotoski
Copy link

Similar use case as above: Nomad postgres job being run in the exec driver as the nobody user, with SSL, pulling PKI certs via consul template from the vault PKI secrets path. All Nomad job files are created as nobody:nobody in the job except for the consul template files which are root:root. Postgres demands perms on the cert secret key file of 0600 (for non-root ownership) or 0640 (for root ownership) which is incompatible with the nobody:nobody user if ownership can't be changed. We can of course copy the secret key and change the ownership by script at the startup of the postgres job, but then when PKI certs expire and are auto-refreshed, the consul template change_mode can't just be SIGHUP, but a more disruptive full job restart to ensure that the scripted change of ownership happens to be able to read the newly rotated private key again.

Maybe there is a way to have the consul template files be written as the nobody:nobody user rather than root:root when the nomad jobs are being run as nobody:nobody?

@MagicRB
Copy link

MagicRB commented May 2, 2021

I'm trying to run HydraCI in a Nix built container, but HydraCI requires the pgpass file to be 600 or less, which means I have to change it's owner from root:root

@virtualshuric
Copy link

Another case for setting templated files ownership is running RabbitMQ containers as non-root user:

  1. RMQ requires, that Erlang cookie has permission of 0600 (or 0400).
  2. When running RMQ image as root user, entrypoint script simply chowns cookie-file to non-privileged rabbitmq user.
  3. When running RMQ as non-root - it either can't read cookie-file (because of root:root owner and 0600 permissions), either RMQ fails to start because permission set don't match (e.g. when cookie file permissions are 0644).

@keslerm
Copy link

keslerm commented Dec 1, 2021

Ran into needing this a bunch already and it makes things really troublesome to get going sometimes.

@3nprob
Copy link

3nprob commented Jan 27, 2022

Support for setting uid and guid just got merged to consul-template, expected for next release: hashicorp/consul-template#1531

So this should be pretty straightforward to implement for nomad as of now

@jrasell
Copy link
Member

jrasell commented Jan 27, 2022

Hi @3nprob and others. I have raised that internally and any updates will be posted as follow up comments.

@danlsgiga
Copy link
Contributor Author

And, here it is: https://github.com/hashicorp/consul-template/blob/master/CHANGELOG.md#v0280-mar-04-2022

@3nprob
Copy link

3nprob commented May 11, 2022

@jrasell Got any news for us now that the prerequisites are in place with 1.3? :)

@github-actions
Copy link

github-actions bot commented Dec 1, 2022

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.