diff --git a/lib/puppet/provider/sshkey/parsed.rb b/lib/puppet/provider/sshkey/parsed.rb index f874683b7..29f345916 100644 --- a/lib/puppet/provider/sshkey/parsed.rb +++ b/lib/puppet/provider/sshkey/parsed.rb @@ -1,35 +1,40 @@ require 'puppet/provider/parsedfile' known = nil case Facter.value(:operatingsystem) when "Darwin"; known = "/etc/ssh_known_hosts" else known = "/etc/ssh/ssh_known_hosts" end Puppet::Type.type(:sshkey).provide( :parsed, :parent => Puppet::Provider::ParsedFile, :default_target => known, :filetype => :flat ) do desc "Parse and generate host-wide known hosts files for SSH." text_line :comment, :match => /^#/ text_line :blank, :match => /^\s+/ record_line :parsed, :fields => %w{name type key}, :post_parse => proc { |hash| names = hash[:name].split(",", -1) hash[:name] = names.shift hash[:host_aliases] = names }, :pre_gen => proc { |hash| if hash[:host_aliases] hash[:name] = [hash[:name], hash[:host_aliases]].flatten.join(",") hash.delete(:host_aliases) end } + + # Make sure to use mode 644 if ssh_known_hosts is newly created + def self.default_mode + 0644 + end end diff --git a/spec/integration/type/sshkey_spec.rb b/spec/integration/type/sshkey_spec.rb new file mode 100644 index 000000000..d1b1e01c7 --- /dev/null +++ b/spec/integration/type/sshkey_spec.rb @@ -0,0 +1,22 @@ +#! /usr/bin/env ruby +require 'spec_helper' +require 'puppet_spec/files' +require 'puppet_spec/compiler' + +describe Puppet::Type.type(:sshkey), '(integration)', :unless => Puppet.features.microsoft_windows? do + include PuppetSpec::Files + include PuppetSpec::Compiler + + let(:target) { tmpfile('ssh_known_hosts') } + let(:manifest) { "sshkey { 'test': + ensure => 'present', + type => 'rsa', + key => 'TESTKEY', + target => '#{target}' }" + } + + it "should create a new known_hosts file with mode 0644" do + apply_compiled_manifest(manifest) + expect_file_mode(target, "644") + end +end