]> git.openstreetmap.org Git - chef.git/blob - cookbooks/openssh/recipes/default.rb
Fix more rubocop detected style issues
[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   if node[:lsb][:release].to_f >= 14.04
28     provider Chef::Provider::Service::Upstart
29   end
30   action [ :enable, :start ]
31   supports :status => true, :restart => true, :reload => true
32 end
33
34 hosts = search(:node, "networking:interfaces").sort_by { |n| n[:hostname] }.collect do |node|
35   names = [ node[:hostname] ]
36
37   node.interfaces(:role => :external).each do |interface|
38     names |= [ "#{node[:hostname]}.openstreetmap.org" ]
39     names |= [ "#{node[:hostname]}.#{interface[:zone]}.openstreetmap.org" ]
40   end
41
42   unless node.interfaces(:role => :internal).empty?
43     names |= [ "#{node[:hostname]}.#{node[:networking][:roles][:external][:zone]}.openstreetmap.org" ]
44   end
45
46   keys = {
47     "rsa" => node[:keys][:ssh][:host_rsa_public],
48     "dsa" => node[:keys][:ssh][:host_dsa_public]
49   }
50
51   if node[:keys][:ssh][:host_ecdsa_public]
52     ecdsa_type = node[:keys][:ssh][:host_ecdsa_type]
53
54     keys[ecdsa_type] = node[:keys][:ssh][:host_ecdsa_public]
55   end
56
57   Hash[
58     :names => names.sort,
59     :addresses => node.ipaddresses.sort,
60     :keys => keys
61   ]
62 end
63
64 template "/etc/ssh/ssh_config" do
65   source "ssh_config.erb"
66   mode 0644
67   owner "root"
68   group "root"
69 end
70
71 template "/etc/ssh/ssh_known_hosts" do
72   source "ssh_known_hosts.erb"
73   mode 0444
74   owner "root"
75   group "root"
76   backup false
77   variables(
78     :hosts => hosts
79   )
80 end
81
82 firewall_rule "accept-ssh" do
83   action :accept
84   source "net"
85   dest "fw"
86   proto "tcp:syn"
87   dest_ports "ssh"
88 end