UID/GID ownership of template output in NOMAD_SECRETS_DIR for Postgres

Looking at the code - it looks like it is supposed to be doing a check on whether or not the UID and GID match up with what is configured for both Nomad and consul-template. The whole render-path setup for Nomad looks to be directly through consul-template … which checks to see if the recorded render time is >= the stored render time. :person_shrugging:

Got it - yeah - it feels like it’d add a ton of complexity to handle it any other way.

For writeToFile the listed concern is that you have control to write freely on the filesystem. Would it be reasonable to add a restriction on writeToFile to honor the path sandbox that file reading does? Looking at things it seems like it’s a simple operation since the majority of the work is dealt with by the file utility.

I think the writeToFile solution will be what I adopt - I’ve used it for writing out PKI when I don’t have Nomad helping out (but the process owner being an unprivileged user and writeToFile not restricted). In the short-term, I’ll just live with the unlikely chance that something calls writeToFile in a way that breaks the sandbox.

So the plan I think will work right:

  • Set a template output to a file that has everything (keys, cert, ca…) w/ restrictive owner and not changing UID
  • Add writeToFile items in the template that write out the separate certificate and key files using the stored template data and sets the appropriate owner
  • Unlock the writeToFile capability in Nomad.
  • See about writing an pull-request for writeToFile honoring the sandbox.