saltstack/salt — pull request #483 by iamb (2012-01-11 04:22:07+00:00)
Title: Managed file races

Small race condition exists in the file state. Files are created and written out with default umask before ownership/modes are set. This makes a small window were a malicious local user could open a file they ought not be able.

This patch introduces two changes in salt/states/file.py, in the managed() function:

- for an existing file, just check/update and permissions first before copying contents into the existing file

- for a new file, create an empty file first using a restrictive umask if the mode will be set. then check/update ownership and permissions. finally, copy content into the file.