puppet 2.7.5 → 2.7.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (140) hide show
  1. data/CHANGELOG +121 -0
  2. data/conf/redhat/puppet.spec +16 -7
  3. data/lib/puppet.rb +1 -1
  4. data/lib/puppet/application/cert.rb +17 -3
  5. data/lib/puppet/application/device.rb +1 -0
  6. data/lib/puppet/application/kick.rb +0 -2
  7. data/lib/puppet/application/resource.rb +73 -66
  8. data/lib/puppet/configurer/plugin_handler.rb +6 -2
  9. data/lib/puppet/defaults.rb +60 -5
  10. data/lib/puppet/face/ca.rb +11 -2
  11. data/lib/puppet/face/certificate.rb +33 -4
  12. data/lib/puppet/file_serving/fileset.rb +1 -1
  13. data/lib/puppet/file_serving/indirection_hooks.rb +2 -2
  14. data/lib/puppet/file_serving/metadata.rb +43 -4
  15. data/lib/puppet/indirector.rb +0 -1
  16. data/lib/puppet/indirector/request.rb +3 -4
  17. data/lib/puppet/indirector/resource/active_record.rb +3 -10
  18. data/lib/puppet/indirector/resource/ral.rb +2 -2
  19. data/lib/puppet/indirector/rest.rb +1 -1
  20. data/lib/puppet/network/handler/ca.rb +16 -106
  21. data/lib/puppet/network/handler/master.rb +0 -3
  22. data/lib/puppet/network/handler/runner.rb +1 -0
  23. data/lib/puppet/parser/scope.rb +10 -0
  24. data/lib/puppet/provider/file/posix.rb +72 -34
  25. data/lib/puppet/provider/file/windows.rb +100 -0
  26. data/lib/puppet/provider/group/windows_adsi.rb +2 -2
  27. data/lib/puppet/provider/user/windows_adsi.rb +19 -4
  28. data/lib/puppet/resource.rb +16 -0
  29. data/lib/puppet/resource/catalog.rb +1 -1
  30. data/lib/puppet/ssl/certificate.rb +2 -2
  31. data/lib/puppet/ssl/certificate_authority.rb +86 -10
  32. data/lib/puppet/ssl/certificate_authority/interface.rb +64 -19
  33. data/lib/puppet/ssl/certificate_factory.rb +112 -91
  34. data/lib/puppet/ssl/certificate_request.rb +88 -1
  35. data/lib/puppet/ssl/host.rb +20 -3
  36. data/lib/puppet/type/file.rb +15 -34
  37. data/lib/puppet/type/file/group.rb +11 -91
  38. data/lib/puppet/type/file/mode.rb +11 -41
  39. data/lib/puppet/type/file/owner.rb +18 -34
  40. data/lib/puppet/type/file/source.rb +22 -7
  41. data/lib/puppet/type/group.rb +4 -3
  42. data/lib/puppet/type/user.rb +4 -1
  43. data/lib/puppet/util.rb +59 -6
  44. data/lib/puppet/util/adsi.rb +11 -0
  45. data/lib/puppet/util/log.rb +4 -0
  46. data/lib/puppet/util/log/destinations.rb +7 -1
  47. data/lib/puppet/util/monkey_patches.rb +19 -0
  48. data/lib/puppet/util/network_device/config.rb +4 -5
  49. data/lib/puppet/util/settings.rb +5 -0
  50. data/lib/puppet/util/suidmanager.rb +0 -1
  51. data/lib/puppet/util/windows.rb +4 -0
  52. data/lib/puppet/util/windows/error.rb +16 -0
  53. data/lib/puppet/util/windows/security.rb +593 -0
  54. data/spec/integration/defaults_spec.rb +27 -0
  55. data/spec/integration/network/handler_spec.rb +1 -1
  56. data/spec/integration/type/file_spec.rb +382 -145
  57. data/spec/integration/util/windows/security_spec.rb +468 -0
  58. data/spec/shared_behaviours/file_serving.rb +4 -3
  59. data/spec/unit/application/agent_spec.rb +1 -0
  60. data/spec/unit/application/device_spec.rb +5 -0
  61. data/spec/unit/application/resource_spec.rb +62 -101
  62. data/spec/unit/configurer/downloader_spec.rb +2 -2
  63. data/spec/unit/configurer/plugin_handler_spec.rb +15 -8
  64. data/spec/unit/configurer_spec.rb +2 -2
  65. data/spec/unit/face/ca_spec.rb +34 -0
  66. data/spec/unit/face/certificate_spec.rb +168 -1
  67. data/spec/unit/file_serving/fileset_spec.rb +1 -1
  68. data/spec/unit/file_serving/indirection_hooks_spec.rb +1 -1
  69. data/spec/unit/file_serving/metadata_spec.rb +151 -107
  70. data/spec/unit/indirector/certificate_request/ca_spec.rb +0 -3
  71. data/spec/unit/indirector/direct_file_server_spec.rb +10 -9
  72. data/spec/unit/indirector/file_metadata/file_spec.rb +6 -4
  73. data/spec/unit/indirector/request_spec.rb +13 -3
  74. data/spec/unit/indirector/resource/active_record_spec.rb +4 -10
  75. data/spec/unit/indirector/resource/ral_spec.rb +6 -4
  76. data/spec/unit/indirector/rest_spec.rb +5 -6
  77. data/spec/unit/network/handler/ca_spec.rb +86 -0
  78. data/spec/unit/parser/collector_spec.rb +7 -7
  79. data/spec/unit/parser/scope_spec.rb +20 -0
  80. data/spec/unit/provider/file/posix_spec.rb +226 -0
  81. data/spec/unit/provider/file/windows_spec.rb +136 -0
  82. data/spec/unit/provider/group/windows_adsi_spec.rb +7 -2
  83. data/spec/unit/provider/user/windows_adsi_spec.rb +36 -3
  84. data/spec/unit/resource/catalog_spec.rb +20 -10
  85. data/spec/unit/resource_spec.rb +55 -8
  86. data/spec/unit/ssl/certificate_authority/interface_spec.rb +97 -54
  87. data/spec/unit/ssl/certificate_authority_spec.rb +133 -23
  88. data/spec/unit/ssl/certificate_factory_spec.rb +90 -70
  89. data/spec/unit/ssl/certificate_request_spec.rb +62 -1
  90. data/spec/unit/ssl/certificate_spec.rb +20 -14
  91. data/spec/unit/ssl/host_spec.rb +52 -6
  92. data/spec/unit/type/file/content_spec.rb +4 -4
  93. data/spec/unit/type/file/group_spec.rb +34 -96
  94. data/spec/unit/type/file/mode_spec.rb +88 -0
  95. data/spec/unit/type/file/owner_spec.rb +32 -123
  96. data/spec/unit/type/file/source_spec.rb +120 -41
  97. data/spec/unit/type/file_spec.rb +1033 -753
  98. data/spec/unit/type_spec.rb +19 -1
  99. data/spec/unit/util/adsi_spec.rb +19 -0
  100. data/spec/unit/util/log/destinations_spec.rb +75 -0
  101. data/spec/unit/util/log_spec.rb +15 -0
  102. data/spec/unit/util/network_device/config_spec.rb +7 -0
  103. data/spec/unit/util/settings_spec.rb +10 -0
  104. data/spec/unit/util_spec.rb +126 -13
  105. data/test/language/functions.rb +0 -1
  106. data/test/language/snippets.rb +0 -9
  107. data/test/lib/puppettest/exetest.rb +1 -1
  108. data/test/lib/puppettest/servertest.rb +0 -1
  109. data/test/rails/rails.rb +0 -1
  110. data/test/ral/type/filesources.rb +0 -60
  111. metadata +13 -33
  112. data/lib/puppet/network/client.rb +0 -174
  113. data/lib/puppet/network/client/ca.rb +0 -56
  114. data/lib/puppet/network/client/file.rb +0 -6
  115. data/lib/puppet/network/client/proxy.rb +0 -27
  116. data/lib/puppet/network/client/report.rb +0 -26
  117. data/lib/puppet/network/client/runner.rb +0 -10
  118. data/lib/puppet/network/client/status.rb +0 -4
  119. data/lib/puppet/network/http_server.rb +0 -3
  120. data/lib/puppet/network/http_server/mongrel.rb +0 -130
  121. data/lib/puppet/network/http_server/webrick.rb +0 -155
  122. data/lib/puppet/network/xmlrpc/client.rb +0 -211
  123. data/lib/puppet/provider/file/win32.rb +0 -72
  124. data/lib/puppet/sslcertificates.rb +0 -146
  125. data/lib/puppet/sslcertificates/ca.rb +0 -375
  126. data/lib/puppet/sslcertificates/certificate.rb +0 -255
  127. data/lib/puppet/sslcertificates/inventory.rb +0 -38
  128. data/lib/puppet/sslcertificates/support.rb +0 -146
  129. data/spec/integration/network/client_spec.rb +0 -18
  130. data/spec/unit/network/xmlrpc/client_spec.rb +0 -172
  131. data/spec/unit/sslcertificates/ca_spec.rb +0 -106
  132. data/test/certmgr/certmgr.rb +0 -308
  133. data/test/certmgr/inventory.rb +0 -69
  134. data/test/certmgr/support.rb +0 -105
  135. data/test/network/client/ca.rb +0 -69
  136. data/test/network/client/dipper.rb +0 -34
  137. data/test/network/handler/ca.rb +0 -273
  138. data/test/network/server/mongrel_test.rb +0 -99
  139. data/test/network/server/webrick.rb +0 -111
  140. data/test/network/xmlrpc/client.rb +0 -45
@@ -1,255 +0,0 @@
1
- class Puppet::SSLCertificates::Certificate
2
- SSLCertificates = Puppet::SSLCertificates
3
-
4
- attr_accessor :certfile, :keyfile, :name, :dir, :hash, :type
5
- attr_accessor :key, :cert, :csr, :cacert
6
-
7
- @@params2names = {
8
- :name => "CN",
9
- :state => "ST",
10
- :country => "C",
11
- :email => "emailAddress",
12
- :org => "O",
13
- :city => "L",
14
- :ou => "OU"
15
- }
16
-
17
- def certname
18
- OpenSSL::X509::Name.new self.subject
19
- end
20
-
21
- def delete
22
- [@certfile,@keyfile].each { |file|
23
- File.unlink(file) if FileTest.exists?(file)
24
- }
25
-
26
- if @hash
27
- File.unlink(@hash) if FileTest.symlink?(@hash)
28
- end
29
- end
30
-
31
- def exists?
32
- FileTest.exists?(@certfile)
33
- end
34
-
35
- def getkey
36
- self.mkkey unless FileTest.exists?(@keyfile)
37
- if @password
38
-
39
- @key = OpenSSL::PKey::RSA.new(
40
-
41
- File.read(@keyfile),
42
-
43
- @password
44
- )
45
- else
46
- @key = OpenSSL::PKey::RSA.new(
47
- File.read(@keyfile)
48
- )
49
- end
50
- end
51
-
52
- def initialize(hash)
53
- raise Puppet::Error, "You must specify the common name for the certificate" unless hash.include?(:name)
54
- @name = hash[:name]
55
-
56
- # init a few variables
57
- @cert = @key = @csr = nil
58
-
59
- if hash.include?(:cert)
60
- @certfile = hash[:cert]
61
- @dir = File.dirname(@certfile)
62
- else
63
- @dir = hash[:dir] || Puppet[:certdir]
64
- @certfile = File.join(@dir, @name)
65
- end
66
-
67
- @cacertfile ||= File.join(Puppet[:certdir], "ca.pem")
68
-
69
- Puppet.recmkdir(@dir) unless FileTest.directory?(@dir)
70
-
71
- unless @certfile =~ /\.pem$/
72
- @certfile += ".pem"
73
- end
74
- @keyfile = hash[:key] || File.join(
75
- Puppet[:privatekeydir], [@name,"pem"].join(".")
76
- )
77
- Puppet.recmkdir(@dir) unless FileTest.directory?(@dir)
78
-
79
- [@keyfile].each { |file|
80
- dir = File.dirname(file)
81
-
82
- Puppet.recmkdir(dir) unless FileTest.directory?(dir)
83
- }
84
-
85
- @ttl = hash[:ttl] || 365 * 24 * 60 * 60
86
- @selfsign = hash[:selfsign] || false
87
- @encrypt = hash[:encrypt] || false
88
- @replace = hash[:replace] || false
89
- @issuer = hash[:issuer] || nil
90
-
91
- if hash.include?(:type)
92
- case hash[:type]
93
- when :ca, :client, :server; @type = hash[:type]
94
- else
95
- raise "Invalid Cert type #{hash[:type]}"
96
- end
97
- else
98
- @type = :client
99
- end
100
-
101
- @params = {:name => @name}
102
- [:state, :country, :email, :org, :ou].each { |param|
103
- @params[param] = hash[param] if hash.include?(param)
104
- }
105
-
106
- if @encrypt
107
- if @encrypt =~ /^\//
108
- File.open(@encrypt) { |f|
109
- @password = f.read.chomp
110
- }
111
- else
112
- raise Puppet::Error, ":encrypt must be a path to a pass phrase file"
113
- end
114
- else
115
- @password = nil
116
- end
117
-
118
- @selfsign = hash.include?(:selfsign) && hash[:selfsign]
119
- end
120
-
121
- # this only works for servers, not for users
122
- def mkcsr
123
- self.getkey unless @key
124
-
125
- name = OpenSSL::X509::Name.new self.subject
126
-
127
- @csr = OpenSSL::X509::Request.new
128
- @csr.version = 0
129
- @csr.subject = name
130
- @csr.public_key = @key.public_key
131
- @csr.sign(@key, OpenSSL::Digest::SHA1.new)
132
-
133
- #File.open(@csrfile, "w") { |f|
134
- # f << @csr.to_pem
135
- #}
136
-
137
- raise Puppet::Error, "CSR sign verification failed" unless @csr.verify(@key.public_key)
138
-
139
- @csr
140
- end
141
-
142
- def mkkey
143
- # @key is the file
144
-
145
- @key = OpenSSL::PKey::RSA.new(1024)
146
- # { |p,n|
147
- # case p
148
- # when 0; Puppet.info "key info: ." # BN_generate_prime
149
- # when 1; Puppet.info "key info: +" # BN_generate_prime
150
- # when 2; Puppet.info "key info: *" # searching good prime,
151
- # # n = #of try,
152
- # # but also data from BN_generate_prime
153
- # when 3; Puppet.info "key info: \n" # found good prime, n==0 - p, n==1 - q,
154
- # # but also data from BN_generate_prime
155
- # else; Puppet.info "key info: *" # BN_generate_prime
156
- # end
157
- # }
158
-
159
- if @password
160
- # passwdproc = proc { @password }
161
-
162
- keytext = @key.export(
163
-
164
- OpenSSL::Cipher::DES.new(:EDE3, :CBC),
165
-
166
- @password
167
- )
168
- File.open(@keyfile, "w", 0400) { |f|
169
- f << keytext
170
- }
171
- else
172
- File.open(@keyfile, "w", 0400) { |f|
173
- f << @key.to_pem
174
- }
175
- end
176
-
177
- #cmd = "#{ossl} genrsa -out #{@key} 1024"
178
- end
179
-
180
- def mkselfsigned
181
- self.getkey unless @key
182
-
183
- raise Puppet::Error, "Cannot replace existing certificate" if @cert
184
-
185
- args = {
186
- :name => self.certname,
187
- :ttl => @ttl,
188
- :issuer => nil,
189
- :serial => 0x0,
190
- :publickey => @key.public_key
191
- }
192
- if @type
193
- args[:type] = @type
194
- else
195
- args[:type] = :server
196
- end
197
- @cert = SSLCertificates.mkcert(args)
198
-
199
- @cert.sign(@key, OpenSSL::Digest::SHA1.new) if @selfsign
200
-
201
- @cert
202
- end
203
-
204
- def subject(string = false)
205
- subj = @@params2names.collect { |param, name|
206
- [name, @params[param]] if @params.include?(param)
207
- }.reject { |ary| ary.nil? }
208
-
209
- if string
210
- return "/" + subj.collect { |ary|
211
- "%s=%s" % ary
212
- }.join("/") + "/"
213
- else
214
- return subj
215
- end
216
- end
217
-
218
- # verify that we can track down the cert chain or whatever
219
- def verify
220
- "openssl verify -verbose -CAfile /home/luke/.puppet/ssl/certs/ca.pem -purpose sslserver culain.madstop.com.pem"
221
- end
222
-
223
- def write
224
- files = {
225
- @certfile => @cert,
226
- @keyfile => @key,
227
- }
228
- files[@cacertfile] = @cacert if defined?(@cacert)
229
-
230
- files.each { |file,thing|
231
- if thing
232
- next if FileTest.exists?(file)
233
-
234
- text = nil
235
-
236
- if thing.is_a?(OpenSSL::PKey::RSA) and @password
237
-
238
- text = thing.export(
239
-
240
- OpenSSL::Cipher::DES.new(:EDE3, :CBC),
241
-
242
- @password
243
- )
244
- else
245
- text = thing.to_pem
246
- end
247
-
248
- File.open(file, "w", 0660) { |f| f.print text }
249
- end
250
- }
251
-
252
- SSLCertificates.mkhash(Puppet[:certdir], @cacert, @cacertfile) if defined?(@cacert)
253
- end
254
- end
255
-
@@ -1,38 +0,0 @@
1
- # A module for keeping track of all the certificates issued by the CA, ever
2
- # Maintains the file "$cadir/inventory.txt"
3
- module Puppet::SSLCertificates
4
- module Inventory
5
-
6
- # Add CERT to the inventory of issued certs in '$cadir/inventory.txt'
7
- # If no inventory exists yet, build an inventory and list all the
8
- # certificates that have been signed so far
9
- def self.add(cert)
10
- inited = false
11
- inited = true if FileTest.exists?(Puppet[:cert_inventory])
12
-
13
- Puppet.settings.write(:cert_inventory, "a") do |f|
14
- f.puts((inited ? nil : self.init).to_s + format(cert))
15
- end
16
- end
17
-
18
- private
19
-
20
- def self.init
21
- inv = "# Inventory of signed certificates\n"
22
- inv += "# SERIAL NOT_BEFORE NOT_AFTER SUBJECT\n"
23
- Dir.glob(File::join(Puppet[:signeddir], "*.pem")) do |f|
24
- inv += format(OpenSSL::X509::Certificate.new(File::read(f))) + "\n"
25
- end
26
- inv
27
- end
28
-
29
- def self.format(cert)
30
- iso = '%Y-%m-%dT%H:%M:%S%Z'
31
- return "0x%04x %s %s %s" % [cert.serial,
32
- cert.not_before.strftime(iso),
33
- cert.not_after.strftime(iso),
34
- cert.subject]
35
- end
36
- end
37
- end
38
-
@@ -1,146 +0,0 @@
1
- require 'puppet/sslcertificates'
2
-
3
- # A module to handle reading of certificates.
4
- module Puppet::SSLCertificates::Support
5
- class MissingCertificate < Puppet::Error; end
6
- class InvalidCertificate < Puppet::Error; end
7
-
8
- attr_reader :cacert
9
-
10
- # Some metaprogramming to create methods for retrieving and creating keys.
11
- # This probably isn't fewer lines than defining each separately...
12
- def self.keytype(name, options, &block)
13
- var = "@#{name}"
14
-
15
- maker = "mk_#{name}"
16
- reader = "read_#{name}"
17
-
18
- unless param = options[:param]
19
- raise ArgumentError, "You must specify the parameter for the key"
20
- end
21
-
22
- unless klass = options[:class]
23
- raise ArgumentError, "You must specify the class for the key"
24
- end
25
-
26
- # Define the method that creates it.
27
- define_method(maker, &block)
28
-
29
- # Define the reading method.
30
- define_method(reader) do
31
- return nil unless FileTest.exists?(Puppet[param]) or rename_files_with_uppercase(Puppet[param])
32
-
33
- begin
34
- instance_variable_set(var, klass.new(File.read(Puppet[param])))
35
- rescue => detail
36
- raise InvalidCertificate, "Could not read #{param}: #{detail}"
37
- end
38
- end
39
-
40
- # Define the overall method, which just calls the reader and maker
41
- # as appropriate.
42
- define_method(name) do
43
- unless cert = instance_variable_get(var)
44
- unless cert = send(reader)
45
- cert = send(maker)
46
- Puppet.settings.write(param) { |f| f.puts cert.to_pem }
47
- end
48
- instance_variable_set(var, cert)
49
- end
50
- cert
51
- end
52
- end
53
-
54
- # The key pair.
55
- keytype :key, :param => :hostprivkey, :class => OpenSSL::PKey::RSA do
56
- Puppet.info "Creating a new SSL key at #{Puppet[:hostprivkey]}"
57
- key = OpenSSL::PKey::RSA.new(Puppet[:keylength])
58
-
59
- # Our key meta programming can only handle one file, so we have
60
- # to separately write out the public key.
61
- Puppet.settings.write(:hostpubkey) do |f|
62
- f.print key.public_key.to_pem
63
- end
64
- return key
65
- end
66
-
67
- # Our certificate request
68
- keytype :csr, :param => :hostcsr, :class => OpenSSL::X509::Request do
69
- Puppet.info "Creating a new certificate request for #{Puppet[:certname]}"
70
-
71
- csr = OpenSSL::X509::Request.new
72
- csr.version = 0
73
- csr.subject = OpenSSL::X509::Name.new([["CN", Puppet[:certname]]])
74
- csr.public_key = key.public_key
75
- csr.sign(key, OpenSSL::Digest::MD5.new)
76
-
77
- return csr
78
- end
79
-
80
- keytype :cert, :param => :hostcert, :class => OpenSSL::X509::Certificate do
81
- raise MissingCertificate, "No host certificate"
82
- end
83
-
84
- keytype :ca_cert, :param => :localcacert, :class => OpenSSL::X509::Certificate do
85
- raise MissingCertificate, "No CA certificate"
86
- end
87
-
88
- # Request a certificate from the remote system. This does all of the work
89
- # of creating the cert request, contacting the remote system, and
90
- # storing the cert locally.
91
- def requestcert
92
- begin
93
- cert, cacert = caclient.getcert(@csr.to_pem)
94
- rescue => detail
95
- puts detail.backtrace if Puppet[:trace]
96
- raise Puppet::Error.new("Certificate retrieval failed: #{detail}")
97
- end
98
-
99
- if cert.nil? or cert == ""
100
- return nil
101
- end
102
- Puppet.settings.write(:hostcert) do |f| f.print cert end
103
- Puppet.settings.write(:localcacert) do |f| f.print cacert end
104
- #File.open(@certfile, "w", 0644) { |f| f.print cert }
105
- #File.open(@cacertfile, "w", 0644) { |f| f.print cacert }
106
- begin
107
- @cert = OpenSSL::X509::Certificate.new(cert)
108
- @cacert = OpenSSL::X509::Certificate.new(cacert)
109
- retrieved = true
110
- rescue => detail
111
- raise Puppet::Error.new(
112
- "Invalid certificate: #{detail}"
113
- )
114
- end
115
-
116
- raise Puppet::DevError, "Received invalid certificate" unless @cert.check_private_key(@key)
117
- retrieved
118
- end
119
-
120
- # A hack method to deal with files that exist with a different case.
121
- # Just renames it; doesn't read it in or anything.
122
- def rename_files_with_uppercase(file)
123
- dir = File.dirname(file)
124
- short = File.basename(file)
125
-
126
- # If the dir isn't present, we clearly don't have the file.
127
- #return nil unless FileTest.directory?(dir)
128
-
129
- raise ArgumentError, "Tried to fix SSL files to a file containing uppercase" unless short.downcase == short
130
-
131
- return false unless File.directory?(dir)
132
-
133
- real_file = Dir.entries(dir).reject { |f| f =~ /^\./ }.find do |other|
134
- other.downcase == short
135
- end
136
-
137
- return nil unless real_file
138
-
139
- full_file = File.join(dir, real_file)
140
-
141
- Puppet.notice "Fixing case in #{full_file}; renaming to #{file}"
142
- File.rename(full_file, file)
143
-
144
- true
145
- end
146
- end
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env rspec
2
- require 'spec_helper'
3
-
4
- require 'puppet/network/client'
5
-
6
- describe Puppet::Network::Client do
7
- %w{ca file report runner status}.each do |name|
8
- it "should have a #{name} client" do
9
- Puppet::Network::Client.client(name).should be_instance_of(Class)
10
- end
11
-
12
- [:name, :handler, :drivername].each do |data|
13
- it "should have a #{data} value for the #{name} client" do
14
- Puppet::Network::Client.client(name).send(data).should_not be_nil
15
- end
16
- end
17
- end
18
- end