HomePhorge

(#12462) user_role_add: use `replace_file` for /etc/shadow
8461203aa7ebUnpublished

Unpublished Commit ยท Learn More

Repository Importing: This repository is still importing.

Description

(#12462) user_role_add: use replace_file for /etc/shadow

The user_role_add provider for user management previously open-coded the safe,
atomic replacement of /etc/shadow after in modified it.

Mostly even safely, except that it didn't enforce permissions on the temporary
file, so might have spilled data to third parties, if tempfile isn't
sufficiently secure. (Ruby makes no promises about tempfile mode.)

We replace that with the standard, central replace_file API, which ensures
that is done in a safe, correct, and standard fashion.

On the way through this removes the window where this could previously have
lost the content of /etc/shadow due to an unfortunately timed crash, by
ensuring we fsync the content of the temporary file.

It also documents, but doesn't eliminate, the lack of locking and other races
around this update to the shadow file.

Finally, some minor code and test updates to make it easier to test this on
fake data, rather than like on your own /etc/shadow file...

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>

Details

Provenance
Daniel Pittman <daniel@puppetlabs.com>Authored on
Nick Lewis <nick@puppetlabs.com>Committed on Feb 13 2012, 8:52 PM
vanmeeuwenPushed on Jun 2 2015, 2:22 PM
Parents
rPU0ad532a4b26e: (#12463) add secure `replace_file` to Puppet::Util
Branches
Unknown
Tags
Unknown

Event Timeline

Nick Lewis <nick@puppetlabs.com> committed rPU8461203aa7eb: (#12462) user_role_add: use `replace_file` for /etc/shadow (authored by Daniel Pittman <daniel@puppetlabs.com>).Feb 13 2012, 8:52 PM