diff options
| author | Markus Roberts <Markus@reality.com> | 2010-04-28 15:39:39 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | ae520057280c2454bc44c64ac1e6686bf2eb086d (patch) | |
| tree | 8769657cf9fc93664ba109ce0c562358e8f83d34 /lib | |
| parent | 8c5e80edd84ec1e2f8c594b74b57a1e48af92e87 (diff) | |
| download | puppet-ae520057280c2454bc44c64ac1e6686bf2eb086d.tar.gz puppet-ae520057280c2454bc44c64ac1e6686bf2eb086d.tar.xz puppet-ae520057280c2454bc44c64ac1e6686bf2eb086d.zip | |
Write ssh_authorized_keys as user
This is a targeted fix to the issue of permissions when writing ssh authorized
key files by 1) requiring that an existing users be specified on the resource
and 2) doing the write as that user. It's based on Michael DeHaan's initial
implementation of Luke's idea, but with a number of simplifications (mostly by
testing necessary conditions as early as possible so the code isn't cluttered
up with a lot of checks).
The tests in this version are modified slightly to remove some additional
implementation couplings that were added in master.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/provider/ssh_authorized_key/parsed.rb | 38 |
1 files changed, 9 insertions, 29 deletions
diff --git a/lib/puppet/provider/ssh_authorized_key/parsed.rb b/lib/puppet/provider/ssh_authorized_key/parsed.rb index 6265c6b7f..fb4d0956e 100644 --- a/lib/puppet/provider/ssh_authorized_key/parsed.rb +++ b/lib/puppet/provider/ssh_authorized_key/parsed.rb @@ -62,36 +62,16 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed, end def flush - # As path expansion had to be moved in the provider, we cannot generate new file - # resources and thus have to chown and chmod here. It smells hackish. - - # Create target's parent directory if nonexistant - if target - dir = File.dirname(target) - if not File.exist? dir - Puppet.debug("Creating directory %s which did not exist" % dir) - Dir.mkdir(dir, dir_perm) - end - end - - # Generate the file - super - - # Ensure correct permissions - if target and user - uid = Puppet::Util.uid(user) - - if uid - File.chown(uid, nil, dir) - File.chown(uid, nil, target) - else - raise Puppet::Error, "Specified user does not exist" - end - end - - if target and FileTest.exist?(target) - File.chmod(file_perm, target) + raise Puppet::Error, "Cannot write SSH authorized keys without user" unless user + raise Puppet::Error, "User '#{user}' does not exist" unless uid = Puppet::Util.uid(user) + unless File.exist?(dir = File.dirname(target)) + Puppet.debug "Creating #{dir}" + Dir.mkdir(dir, dir_perm) + File.chown(uid, nil, dir) end + Puppet::Util::SUIDManager.asuser(user) { super } + File.chown(uid, nil, target) + File.chmod(file_perm, target) end # parse sshv2 option strings, wich is a comma separated list of |
