leap_cli 1.8.1 → 1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/leap +6 -12
- data/lib/leap_cli.rb +3 -23
- data/lib/leap_cli/bootstrap.rb +36 -12
- data/lib/leap_cli/commands/common.rb +88 -46
- data/lib/leap_cli/commands/new.rb +24 -17
- data/lib/leap_cli/commands/pre.rb +3 -1
- data/lib/leap_cli/core_ext/hash.rb +19 -0
- data/lib/leap_cli/leapfile.rb +47 -32
- data/lib/leap_cli/log.rb +196 -88
- data/lib/leap_cli/path.rb +5 -5
- data/lib/leap_cli/util.rb +28 -18
- data/lib/leap_cli/version.rb +8 -3
- data/vendor/acme-client/lib/acme-client.rb +1 -0
- data/vendor/acme-client/lib/acme/client.rb +122 -0
- data/vendor/acme-client/lib/acme/client/certificate.rb +30 -0
- data/vendor/acme-client/lib/acme/client/certificate_request.rb +111 -0
- data/vendor/acme-client/lib/acme/client/crypto.rb +98 -0
- data/vendor/acme-client/lib/acme/client/error.rb +16 -0
- data/vendor/acme-client/lib/acme/client/faraday_middleware.rb +123 -0
- data/vendor/acme-client/lib/acme/client/resources.rb +5 -0
- data/vendor/acme-client/lib/acme/client/resources/authorization.rb +44 -0
- data/vendor/acme-client/lib/acme/client/resources/challenges.rb +6 -0
- data/vendor/acme-client/lib/acme/client/resources/challenges/base.rb +43 -0
- data/vendor/acme-client/lib/acme/client/resources/challenges/dns01.rb +19 -0
- data/vendor/acme-client/lib/acme/client/resources/challenges/http01.rb +18 -0
- data/vendor/acme-client/lib/acme/client/resources/challenges/tls_sni01.rb +24 -0
- data/vendor/acme-client/lib/acme/client/resources/registration.rb +37 -0
- data/vendor/acme-client/lib/acme/client/self_sign_certificate.rb +60 -0
- data/vendor/acme-client/lib/acme/client/version.rb +7 -0
- data/vendor/base32/lib/base32.rb +67 -0
- data/vendor/certificate_authority/lib/certificate_authority.rb +2 -1
- data/vendor/certificate_authority/lib/certificate_authority/certificate.rb +4 -4
- data/vendor/certificate_authority/lib/certificate_authority/certificate_revocation_list.rb +7 -5
- data/vendor/certificate_authority/lib/certificate_authority/core_extensions.rb +46 -0
- data/vendor/certificate_authority/lib/certificate_authority/distinguished_name.rb +6 -2
- data/vendor/certificate_authority/lib/certificate_authority/extensions.rb +10 -3
- data/vendor/certificate_authority/lib/certificate_authority/key_material.rb +11 -9
- data/vendor/certificate_authority/lib/certificate_authority/ocsp_handler.rb +3 -3
- data/vendor/certificate_authority/lib/certificate_authority/pkcs11_key_material.rb +0 -2
- data/vendor/certificate_authority/lib/certificate_authority/serial_number.rb +8 -2
- data/vendor/certificate_authority/lib/certificate_authority/validations.rb +31 -0
- data/vendor/rsync_command/lib/rsync_command.rb +49 -12
- metadata +50 -91
- data/lib/leap/platform.rb +0 -90
- data/lib/leap_cli/config/environment.rb +0 -180
- data/lib/leap_cli/config/filter.rb +0 -178
- data/lib/leap_cli/config/manager.rb +0 -419
- data/lib/leap_cli/config/node.rb +0 -77
- data/lib/leap_cli/config/object.rb +0 -428
- data/lib/leap_cli/config/object_list.rb +0 -209
- data/lib/leap_cli/config/provider.rb +0 -22
- data/lib/leap_cli/config/secrets.rb +0 -87
- data/lib/leap_cli/config/sources.rb +0 -11
- data/lib/leap_cli/config/tag.rb +0 -25
- data/lib/leap_cli/lib_ext/capistrano_connections.rb +0 -16
- data/lib/leap_cli/logger.rb +0 -237
- data/lib/leap_cli/remote/leap_plugin.rb +0 -192
- data/lib/leap_cli/remote/puppet_plugin.rb +0 -26
- data/lib/leap_cli/remote/rsync_plugin.rb +0 -35
- data/lib/leap_cli/remote/tasks.rb +0 -51
- data/lib/leap_cli/ssh_key.rb +0 -195
- data/lib/leap_cli/util/remote_command.rb +0 -158
- data/lib/leap_cli/util/secret.rb +0 -55
- data/lib/leap_cli/util/x509.rb +0 -33
@@ -1,158 +0,0 @@
|
|
1
|
-
module LeapCli; module Util; module RemoteCommand
|
2
|
-
extend self
|
3
|
-
|
4
|
-
#
|
5
|
-
# FYI
|
6
|
-
# Capistrano::Logger::IMPORTANT = 0
|
7
|
-
# Capistrano::Logger::INFO = 1
|
8
|
-
# Capistrano::Logger::DEBUG = 2
|
9
|
-
# Capistrano::Logger::TRACE = 3
|
10
|
-
#
|
11
|
-
def ssh_connect(nodes, options={}, &block)
|
12
|
-
options ||= {}
|
13
|
-
node_list = parse_node_list(nodes)
|
14
|
-
|
15
|
-
cap = new_capistrano
|
16
|
-
cap.logger = LeapCli::Logger.new(:level => [LeapCli.log_level,3].min)
|
17
|
-
user = options[:user] || 'root'
|
18
|
-
cap.set :user, user
|
19
|
-
cap.set :ssh_options, ssh_options # ssh options common to all nodes
|
20
|
-
cap.set :use_sudo, false # we may want to change this in the future
|
21
|
-
|
22
|
-
# Allow password authentication when we are bootstraping a single node
|
23
|
-
# (and key authentication fails).
|
24
|
-
if options[:bootstrap] && node_list.size == 1
|
25
|
-
hostname = node_list.values.first.name
|
26
|
-
if options[:echo]
|
27
|
-
cap.set(:password) { ask "Root SSH password for #{user}@#{hostname}> " }
|
28
|
-
else
|
29
|
-
cap.set(:password) { Capistrano::CLI.password_prompt " * Typed password will be hidden (use --echo to make it visible)\nRoot SSH password for #{user}@#{hostname}> " }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
node_list.each do |name, node|
|
34
|
-
cap.server node.domain.full, :dummy_arg, node_options(node, options[:ssh_options])
|
35
|
-
end
|
36
|
-
|
37
|
-
yield cap
|
38
|
-
rescue Capistrano::ConnectionError => exc
|
39
|
-
# not sure if this will work if english is not the locale??
|
40
|
-
if exc.message =~ /Too many authentication failures/
|
41
|
-
at_exit {ssh_config_help_message}
|
42
|
-
end
|
43
|
-
raise exc
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
#
|
49
|
-
# For available options, see http://net-ssh.github.com/net-ssh/classes/Net/SSH.html#method-c-start
|
50
|
-
#
|
51
|
-
# Capistrano has some very evil behavior in it's ssh.rb:
|
52
|
-
#
|
53
|
-
# ssh_options = Net::SSH.configuration_for(
|
54
|
-
# server.host, ssh_options.fetch(:config, true)
|
55
|
-
# ).merge(ssh_options)
|
56
|
-
# # Once we've loaded the config, we don't need Net::SSH to do it again.
|
57
|
-
# ssh_options[:config] = false
|
58
|
-
#
|
59
|
-
# Net:SSH is supposed to call Net::SSH.configuration_for, but Capistrano is doing it
|
60
|
-
# in advance and then disabling loading of configs.
|
61
|
-
#
|
62
|
-
# The result of this is the following: if you have IdentityFile in your ~/.ssh/config
|
63
|
-
# file, then the above code will transform the ssh_options by reading ~/.ssh/config
|
64
|
-
# and adding the keys specified via IdentityFile to ssh_options...
|
65
|
-
# AND IT WILL SET :keys_only TO TRUE.
|
66
|
-
#
|
67
|
-
# The problem is that :keys_only will disable Net:SSH's ability to use ssh-agent.
|
68
|
-
# With :keys_only set to true, it will not consult the ssh-agent at all.
|
69
|
-
#
|
70
|
-
# So nice of capistrano to parse ~/.ssh/config for us, but then add flags to the
|
71
|
-
# ssh_options that prevent's these options from being useful.
|
72
|
-
#
|
73
|
-
# The current hackaround is to force :keys_only to be false. This allows the config
|
74
|
-
# to be read and also allows ssh-agent to still be used.
|
75
|
-
#
|
76
|
-
def ssh_options
|
77
|
-
{
|
78
|
-
:keys_only => false, # Don't you dare change this.
|
79
|
-
:global_known_hosts_file => path(:known_hosts),
|
80
|
-
:user_known_hosts_file => '/dev/null',
|
81
|
-
:paranoid => true,
|
82
|
-
:verbose => net_ssh_log_level
|
83
|
-
}
|
84
|
-
end
|
85
|
-
|
86
|
-
def net_ssh_log_level
|
87
|
-
if DEBUG
|
88
|
-
case LeapCli.log_level
|
89
|
-
when 1 then 3
|
90
|
-
when 2 then 2
|
91
|
-
when 3 then 1
|
92
|
-
else 0
|
93
|
-
end
|
94
|
-
else
|
95
|
-
nil
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
#
|
100
|
-
# For notes on advanced ways to set server-specific options, see
|
101
|
-
# http://railsware.com/blog/2011/11/02/advanced-server-definitions-in-capistrano/
|
102
|
-
#
|
103
|
-
# if, in the future, we want to do per-node password options, it would be done like so:
|
104
|
-
#
|
105
|
-
# password_proc = Proc.new {Capistrano::CLI.password_prompt "Root SSH password for #{node.name}"}
|
106
|
-
# return {:password => password_proc}
|
107
|
-
#
|
108
|
-
def node_options(node, ssh_options_override=nil)
|
109
|
-
{
|
110
|
-
:ssh_options => {
|
111
|
-
# :host_key_alias => node.name, << incompatible with ports in known_hosts
|
112
|
-
:host_name => node.ip_address,
|
113
|
-
:port => node.ssh.port
|
114
|
-
}.merge(contingent_ssh_options_for_node(node)).merge(ssh_options_override||{})
|
115
|
-
}
|
116
|
-
end
|
117
|
-
|
118
|
-
def new_capistrano
|
119
|
-
# load once the library files
|
120
|
-
@capistrano_enabled ||= begin
|
121
|
-
require 'capistrano'
|
122
|
-
require 'capistrano/cli'
|
123
|
-
require 'leap_cli/lib_ext/capistrano_connections'
|
124
|
-
require 'leap_cli/remote/leap_plugin'
|
125
|
-
require 'leap_cli/remote/puppet_plugin'
|
126
|
-
require 'leap_cli/remote/rsync_plugin'
|
127
|
-
Capistrano.plugin :leap, LeapCli::Remote::LeapPlugin
|
128
|
-
Capistrano.plugin :puppet, LeapCli::Remote::PuppetPlugin
|
129
|
-
Capistrano.plugin :rsync, LeapCli::Remote::RsyncPlugin
|
130
|
-
true
|
131
|
-
end
|
132
|
-
|
133
|
-
# create capistrano instance
|
134
|
-
cap = Capistrano::Configuration.new
|
135
|
-
|
136
|
-
# add tasks to capistrano instance
|
137
|
-
cap.load File.dirname(__FILE__) + '/../remote/tasks.rb'
|
138
|
-
|
139
|
-
return cap
|
140
|
-
end
|
141
|
-
|
142
|
-
def contingent_ssh_options_for_node(node)
|
143
|
-
opts = {}
|
144
|
-
if node.vagrant?
|
145
|
-
opts[:keys] = [vagrant_ssh_key_file]
|
146
|
-
opts[:keys_only] = true # only use the keys specified above, and ignore whatever keys the ssh-agent is aware of.
|
147
|
-
opts[:paranoid] = false # we skip host checking for vagrant nodes, because fingerprint is different for everyone.
|
148
|
-
if LeapCli::log_level <= 1
|
149
|
-
opts[:verbose] = :error # suppress all the warnings about adding host keys to known_hosts, since it is not actually doing that.
|
150
|
-
end
|
151
|
-
end
|
152
|
-
if !node.supported_ssh_host_key_algorithms.empty?
|
153
|
-
opts[:host_key] = node.supported_ssh_host_key_algorithms
|
154
|
-
end
|
155
|
-
return opts
|
156
|
-
end
|
157
|
-
|
158
|
-
end; end; end
|
data/lib/leap_cli/util/secret.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# A simple secret generator
|
4
|
-
#
|
5
|
-
# Uses OpenSSL random number generator instead of Ruby's rand function
|
6
|
-
#
|
7
|
-
autoload :OpenSSL, 'openssl'
|
8
|
-
|
9
|
-
module LeapCli; module Util
|
10
|
-
class Secret
|
11
|
-
CHARS = (('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a) - "i1loO06G".split(//u)
|
12
|
-
HEX = (0..9).to_a + ('a'..'f').to_a
|
13
|
-
|
14
|
-
#
|
15
|
-
# generate a secret with with no ambiguous characters.
|
16
|
-
#
|
17
|
-
# +length+ is in chars
|
18
|
-
#
|
19
|
-
# Only alphanumerics are allowed, in order to make these passwords work
|
20
|
-
# for REST url calls and to allow you to easily copy and paste them.
|
21
|
-
#
|
22
|
-
def self.generate(length = 16)
|
23
|
-
seed
|
24
|
-
OpenSSL::Random.random_bytes(length).bytes.to_a.collect { |byte|
|
25
|
-
CHARS[ byte % CHARS.length ]
|
26
|
-
}.join
|
27
|
-
end
|
28
|
-
|
29
|
-
#
|
30
|
-
# generates a hex secret, instead of an alphanumeric on.
|
31
|
-
#
|
32
|
-
# length is in bits
|
33
|
-
#
|
34
|
-
def self.generate_hex(length = 128)
|
35
|
-
seed
|
36
|
-
OpenSSL::Random.random_bytes(length/4).bytes.to_a.collect { |byte|
|
37
|
-
HEX[ byte % HEX.length ]
|
38
|
-
}.join
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def self.seed
|
44
|
-
@pid ||= 0
|
45
|
-
pid = $$
|
46
|
-
if @pid != pid
|
47
|
-
now = Time.now
|
48
|
-
ary = [now.to_i, now.nsec, @pid, pid]
|
49
|
-
OpenSSL::Random.seed(ary.to_s)
|
50
|
-
@pid = pid
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end; end
|
data/lib/leap_cli/util/x509.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
autoload :OpenSSL, 'openssl'
|
2
|
-
autoload :CertificateAuthority, 'certificate_authority'
|
3
|
-
|
4
|
-
require 'digest'
|
5
|
-
require 'digest/md5'
|
6
|
-
require 'digest/sha1'
|
7
|
-
|
8
|
-
module LeapCli; module X509
|
9
|
-
extend self
|
10
|
-
|
11
|
-
#
|
12
|
-
# returns a fingerprint of a x509 certificate
|
13
|
-
#
|
14
|
-
def fingerprint(digest, cert_file)
|
15
|
-
if cert_file.is_a? String
|
16
|
-
cert = OpenSSL::X509::Certificate.new(Util.read_file!(cert_file))
|
17
|
-
elsif cert_file.is_a? OpenSSL::X509::Certificate
|
18
|
-
cert = cert_file
|
19
|
-
elsif cert_file.is_a? CertificateAuthority::Certificate
|
20
|
-
cert = cert_file.openssl_body
|
21
|
-
end
|
22
|
-
digester = case digest
|
23
|
-
when "MD5" then Digest::MD5.new
|
24
|
-
when "SHA1" then Digest::SHA1.new
|
25
|
-
when "SHA256" then Digest::SHA256.new
|
26
|
-
when "SHA384" then Digest::SHA384.new
|
27
|
-
when "SHA512" then Digest::SHA512.new
|
28
|
-
end
|
29
|
-
digester.hexdigest(cert.to_der)
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
end; end
|