]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/portforwarder/templates/authorized_keys.erb
massive style guide fixups
[dsa-puppet.git] / modules / portforwarder / templates / authorized_keys.erb
1 ##
2 ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
3 ## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
4 ##
5
6 <%=
7 def getportforwarderkey(host)
8         key = nil
9         begin
10                 facts = YAML.load(File.open("/var/lib/puppet/yaml/facts/#{host}.yaml").read)
11                 return facts.values['portforwarder_key']
12         rescue Exception => e
13         end
14         return key
15 end
16
17
18 lines = []
19 config = YAML.load(File.open('/etc/puppet/modules/portforwarder/misc/config.yaml').read)
20 config.each_pair do |sourcehost, services|
21         allowed_ports = []
22
23         ##lines << "# sourcehost is #{sourcehost}"
24         services.each do |service|
25                 ##lines << "# targethost is #{service['target_host']}, my hostname #{hostname}, fqdn is #{fqdn}"
26                 next if service['target_host'] != fqdn
27                 allowed_ports << service['target_port'] if service['target_port']
28         end
29
30         if allowed_ports.length > 0
31                 sshkey = getportforwarderkey(sourcehost)
32                 remote_ip = scope.lookupvar('site::allnodeinfo')[sourcehost]['ipHostNumber'].join(',')
33                 local_bind = '127.101.%d.%d'%[ (sourcehost.hash / 256 % 256), sourcehost.hash % 256 ]
34
35                 lines << "# from #{sourcehost}"
36                 if sshkey.nil? or remote_ip.nil? or local_bind.nil?
37                         lines << "# insufficient config values"
38                 else
39                         command = "/usr/bin/portforwarder-ssh-wrap #{sourcehost} #{local_bind} #{allowed_ports.join(' ')}"
40                         lines << "from=\"#{remote_ip}\",command=\"#{command}\",no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding #{sshkey}"
41                 end
42         end
43 end
44 lines.join("\n")
45 %>