]> git.openstreetmap.org Git - chef.git/blob - cookbooks/openssh/recipes/default.rb
blogs: fix build in test
[chef.git] / cookbooks / openssh / recipes / default.rb
1 #
2 # Cookbook:: openssh
3 # Recipe:: default
4 #
5 # Copyright:: 2010, OpenStreetMap Foundation.
6 # Copyright:: 2008-2009, Opscode, Inc.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     https://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 include_recipe "networking"
22
23 package "openssh-client"
24 package "openssh-server"
25
26 template "/etc/ssh/sshd_config.d/chef.conf" do
27   source "sshd_config.conf.erb"
28   owner "root"
29   group "root"
30   mode "644"
31   notifies :restart, "service[ssh]"
32   only_if { Dir.exist?("/etc/ssh/sshd_config.d") }
33 end
34
35 service "ssh" do
36   action [:enable, :start]
37   supports :status => true, :restart => true, :reload => true
38 end
39
40 hosts = search(:node, "networking:interfaces").sort_by { |n| n[:hostname] }.collect do |node|
41   name = node.name.split(".").first
42
43   names = [name]
44
45   unless node.interfaces(:role => :internal).empty?
46     names.unshift("#{name}.#{node[:networking][:roles][:external][:zone]}.openstreetmap.org")
47   end
48
49   unless node.interfaces(:role => :external).empty?
50     names.unshift("#{name}.openstreetmap.org")
51   end
52
53   keys = {
54     "ssh-rsa" => node[:keys][:ssh][:host_rsa_public]
55   }
56
57   if node[:keys][:ssh][:host_ecdsa_public]
58     ecdsa_type = node[:keys][:ssh][:host_ecdsa_type]
59
60     keys[ecdsa_type] = node[:keys][:ssh][:host_ecdsa_public]
61   end
62
63   if node[:keys][:ssh][:host_ed25519_public]
64     keys["ssh-ed25519"] = node[:keys][:ssh][:host_ed25519_public]
65   end
66
67   Hash[
68     :names => names,
69     :addresses => node.ipaddresses.sort,
70     :keys => keys
71   ]
72 end
73
74 template "/etc/ssh/ssh_known_hosts" do
75   source "ssh_known_hosts.erb"
76   mode "444"
77   owner "root"
78   group "root"
79   backup false
80   variables(
81     :hosts => hosts
82   )
83 end
84
85 firewall_rule "accept-ssh" do
86   action :accept
87   context :incoming
88   protocol :tcp
89   dest_ports node[:openssh][:port]
90 end