2

I have a service running on a linux box, started with upstart, that runs as user "the_user", it has to read a config file. Having the file owned by root would make things more secure, but would prevent the service reading the file.

I know that nginx can read a private cert file owned by root while running as a non root user.

I read about the approach or sourcing a script that sets sensitive environment variables read from a root owned file, and then launching the service process as the service user, which then "inherits" from the environment variables.

What is the best approach ?

  • I don't see how that would make things secure, if the user account for the service is unique and only that user has read access to its config file, it's as safe as if root was owning it (if the service itself is compromised I don't see why you would need to protect its config, as its contents would already be loaded in the service's memory and can be extracted that way). – user42178 Apr 1 '15 at 16:18
  • André, I see your point, I was assuming it is harder for an attacker to "become" root than to become a non root user, but this assumption is only founded on an impression (the impression that if nginx does it this way then...)... – Max L. Apr 1 '15 at 16:45
2

Im unsure if this is the "correct" approach, but I would change the permissions of the file to owned by root but also owned by another group which only has read access. Making sure your upstart user is in this shared group.

# groupadd upstart
# usermod -G upstart the_user
# chown root:upstart the_file.conf
# chmod 740 the_file.conf

The above adds a new group "upstart" at which point user "the_user" is added. The file ownership is changed to user "root" group "upstart" and permissions set to "root" read, write, execute; and group "upstart" read.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.