]> git.openstreetmap.org Git - chef.git/blob - cookbooks/openssh/recipes/default.rb
nominatim: fix rights for restricted IP log
[chef.git] / cookbooks / openssh / recipes / default.rb
1 #
2 # Cookbook Name:: 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 #     http://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   names = [node[:hostname]]
33
34   node.interfaces(:role => :external).each do |interface|
35     names |= ["#{node[:hostname]}.openstreetmap.org"]
36     names |= ["#{node[:hostname]}.#{interface[:zone]}.openstreetmap.org"]
37   end
38
39   unless node.interfaces(:role => :internal).empty?
40     names |= ["#{node[:hostname]}.#{node[:networking][:roles][:external][:zone]}.openstreetmap.org"]
41   end
42
43   keys = {
44     "rsa" => node[:keys][:ssh][:host_rsa_public],            # ~FC039
45     "dsa" => node[:keys][:ssh][:host_dsa_public]             # ~FC039
46   }
47
48   if node[:keys][:ssh][:host_ecdsa_public]                   # ~FC039
49     ecdsa_type = node[:keys][:ssh][:host_ecdsa_type]         # ~FC039
50
51     keys[ecdsa_type] = node[:keys][:ssh][:host_ecdsa_public] # ~FC039
52   end
53
54   Hash[
55     :names => names.sort,
56     :addresses => node.ipaddresses.sort,
57     :keys => keys
58   ]
59 end
60
61 template "/etc/ssh/ssh_config" do
62   source "ssh_config.erb"
63   mode 0o644
64   owner "root"
65   group "root"
66 end
67
68 template "/etc/ssh/ssh_known_hosts" do
69   source "ssh_known_hosts.erb"
70   mode 0o444
71   owner "root"
72   group "root"
73   backup false
74   variables(
75     :hosts => hosts
76   )
77 end
78
79 firewall_rule "accept-ssh" do
80   action :accept
81   source "net"
82   dest "fw"
83   proto "tcp:syn"
84   dest_ports "ssh"
85 end