]> git.openstreetmap.org Git - chef.git/blob - cookbooks/openssh/recipes/default.rb
geodns: set standard SOA retry
[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 service "ssh" do
27   action [:enable, :start]
28   supports :status => true, :restart => true, :reload => true
29 end
30
31 hosts = search(:node, "networking:interfaces").sort_by { |n| n[:hostname] }.collect do |node|
32   name = node.name.split(".").first
33
34   names = [name]
35
36   unless node.interfaces(:role => :internal).empty?
37     names.unshift("#{name}.#{node[:networking][:roles][:external][:zone]}.openstreetmap.org")
38   end
39
40   unless node.interfaces(:role => :external).empty?
41     names.unshift("#{name}.openstreetmap.org")
42   end
43
44   keys = {
45     "ssh-rsa" => node[:keys][:ssh][:host_rsa_public]
46   }
47
48   if node[:keys][:ssh][:host_ecdsa_public]
49     ecdsa_type = node[:keys][:ssh][:host_ecdsa_type]
50
51     keys[ecdsa_type] = node[:keys][:ssh][:host_ecdsa_public]
52   end
53
54   if node[:keys][:ssh][:host_ed25519_public]
55     keys["ssh-ed25519"] = node[:keys][:ssh][:host_ed25519_public]
56   end
57
58   Hash[
59     :names => names,
60     :addresses => node.ipaddresses.sort,
61     :keys => keys
62   ]
63 end
64
65 template "/etc/ssh/ssh_known_hosts" do
66   source "ssh_known_hosts.erb"
67   mode 0o444
68   owner "root"
69   group "root"
70   backup false
71   variables(
72     :hosts => hosts
73   )
74 end
75
76 firewall_rule "accept-ssh" do
77   action :accept
78   source "net"
79   dest "fw"
80   proto "tcp:syn"
81   dest_ports node[:openssh][:port]
82 end