poolparty 1.3.4 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/Rakefile +2 -2
  2. data/VERSION.yml +1 -1
  3. data/bin/cloud-bootstrap +1 -0
  4. data/bin/cloud-configure +1 -0
  5. data/bin/cloud-contract +1 -0
  6. data/bin/cloud-misc +34 -0
  7. data/bin/cloud-setup +36 -0
  8. data/bin/cloud-ssh +4 -1
  9. data/config/jeweler.rb +4 -3
  10. data/examples/monitored_cloud.rb +1 -1
  11. data/examples/thrift/thrift_example.rb +5 -3
  12. data/examples/vmware.rb +28 -0
  13. data/lib/cloud_providers/cloud_provider_instance.rb +14 -5
  14. data/lib/cloud_providers/connections.rb +1 -1
  15. data/lib/core/file.rb +12 -0
  16. data/lib/core/object.rb +2 -2
  17. data/lib/dependency_resolvers/base.rb +1 -1
  18. data/lib/dependency_resolvers/chef.rb +9 -7
  19. data/lib/dependency_resolvers/proxy_object.rb +11 -3
  20. data/lib/mixins/askable.rb +16 -7
  21. data/lib/poolparty/base.rb +8 -7
  22. data/lib/poolparty/cloud.rb +77 -7
  23. data/lib/poolparty/default.rb +1 -0
  24. data/lib/poolparty/installer.rb +8 -4
  25. data/lib/poolparty/installers/ec2.rb +75 -5
  26. data/lib/poolparty/installers/vmware.rb +17 -5
  27. data/lib/poolparty/plugin.rb +1 -5
  28. data/lib/poolparty/plugins/apache.rb +10 -7
  29. data/lib/poolparty/plugins/apache2/base.conf.erb +2 -2
  30. data/lib/poolparty/plugins/apache2/browser_fixes.conf.erb +1 -1
  31. data/lib/poolparty/plugins/apache2/passenger_site.rb +2 -2
  32. data/lib/poolparty/plugins/collectd/templates/collectd.conf.erb +369 -0
  33. data/lib/poolparty/plugins/collectd.rb +24 -0
  34. data/lib/poolparty/plugins/hermes.rb +89 -0
  35. data/lib/poolparty/pool.rb +33 -3
  36. data/lib/poolparty/resource.rb +32 -18
  37. data/lib/poolparty/resources/directory.rb +5 -1
  38. data/lib/poolparty/resources/exec.rb +2 -2
  39. data/lib/poolparty/resources/file.rb +8 -2
  40. data/lib/poolparty/resources/gem_package.rb +2 -2
  41. data/lib/poolparty/resources/line.rb +23 -6
  42. data/lib/poolparty/resources/mount.rb +2 -2
  43. data/lib/poolparty/resources/package.rb +2 -2
  44. data/lib/poolparty/resources/service.rb +2 -2
  45. data/lib/poolparty/resources/user.rb +2 -2
  46. data/lib/poolparty/resources/variable.rb +4 -3
  47. data/lib/poolparty.rb +5 -3
  48. data/lib/proto/command_interface_handler.rb +17 -1
  49. data/lib/proto/gen-py/cloudthrift/CommandInterface.pyc +0 -0
  50. data/lib/proto/gen-py/cloudthrift/__init__.pyc +0 -0
  51. data/lib/proto/gen-py/cloudthrift/constants.pyc +0 -0
  52. data/lib/proto/gen-py/cloudthrift/ttypes.pyc +0 -0
  53. data/lib/proto/gen-py/thrift/Thrift.pyc +0 -0
  54. data/lib/proto/gen-py/thrift/__init__.pyc +0 -0
  55. data/lib/proto/gen-py/thrift/protocol/TBinaryProtocol.pyc +0 -0
  56. data/lib/proto/gen-py/thrift/protocol/TProtocol.pyc +0 -0
  57. data/lib/proto/gen-py/thrift/protocol/__init__.pyc +0 -0
  58. data/lib/proto/gen-py/thrift/transport/TSocket.pyc +0 -0
  59. data/lib/proto/gen-py/thrift/transport/TTransport.pyc +0 -0
  60. data/lib/proto/gen-py/thrift/transport/__init__.pyc +0 -0
  61. data/test/lib/dependency_resolvers/chef_test.rb +92 -100
  62. data/test/lib/poolparty/base_test.rb +13 -0
  63. data/test/lib/poolparty/cloud_test.rb +50 -2
  64. data/test/lib/poolparty/monitor_test.rb +2 -2
  65. data/test/lib/poolparty/resource_test.rb +5 -0
  66. data/test/lib/poolparty/resources/line_test.rb +3 -3
  67. data/test/lib/poolparty/resources/service_test.rb +1 -1
  68. data/test/lib/poolparty/resources/variable_test.rb +33 -10
  69. data/vendor/gems/net-ssh/CHANGELOG.rdoc +127 -0
  70. data/vendor/gems/net-ssh/Manifest +104 -0
  71. data/vendor/gems/net-ssh/README.rdoc +110 -0
  72. data/vendor/gems/net-ssh/Rakefile +26 -0
  73. data/vendor/gems/net-ssh/THANKS.rdoc +16 -0
  74. data/vendor/gems/net-ssh/lib/net/ssh/authentication/agent.rb +176 -0
  75. data/vendor/gems/net-ssh/lib/net/ssh/authentication/constants.rb +18 -0
  76. data/vendor/gems/net-ssh/lib/net/ssh/authentication/key_manager.rb +193 -0
  77. data/vendor/gems/net-ssh/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  78. data/vendor/gems/net-ssh/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
  79. data/vendor/gems/net-ssh/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
  80. data/vendor/gems/net-ssh/lib/net/ssh/authentication/methods/password.rb +39 -0
  81. data/vendor/gems/net-ssh/lib/net/ssh/authentication/methods/publickey.rb +92 -0
  82. data/vendor/gems/net-ssh/lib/net/ssh/authentication/pageant.rb +183 -0
  83. data/vendor/gems/net-ssh/lib/net/ssh/authentication/session.rb +134 -0
  84. data/vendor/gems/net-ssh/lib/net/ssh/buffer.rb +340 -0
  85. data/vendor/gems/net-ssh/lib/net/ssh/buffered_io.rb +149 -0
  86. data/vendor/gems/net-ssh/lib/net/ssh/config.rb +181 -0
  87. data/vendor/gems/net-ssh/lib/net/ssh/connection/channel.rb +625 -0
  88. data/vendor/gems/net-ssh/lib/net/ssh/connection/constants.rb +33 -0
  89. data/vendor/gems/net-ssh/lib/net/ssh/connection/session.rb +596 -0
  90. data/vendor/gems/net-ssh/lib/net/ssh/connection/term.rb +178 -0
  91. data/vendor/gems/net-ssh/lib/net/ssh/errors.rb +85 -0
  92. data/vendor/gems/net-ssh/lib/net/ssh/key_factory.rb +102 -0
  93. data/vendor/gems/net-ssh/lib/net/ssh/known_hosts.rb +129 -0
  94. data/vendor/gems/net-ssh/lib/net/ssh/loggable.rb +61 -0
  95. data/vendor/gems/net-ssh/lib/net/ssh/packet.rb +102 -0
  96. data/vendor/gems/net-ssh/lib/net/ssh/prompt.rb +93 -0
  97. data/vendor/gems/net-ssh/lib/net/ssh/proxy/errors.rb +14 -0
  98. data/vendor/gems/net-ssh/lib/net/ssh/proxy/http.rb +94 -0
  99. data/vendor/gems/net-ssh/lib/net/ssh/proxy/socks4.rb +70 -0
  100. data/vendor/gems/net-ssh/lib/net/ssh/proxy/socks5.rb +129 -0
  101. data/vendor/gems/net-ssh/lib/net/ssh/ruby_compat.rb +7 -0
  102. data/vendor/gems/net-ssh/lib/net/ssh/service/forward.rb +267 -0
  103. data/vendor/gems/net-ssh/lib/net/ssh/test/channel.rb +129 -0
  104. data/vendor/gems/net-ssh/lib/net/ssh/test/extensions.rb +152 -0
  105. data/vendor/gems/net-ssh/lib/net/ssh/test/kex.rb +44 -0
  106. data/vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb +51 -0
  107. data/vendor/gems/net-ssh/lib/net/ssh/test/packet.rb +81 -0
  108. data/vendor/gems/net-ssh/lib/net/ssh/test/remote_packet.rb +38 -0
  109. data/vendor/gems/net-ssh/lib/net/ssh/test/script.rb +157 -0
  110. data/vendor/gems/net-ssh/lib/net/ssh/test/socket.rb +59 -0
  111. data/vendor/gems/net-ssh/lib/net/ssh/test.rb +89 -0
  112. data/vendor/gems/net-ssh/lib/net/ssh/transport/algorithms.rb +384 -0
  113. data/vendor/gems/net-ssh/lib/net/ssh/transport/cipher_factory.rb +80 -0
  114. data/vendor/gems/net-ssh/lib/net/ssh/transport/constants.rb +30 -0
  115. data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/abstract.rb +78 -0
  116. data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/md5.rb +12 -0
  117. data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  118. data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/none.rb +15 -0
  119. data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  120. data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  121. data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac.rb +31 -0
  122. data/vendor/gems/net-ssh/lib/net/ssh/transport/identity_cipher.rb +55 -0
  123. data/vendor/gems/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  124. data/vendor/gems/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  125. data/vendor/gems/net-ssh/lib/net/ssh/transport/kex.rb +13 -0
  126. data/vendor/gems/net-ssh/lib/net/ssh/transport/openssl.rb +128 -0
  127. data/vendor/gems/net-ssh/lib/net/ssh/transport/packet_stream.rb +230 -0
  128. data/vendor/gems/net-ssh/lib/net/ssh/transport/server_version.rb +60 -0
  129. data/vendor/gems/net-ssh/lib/net/ssh/transport/session.rb +276 -0
  130. data/vendor/gems/net-ssh/lib/net/ssh/transport/state.rb +201 -0
  131. data/vendor/gems/net-ssh/lib/net/ssh/verifiers/lenient.rb +30 -0
  132. data/vendor/gems/net-ssh/lib/net/ssh/verifiers/null.rb +12 -0
  133. data/vendor/gems/net-ssh/lib/net/ssh/verifiers/strict.rb +53 -0
  134. data/vendor/gems/net-ssh/lib/net/ssh/version.rb +62 -0
  135. data/vendor/gems/net-ssh/lib/net/ssh.rb +215 -0
  136. data/vendor/gems/net-ssh/net-ssh.gemspec +33 -0
  137. data/vendor/gems/net-ssh/setup.rb +1585 -0
  138. data/vendor/gems/net-ssh/test/authentication/methods/common.rb +28 -0
  139. data/vendor/gems/net-ssh/test/authentication/methods/test_abstract.rb +51 -0
  140. data/vendor/gems/net-ssh/test/authentication/methods/test_hostbased.rb +114 -0
  141. data/vendor/gems/net-ssh/test/authentication/methods/test_keyboard_interactive.rb +98 -0
  142. data/vendor/gems/net-ssh/test/authentication/methods/test_password.rb +50 -0
  143. data/vendor/gems/net-ssh/test/authentication/methods/test_publickey.rb +127 -0
  144. data/vendor/gems/net-ssh/test/authentication/test_agent.rb +205 -0
  145. data/vendor/gems/net-ssh/test/authentication/test_key_manager.rb +105 -0
  146. data/vendor/gems/net-ssh/test/authentication/test_session.rb +93 -0
  147. data/vendor/gems/net-ssh/test/common.rb +106 -0
  148. data/vendor/gems/net-ssh/test/configs/eqsign +3 -0
  149. data/vendor/gems/net-ssh/test/configs/exact_match +8 -0
  150. data/vendor/gems/net-ssh/test/configs/wild_cards +14 -0
  151. data/vendor/gems/net-ssh/test/connection/test_channel.rb +452 -0
  152. data/vendor/gems/net-ssh/test/connection/test_session.rb +488 -0
  153. data/vendor/gems/net-ssh/test/test_all.rb +6 -0
  154. data/vendor/gems/net-ssh/test/test_buffer.rb +336 -0
  155. data/vendor/gems/net-ssh/test/test_buffered_io.rb +63 -0
  156. data/vendor/gems/net-ssh/test/test_config.rb +84 -0
  157. data/vendor/gems/net-ssh/test/test_key_factory.rb +67 -0
  158. data/vendor/gems/net-ssh/test/transport/hmac/test_md5.rb +39 -0
  159. data/vendor/gems/net-ssh/test/transport/hmac/test_md5_96.rb +25 -0
  160. data/vendor/gems/net-ssh/test/transport/hmac/test_none.rb +34 -0
  161. data/vendor/gems/net-ssh/test/transport/hmac/test_sha1.rb +34 -0
  162. data/vendor/gems/net-ssh/test/transport/hmac/test_sha1_96.rb +25 -0
  163. data/vendor/gems/net-ssh/test/transport/kex/test_diffie_hellman_group1_sha1.rb +146 -0
  164. data/vendor/gems/net-ssh/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +92 -0
  165. data/vendor/gems/net-ssh/test/transport/test_algorithms.rb +302 -0
  166. data/vendor/gems/net-ssh/test/transport/test_cipher_factory.rb +171 -0
  167. data/vendor/gems/net-ssh/test/transport/test_hmac.rb +34 -0
  168. data/vendor/gems/net-ssh/test/transport/test_identity_cipher.rb +40 -0
  169. data/vendor/gems/net-ssh/test/transport/test_packet_stream.rb +435 -0
  170. data/vendor/gems/net-ssh/test/transport/test_server_version.rb +57 -0
  171. data/vendor/gems/net-ssh/test/transport/test_session.rb +315 -0
  172. data/vendor/gems/net-ssh/test/transport/test_state.rb +173 -0
  173. metadata +116 -4
  174. data/bin/install-poolparty +0 -20
@@ -0,0 +1,110 @@
1
+ = Net::SSH
2
+
3
+ * http://net-ssh.rubyforge.org/ssh
4
+
5
+ == DESCRIPTION:
6
+
7
+ Net::SSH is a pure-Ruby implementation of the SSH2 client protocol. It allows you to write programs that invoke and interact with processes on remote servers, via SSH2.
8
+
9
+ == FEATURES:
10
+
11
+ * Execute processes on remote servers and capture their output
12
+ * Run multiple processes in parallel over a single SSH connection
13
+ * Support for SSH subsystems
14
+ * Forward local and remote ports via an SSH connection
15
+
16
+ == SYNOPSIS:
17
+
18
+ In a nutshell:
19
+
20
+ require 'net/ssh'
21
+
22
+ Net::SSH.start('host', 'user', :password => "password") do |ssh|
23
+ # capture all stderr and stdout output from a remote process
24
+ output = ssh.exec!("hostname")
25
+
26
+ # capture only stdout matching a particular pattern
27
+ stdout = ""
28
+ ssh.exec!("ls -l /home/jamis") do |channel, stream, data|
29
+ stdout << data if stream == :stdout
30
+ end
31
+ puts stdout
32
+
33
+ # run multiple processes in parallel to completion
34
+ ssh.exec "sed ..."
35
+ ssh.exec "awk ..."
36
+ ssh.exec "rm -rf ..."
37
+ ssh.loop
38
+
39
+ # open a new channel and configure a minimal set of callbacks, then run
40
+ # the event loop until the channel finishes (closes)
41
+ channel = ssh.open_channel do |ch|
42
+ ch.exec "/usr/local/bin/ruby /path/to/file.rb" do |ch, success|
43
+ raise "could not execute command" unless success
44
+
45
+ # "on_data" is called when the process writes something to stdout
46
+ ch.on_data do |c, data|
47
+ $STDOUT.print data
48
+ end
49
+
50
+ # "on_extended_data" is called when the process writes something to stderr
51
+ ch.on_extended_data do |c, type, data|
52
+ $STDERR.print data
53
+ end
54
+
55
+ ch.on_close { puts "done!" }
56
+ end
57
+ end
58
+
59
+ channel.wait
60
+
61
+ # forward connections on local port 1234 to port 80 of www.capify.org
62
+ ssh.forward.local(1234, "www.capify.org", 80)
63
+ ssh.loop { true }
64
+ end
65
+
66
+ See Net::SSH for more documentation, and links to further information.
67
+
68
+ == REQUIREMENTS:
69
+
70
+ The only requirement you might be missing is the OpenSSL bindings for Ruby. These are built by default on most platforms, but you can verify that they're built and installed on your system by running the following command line:
71
+
72
+ ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
73
+
74
+ If that spits out something like "OpenSSL 0.9.8g 19 Oct 2007", then you're set. If you get an error, then you'll need to see about rebuilding ruby with OpenSSL support, or (if your platform supports it) installing the OpenSSL bindings separately.
75
+
76
+ Additionally: if you are going to be having Net::SSH prompt you for things like passwords or certificate passphrases, you'll want to have either the Highline (recommended) or Termios (unix systems only) gem installed, so that the passwords don't echo in clear text.
77
+
78
+ Lastly, if you want to run the tests or use any of the Rake tasks, you'll need:
79
+
80
+ * Echoe (for the Rakefile)
81
+ * Mocha (for the tests)
82
+
83
+ == INSTALL:
84
+
85
+ * gem install net-ssh (might need sudo privileges)
86
+
87
+ == LICENSE:
88
+
89
+ (The MIT License)
90
+
91
+ Copyright (c) 2008 Jamis Buck <jamis@37signals.com>
92
+
93
+ Permission is hereby granted, free of charge, to any person obtaining
94
+ a copy of this software and associated documentation files (the
95
+ 'Software'), to deal in the Software without restriction, including
96
+ without limitation the rights to use, copy, modify, merge, publish,
97
+ distribute, sublicense, and/or sell copies of the Software, and to
98
+ permit persons to whom the Software is furnished to do so, subject to
99
+ the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be
102
+ included in all copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
105
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
106
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
107
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
108
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
109
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
110
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ require './lib/net/ssh/version'
2
+
3
+ begin
4
+ require 'echoe'
5
+ rescue LoadError
6
+ abort "You'll need to have `echoe' installed to use Net::SSH's Rakefile"
7
+ end
8
+
9
+ version = Net::SSH::Version::STRING.dup
10
+ if ENV['SNAPSHOT'].to_i == 1
11
+ version << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
12
+ end
13
+
14
+ Echoe.new('net-ssh', version) do |p|
15
+ p.changelog = "CHANGELOG.rdoc"
16
+
17
+ p.author = "Jamis Buck"
18
+ p.email = "jamis@jamisbuck.org"
19
+ p.summary = "a pure-Ruby implementation of the SSH2 client protocol"
20
+ p.url = "http://net-ssh.rubyforge.org/ssh"
21
+
22
+ p.need_zip = true
23
+ p.include_rakefile = true
24
+
25
+ p.rdoc_pattern = /^(lib|README.rdoc|CHANGELOG.rdoc|THANKS.rdoc)/
26
+ end
@@ -0,0 +1,16 @@
1
+ Net::SSH was originally written by Jamis Buck <jamis@37signals.com>. In
2
+ addition, the following individuals are gratefully acknowledged for their
3
+ contributions:
4
+
5
+ GOTOU Yuuzou <gotoyuzo@notwork.org>
6
+ * help and code related to OpenSSL
7
+
8
+ Guillaume Mar�ais <guillaume.marcais@free.fr>
9
+ * support for communicating with the the PuTTY "pageant" process
10
+
11
+ Daniel Berger <djberg96@yahoo.com>
12
+ * help getting unit tests in earlier Net::SSH versions to pass in Windows
13
+ * initial version of Net::SSH::Config provided inspiration and encouragement
14
+
15
+ Chris Andrews <chris@nodnol.org> and Lee Jensen <lee@outerim.com>
16
+ * support for ssh agent forwarding
@@ -0,0 +1,176 @@
1
+ require 'net/ssh/buffer'
2
+ require 'net/ssh/errors'
3
+ require 'net/ssh/loggable'
4
+ require 'net/ssh/transport/server_version'
5
+
6
+ require 'net/ssh/authentication/pageant' if File::ALT_SEPARATOR && !(RUBY_PLATFORM =~ /java/)
7
+
8
+ module Net; module SSH; module Authentication
9
+
10
+ # A trivial exception class for representing agent-specific errors.
11
+ class AgentError < Net::SSH::Exception; end
12
+
13
+ # An exception for indicating that the SSH agent is not available.
14
+ class AgentNotAvailable < AgentError; end
15
+
16
+ # This class implements a simple client for the ssh-agent protocol. It
17
+ # does not implement any specific protocol, but instead copies the
18
+ # behavior of the ssh-agent functions in the OpenSSH library (3.8).
19
+ #
20
+ # This means that although it behaves like a SSH1 client, it also has
21
+ # some SSH2 functionality (like signing data).
22
+ class Agent
23
+ include Loggable
24
+
25
+ # A simple module for extending keys, to allow comments to be specified
26
+ # for them.
27
+ module Comment
28
+ attr_accessor :comment
29
+ end
30
+
31
+ SSH2_AGENT_REQUEST_VERSION = 1
32
+ SSH2_AGENT_REQUEST_IDENTITIES = 11
33
+ SSH2_AGENT_IDENTITIES_ANSWER = 12
34
+ SSH2_AGENT_SIGN_REQUEST = 13
35
+ SSH2_AGENT_SIGN_RESPONSE = 14
36
+ SSH2_AGENT_FAILURE = 30
37
+ SSH2_AGENT_VERSION_RESPONSE = 103
38
+
39
+ SSH_COM_AGENT2_FAILURE = 102
40
+
41
+ SSH_AGENT_REQUEST_RSA_IDENTITIES = 1
42
+ SSH_AGENT_RSA_IDENTITIES_ANSWER1 = 2
43
+ SSH_AGENT_RSA_IDENTITIES_ANSWER2 = 5
44
+ SSH_AGENT_FAILURE = 5
45
+
46
+ # The underlying socket being used to communicate with the SSH agent.
47
+ attr_reader :socket
48
+
49
+ # Instantiates a new agent object, connects to a running SSH agent,
50
+ # negotiates the agent protocol version, and returns the agent object.
51
+ def self.connect(logger=nil)
52
+ agent = new(logger)
53
+ agent.connect!
54
+ agent.negotiate!
55
+ agent
56
+ end
57
+
58
+ # Creates a new Agent object, using the optional logger instance to
59
+ # report status.
60
+ def initialize(logger=nil)
61
+ self.logger = logger
62
+ end
63
+
64
+ # Connect to the agent process using the socket factory and socket name
65
+ # given by the attribute writers. If the agent on the other end of the
66
+ # socket reports that it is an SSH2-compatible agent, this will fail
67
+ # (it only supports the ssh-agent distributed by OpenSSH).
68
+ def connect!
69
+ begin
70
+ debug { "connecting to ssh-agent" }
71
+ @socket = agent_socket_factory.open(ENV['SSH_AUTH_SOCK'])
72
+ rescue
73
+ error { "could not connect to ssh-agent" }
74
+ raise AgentNotAvailable, $!.message
75
+ end
76
+ end
77
+
78
+ # Attempts to negotiate the SSH agent protocol version. Raises an error
79
+ # if the version could not be negotiated successfully.
80
+ def negotiate!
81
+ # determine what type of agent we're communicating with
82
+ type, body = send_and_wait(SSH2_AGENT_REQUEST_VERSION, :string, Transport::ServerVersion::PROTO_VERSION)
83
+
84
+ if type == SSH2_AGENT_VERSION_RESPONSE
85
+ raise NotImplementedError, "SSH2 agents are not yet supported"
86
+ elsif type != SSH_AGENT_RSA_IDENTITIES_ANSWER1 && type != SSH_AGENT_RSA_IDENTITIES_ANSWER2
87
+ raise AgentError, "unknown response from agent: #{type}, #{body.to_s.inspect}"
88
+ end
89
+ end
90
+
91
+ # Return an array of all identities (public keys) known to the agent.
92
+ # Each key returned is augmented with a +comment+ property which is set
93
+ # to the comment returned by the agent for that key.
94
+ def identities
95
+ type, body = send_and_wait(SSH2_AGENT_REQUEST_IDENTITIES)
96
+ raise AgentError, "could not get identity count" if agent_failed(type)
97
+ raise AgentError, "bad authentication reply: #{type}" if type != SSH2_AGENT_IDENTITIES_ANSWER
98
+
99
+ identities = []
100
+ body.read_long.times do
101
+ key = Buffer.new(body.read_string).read_key
102
+ key.extend(Comment)
103
+ key.comment = body.read_string
104
+ identities.push key
105
+ end
106
+
107
+ return identities
108
+ end
109
+
110
+ # Closes this socket. This agent reference is no longer able to
111
+ # query the agent.
112
+ def close
113
+ @socket.close
114
+ end
115
+
116
+ # Using the agent and the given public key, sign the given data. The
117
+ # signature is returned in SSH2 format.
118
+ def sign(key, data)
119
+ type, reply = send_and_wait(SSH2_AGENT_SIGN_REQUEST, :string, Buffer.from(:key, key), :string, data, :long, 0)
120
+
121
+ if agent_failed(type)
122
+ raise AgentError, "agent could not sign data with requested identity"
123
+ elsif type != SSH2_AGENT_SIGN_RESPONSE
124
+ raise AgentError, "bad authentication response #{type}"
125
+ end
126
+
127
+ return reply.read_string
128
+ end
129
+
130
+ private
131
+
132
+ # Returns the agent socket factory to use.
133
+ def agent_socket_factory
134
+ if File::ALT_SEPARATOR
135
+ Pageant::Socket
136
+ else
137
+ UNIXSocket
138
+ end
139
+ end
140
+
141
+ # Send a new packet of the given type, with the associated data.
142
+ def send_packet(type, *args)
143
+ buffer = Buffer.from(*args)
144
+ data = [buffer.length + 1, type.to_i, buffer.to_s].pack("NCA*")
145
+ debug { "sending agent request #{type} len #{buffer.length}" }
146
+ @socket.send data, 0
147
+ end
148
+
149
+ # Read the next packet from the agent. This will return a two-part
150
+ # tuple consisting of the packet type, and the packet's body (which
151
+ # is returned as a Net::SSH::Buffer).
152
+ def read_packet
153
+ buffer = Net::SSH::Buffer.new(@socket.read(4))
154
+ buffer.append(@socket.read(buffer.read_long))
155
+ type = buffer.read_byte
156
+ debug { "received agent packet #{type} len #{buffer.length-4}" }
157
+ return type, buffer
158
+ end
159
+
160
+ # Send the given packet and return the subsequent reply from the agent.
161
+ # (See #send_packet and #read_packet).
162
+ def send_and_wait(type, *args)
163
+ send_packet(type, *args)
164
+ read_packet
165
+ end
166
+
167
+ # Returns +true+ if the parameter indicates a "failure" response from
168
+ # the agent, and +false+ otherwise.
169
+ def agent_failed(type)
170
+ type == SSH_AGENT_FAILURE ||
171
+ type == SSH2_AGENT_FAILURE ||
172
+ type == SSH_COM_AGENT2_FAILURE
173
+ end
174
+ end
175
+
176
+ end; end; end
@@ -0,0 +1,18 @@
1
+ module Net; module SSH; module Authentication
2
+
3
+ # Describes the constants used by the Net::SSH::Authentication components
4
+ # of the Net::SSH library. Individual authentication method implemenations
5
+ # may define yet more constants that are specific to their implementation.
6
+ module Constants
7
+ USERAUTH_REQUEST = 50
8
+ USERAUTH_FAILURE = 51
9
+ USERAUTH_SUCCESS = 52
10
+ USERAUTH_BANNER = 53
11
+
12
+ USERAUTH_PASSWD_CHANGEREQ = 60
13
+ USERAUTH_PK_OK = 60
14
+
15
+ USERAUTH_METHOD_RANGE = 60..79
16
+ end
17
+
18
+ end; end; end
@@ -0,0 +1,193 @@
1
+ require 'net/ssh/errors'
2
+ require 'net/ssh/key_factory'
3
+ require 'net/ssh/loggable'
4
+ require 'net/ssh/authentication/agent'
5
+
6
+ module Net
7
+ module SSH
8
+ module Authentication
9
+
10
+ # A trivial exception class used to report errors in the key manager.
11
+ class KeyManagerError < Net::SSH::Exception; end
12
+
13
+ # This class encapsulates all operations done by clients on a user's
14
+ # private keys. In practice, the client should never need a reference
15
+ # to a private key; instead, they grab a list of "identities" (public
16
+ # keys) that are available from the KeyManager, and then use
17
+ # the KeyManager to do various private key operations using those
18
+ # identities.
19
+ #
20
+ # The KeyManager also uses the Agent class to encapsulate the
21
+ # ssh-agent. Thus, from a client's perspective it is completely
22
+ # hidden whether an identity comes from the ssh-agent or from a file
23
+ # on disk.
24
+ class KeyManager
25
+ include Loggable
26
+
27
+ # The list of user key files that will be examined
28
+ attr_reader :key_files
29
+
30
+ # The list of user key data that will be examined
31
+ attr_reader :key_data
32
+
33
+ # The map of loaded identities
34
+ attr_reader :known_identities
35
+
36
+ # The map of options that were passed to the key-manager
37
+ attr_reader :options
38
+
39
+ # Create a new KeyManager. By default, the manager will
40
+ # use the ssh-agent (if it is running).
41
+ def initialize(logger, options={})
42
+ self.logger = logger
43
+ @key_files = []
44
+ @key_data = []
45
+ @use_agent = true
46
+ @known_identities = {}
47
+ @agent = nil
48
+ @options = options
49
+ end
50
+
51
+ # Clear all knowledge of any loaded user keys. This also clears the list
52
+ # of default identity files that are to be loaded, thus making it
53
+ # appropriate to use if a client wishes to NOT use the default identity
54
+ # files.
55
+ def clear!
56
+ key_files.clear
57
+ key_data.clear
58
+ known_identities.clear
59
+ self
60
+ end
61
+
62
+ # Add the given key_file to the list of key files that will be used.
63
+ def add(key_file)
64
+ key_files.push(File.expand_path(key_file)).uniq!
65
+ self
66
+ end
67
+
68
+ # Add the given key_file to the list of keys that will be used.
69
+ def add_key_data(key_data_)
70
+ key_data.push(key_data_).uniq!
71
+ self
72
+ end
73
+
74
+ # This is used as a hint to the KeyManager indicating that the agent
75
+ # connection is no longer needed. Any other open resources may be closed
76
+ # at this time.
77
+ #
78
+ # Calling this does NOT indicate that the KeyManager will no longer
79
+ # be used. Identities may still be requested and operations done on
80
+ # loaded identities, in which case, the agent will be automatically
81
+ # reconnected. This method simply allows the client connection to be
82
+ # closed when it will not be used in the immediate future.
83
+ def finish
84
+ @agent.close if @agent
85
+ @agent = nil
86
+ end
87
+
88
+ # Iterates over all available identities (public keys) known to this
89
+ # manager. As it finds one, it will then yield it to the caller.
90
+ # The origin of the identities may be from files on disk or from an
91
+ # ssh-agent. Note that identities from an ssh-agent are always listed
92
+ # first in the array, with other identities coming after.
93
+ def each_identity
94
+ if agent
95
+ agent.identities.each do |key|
96
+ known_identities[key] = { :from => :agent }
97
+ yield key
98
+ end
99
+ end
100
+
101
+ key_files.each do |file|
102
+ public_key_file = file + ".pub"
103
+ if File.readable?(public_key_file)
104
+ begin
105
+ key = KeyFactory.load_public_key(public_key_file)
106
+ known_identities[key] = { :from => :file, :file => file }
107
+ yield key
108
+ rescue Exception => e
109
+ error { "could not load public key file `#{public_key_file}': #{e.class} (#{e.message})" }
110
+ end
111
+ elsif File.readable?(file)
112
+ begin
113
+ private_key = KeyFactory.load_private_key(file, options[:passphrase])
114
+ key = private_key.send(:public_key)
115
+ known_identities[key] = { :from => :file, :file => file, :key => private_key }
116
+ yield key
117
+ rescue Exception => e
118
+ error { "could not load private key file `#{file}': #{e.class} (#{e.message})" }
119
+ end
120
+ end
121
+ end
122
+
123
+ key_data.each do |data|
124
+ private_key = KeyFactory.load_data_private_key(data)
125
+ key = private_key.send(:public_key)
126
+ known_identities[key] = { :from => :key_data, :data => data, :key => private_key }
127
+ yield key
128
+ end
129
+
130
+ self
131
+ end
132
+
133
+ # Sign the given data, using the corresponding private key of the given
134
+ # identity. If the identity was originally obtained from an ssh-agent,
135
+ # then the ssh-agent will be used to sign the data, otherwise the
136
+ # private key for the identity will be loaded from disk (if it hasn't
137
+ # been loaded already) and will then be used to sign the data.
138
+ #
139
+ # Regardless of the identity's origin or who does the signing, this
140
+ # will always return the signature in an SSH2-specified "signature
141
+ # blob" format.
142
+ def sign(identity, data)
143
+ info = known_identities[identity] or raise KeyManagerError, "the given identity is unknown to the key manager"
144
+
145
+ if info[:key].nil? && info[:from] == :file
146
+ begin
147
+ info[:key] = KeyFactory.load_private_key(info[:file], options[:passphrase])
148
+ rescue Exception => e
149
+ raise KeyManagerError, "the given identity is known, but the private key could not be loaded: #{e.class} (#{e.message})"
150
+ end
151
+ end
152
+
153
+ if info[:key]
154
+ return Net::SSH::Buffer.from(:string, identity.ssh_type,
155
+ :string, info[:key].ssh_do_sign(data.to_s)).to_s
156
+ end
157
+
158
+ if info[:from] == :agent
159
+ raise KeyManagerError, "the agent is no longer available" unless agent
160
+ return agent.sign(identity, data.to_s)
161
+ end
162
+
163
+ raise KeyManagerError, "[BUG] can't determine identity origin (#{info.inspect})"
164
+ end
165
+
166
+ # Identifies whether the ssh-agent will be used or not.
167
+ def use_agent?
168
+ @use_agent
169
+ end
170
+
171
+ # Toggles whether the ssh-agent will be used or not. If true, an
172
+ # attempt will be made to use the ssh-agent. If false, any existing
173
+ # connection to an agent is closed and the agent will not be used.
174
+ def use_agent=(use_agent)
175
+ finish if !use_agent
176
+ @use_agent = use_agent
177
+ end
178
+
179
+ # Returns an Agent instance to use for communicating with an SSH
180
+ # agent process. Returns nil if use of an SSH agent has been disabled,
181
+ # or if the agent is otherwise not available.
182
+ def agent
183
+ return unless use_agent?
184
+ @agent ||= Agent.connect(logger)
185
+ rescue AgentNotAvailable
186
+ @use_agent = false
187
+ nil
188
+ end
189
+ end
190
+
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,60 @@
1
+ require 'net/ssh/buffer'
2
+ require 'net/ssh/errors'
3
+ require 'net/ssh/loggable'
4
+ require 'net/ssh/authentication/constants'
5
+
6
+ module Net; module SSH; module Authentication; module Methods
7
+
8
+ # The base class of all user authentication methods. It provides a few
9
+ # bits of common functionality.
10
+ class Abstract
11
+ include Constants, Loggable
12
+
13
+ # The authentication session object
14
+ attr_reader :session
15
+
16
+ # The key manager object. Not all authentication methods will require
17
+ # this.
18
+ attr_reader :key_manager
19
+
20
+ # Instantiates a new authentication method.
21
+ def initialize(session, options={})
22
+ @session = session
23
+ @key_manager = options[:key_manager]
24
+ @options = options
25
+ self.logger = session.logger
26
+ end
27
+
28
+ # Returns the session-id, as generated during the first key exchange of
29
+ # an SSH connection.
30
+ def session_id
31
+ session.transport.algorithms.session_id
32
+ end
33
+
34
+ # Sends a message via the underlying transport layer abstraction. This
35
+ # will block until the message is completely sent.
36
+ def send_message(msg)
37
+ session.transport.send_message(msg)
38
+ end
39
+
40
+ # Creates a new USERAUTH_REQUEST packet. The extra arguments on the end
41
+ # must be either boolean values or strings, and are tacked onto the end
42
+ # of the packet. The new packet is returned, ready for sending.
43
+ def userauth_request(username, next_service, auth_method, *others)
44
+ buffer = Net::SSH::Buffer.from(:byte, USERAUTH_REQUEST,
45
+ :string, username, :string, next_service, :string, auth_method)
46
+
47
+ others.each do |value|
48
+ case value
49
+ when true, false then buffer.write_bool(value)
50
+ when String then buffer.write_string(value)
51
+ else raise ArgumentError, "don't know how to write #{value.inspect}"
52
+ end
53
+ end
54
+
55
+ buffer
56
+ end
57
+
58
+ end
59
+
60
+ end; end; end; end
@@ -0,0 +1,71 @@
1
+ require 'net/ssh/authentication/methods/abstract'
2
+
3
+ module Net
4
+ module SSH
5
+ module Authentication
6
+ module Methods
7
+
8
+ # Implements the host-based SSH authentication method.
9
+ class Hostbased < Abstract
10
+ include Constants
11
+
12
+ # Attempts to perform host-based authorization of the user by trying
13
+ # all known keys.
14
+ def authenticate(next_service, username, password=nil)
15
+ return false unless key_manager
16
+
17
+ key_manager.each_identity do |identity|
18
+ return true if authenticate_with(identity, next_service,
19
+ username, key_manager)
20
+ end
21
+
22
+ return false
23
+ end
24
+
25
+ private
26
+
27
+ # Returns the hostname as reported by the underlying socket.
28
+ def hostname
29
+ session.transport.socket.client_name
30
+ end
31
+
32
+ # Attempts to perform host-based authentication of the user, using
33
+ # the given host identity (key).
34
+ def authenticate_with(identity, next_service, username, key_manager)
35
+ debug { "trying hostbased (#{identity.fingerprint})" }
36
+ client_username = ENV['USER'] || username
37
+
38
+ req = build_request(identity, next_service, username, "#{hostname}.", client_username)
39
+ sig_data = Buffer.from(:string, session_id, :raw, req)
40
+
41
+ sig = key_manager.sign(identity, sig_data.to_s)
42
+
43
+ message = Buffer.from(:raw, req, :string, sig)
44
+
45
+ send_message(message)
46
+ message = session.next_message
47
+
48
+ case message.type
49
+ when USERAUTH_SUCCESS
50
+ info { "hostbased succeeded (#{identity.fingerprint})" }
51
+ return true
52
+ when USERAUTH_FAILURE
53
+ info { "hostbased failed (#{identity.fingerprint})" }
54
+ return false
55
+ else
56
+ raise Net::SSH::Exception, "unexpected server response to USERAUTH_REQUEST: #{message.type} (#{message.inspect})"
57
+ end
58
+ end
59
+
60
+ # Build the "core" hostbased request string.
61
+ def build_request(identity, next_service, username, hostname, client_username)
62
+ userauth_request(username, next_service, "hostbased", identity.ssh_type,
63
+ Buffer.from(:key, identity).to_s, hostname, client_username).to_s
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
70
+ end
71
+ end