X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Fportforwarder%2Ftemplates%2Fauthorized_keys.erb;h=f7b56fcd7aa5db621e1fd410656118c253688d19;hb=d0c098685b92334a611a0c596a35f538b95ead47;hp=5cb76624d7181206b65cd01cdb705774eb2994ac;hpb=7fbd1fb63f9a8e87683b183e8b39bce18af59a4a;p=mirror%2Fdsa-puppet.git diff --git a/modules/portforwarder/templates/authorized_keys.erb b/modules/portforwarder/templates/authorized_keys.erb index 5cb76624d..f7b56fcd7 100644 --- a/modules/portforwarder/templates/authorized_keys.erb +++ b/modules/portforwarder/templates/authorized_keys.erb @@ -4,6 +4,13 @@ ## <%= + +require 'digest/sha1' +def get_local_ip_addr(host) + hash = Digest::SHA1.digest(host) + return '127.101.%d.%d'%[hash[0].ord, hash[1].ord] +end + def getportforwarderkey(host) key = nil begin @@ -23,21 +30,21 @@ config.each_pair do |sourcehost, services| ##lines << "# sourcehost is #{sourcehost}" services.each do |service| ##lines << "# targethost is #{service['target_host']}, my hostname #{hostname}, fqdn is #{fqdn}" - next if service['target_host'] != fqdn + next if service['target_host'] != @fqdn allowed_ports << service['target_port'] if service['target_port'] end if allowed_ports.length > 0 sshkey = getportforwarderkey(sourcehost) - remote_ip = allnodeinfo[sourcehost]['ipHostNumber'].join(',') - local_bind = '127.101.%d.%d'%[ (sourcehost.hash / 256 % 256), sourcehost.hash % 256 ] + remote_ip = scope.lookupvar('deprecated::allnodeinfo')[sourcehost]['ipHostNumber'].join(',') + local_bind = get_local_ip_addr(sourcehost) lines << "# from #{sourcehost}" if sshkey.nil? or remote_ip.nil? or local_bind.nil? lines << "# insufficient config values" else command = "/usr/bin/portforwarder-ssh-wrap #{sourcehost} #{local_bind} #{allowed_ports.join(' ')}" - lines << "from=\"#{remote_ip}\",command=\"#{command}\",no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding #{sshkey}" + lines << "from=\"#{remote_ip}\",command=\"#{command}\",restrict #{sshkey}" end end end