Skip to content

Commit 3d12856

Browse files
committed
make ssh_authorized_key world-readable when deployed as root
This is a rather bold and naive move to fix puppetlabs#92. It makes all authorized_keys generated by this module to be readonly when generated by root, so that Puppet can be used to deploy authorized_keys files that are not writable by the user, yet still usable for authentication. This is necessary because OpenSSH drops privileges before parsing authorized_keys. If a file is owned by root and mode `0600` (as right now), authentication fails. We keep the old `0600` mode for files managed by the user. For those, there's nothing we can do anyways: if the user owns the file, they can change the mode and rewrite the file anyways. A proper solution would probably be to hook into a File resource there that could be overriden properly. Fundamentally, the problem here is that we are managing multiple resources that hit the same actual file on disk: ideally, we'd have a mode parameter to the resource here, but then we could get into conflicts if multiple invocations of ssh_authorized_key use different mode parameters. Closes: puppetlabs#92
1 parent da321a4 commit 3d12856

File tree

1 file changed

+7
-3
lines changed
  • lib/puppet/provider/ssh_authorized_key

1 file changed

+7
-3
lines changed

lib/puppet/provider/ssh_authorized_key/parsed.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ def dir_perm
3838
0o700
3939
end
4040

41-
def file_perm
41+
def file_perm_readonly
42+
0o444
43+
end
44+
45+
def file_perm_writable
4246
0o600
4347
end
4448

@@ -84,7 +88,7 @@ def flush
8488
end
8589
super
8690

87-
File.chmod(file_perm, target)
91+
File.chmod(file_perm_writable, target)
8892
end
8993
# to avoid race conditions when handling permissions as a privileged user
9094
# (CVE-2011-3870) we use the trusted_path method to ensure the entire
@@ -97,7 +101,7 @@ def flush
97101
gid = Puppet::Util.gid(@resource.should(:user))
98102
File.open(target) do |target|
99103
target.chown(uid, gid)
100-
target.chmod(file_perm)
104+
target.chmod(file_perm_readonly)
101105
end
102106
end
103107
end

0 commit comments

Comments
 (0)