puppetserver-ca 1.9.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/puppetserver/ca/action/clean.rb +1 -1
- data/lib/puppetserver/ca/action/enable.rb +1 -1
- data/lib/puppetserver/ca/action/generate.rb +1 -1
- data/lib/puppetserver/ca/action/import.rb +4 -1
- data/lib/puppetserver/ca/action/list.rb +1 -1
- data/lib/puppetserver/ca/action/migrate.rb +1 -9
- data/lib/puppetserver/ca/action/revoke.rb +1 -1
- data/lib/puppetserver/ca/action/setup.rb +4 -1
- data/lib/puppetserver/ca/action/sign.rb +1 -1
- data/lib/puppetserver/ca/config/puppet.rb +46 -21
- data/lib/puppetserver/ca/utils/config.rb +36 -0
- data/lib/puppetserver/ca/utils/file_system.rb +5 -0
- data/lib/puppetserver/ca/utils/http_client.rb +1 -1
- data/lib/puppetserver/ca/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6523b5628cc4d83aa2627326400a2fb493a18f28d7e4da4b8046eac41e09c555
|
4
|
+
data.tar.gz: 6e8cfbeb2a63ad443f22b196d9cdf2749242ef552c6376fd55b723aa699ceefd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82c62889b706bad66349d5efd8469969b919d8d90741c57c12827eccdedf2de80597ea923509c66de6d6f317da365d860705d556441ce817167d323ad6e80325
|
7
|
+
data.tar.gz: 72cca87e22e38e8c6b2b7975d4920057f5364c7a9499bcf30553894b9285468a0cb1d3fd93aace8974a889a0e0a0ed35f348d902139a07d0f588957e61f479f4
|
data/README.md
CHANGED
@@ -92,7 +92,7 @@ To test your changes on a VM:
|
|
92
92
|
1. To confirm that installation was successful, run `puppetserver ca --help`
|
93
93
|
|
94
94
|
### Releasing
|
95
|
-
To release a new version, run the [release pipeline](https://jenkins-master-prod-1.delivery.puppetlabs.net/job/platform_puppetserver-ca_init-
|
95
|
+
To release a new version, run the [release pipeline](https://jenkins-master-prod-1.delivery.puppetlabs.net/job/platform_puppetserver-ca_init-multijob_main/), which will bump the version, tag, build, and release the gem.
|
96
96
|
|
97
97
|
|
98
98
|
## Contributing & Support
|
@@ -85,7 +85,7 @@ BANNER
|
|
85
85
|
return 1 if Errors.handle_with_usage(@logger, errors)
|
86
86
|
end
|
87
87
|
|
88
|
-
puppet = Config::Puppet.parse(config)
|
88
|
+
puppet = Config::Puppet.parse(config, @logger)
|
89
89
|
return 1 if Errors.handle_with_usage(@logger, puppet.errors)
|
90
90
|
|
91
91
|
result = clean_certs(certnames, puppet.settings)
|
@@ -126,7 +126,7 @@ BANNER
|
|
126
126
|
# Load, resolve, and validate puppet config settings
|
127
127
|
settings_overrides = {}
|
128
128
|
puppet = Config::Puppet.new(config_path)
|
129
|
-
puppet.load(settings_overrides)
|
129
|
+
puppet.load(settings_overrides, @logger)
|
130
130
|
return 1 if Errors.handle_with_usage(@logger, puppet.errors)
|
131
131
|
|
132
132
|
# We don't want generate to respect the alt names setting, since it is usually
|
@@ -4,6 +4,7 @@ require 'puppetserver/ca/config/puppet'
|
|
4
4
|
require 'puppetserver/ca/errors'
|
5
5
|
require 'puppetserver/ca/local_certificate_authority'
|
6
6
|
require 'puppetserver/ca/utils/cli_parsing'
|
7
|
+
require 'puppetserver/ca/utils/config'
|
7
8
|
require 'puppetserver/ca/utils/file_system'
|
8
9
|
require 'puppetserver/ca/utils/signing_digest'
|
9
10
|
require 'puppetserver/ca/x509_loader'
|
@@ -55,7 +56,7 @@ BANNER
|
|
55
56
|
settings_overrides[:dns_alt_names] = input['subject-alt-names'] unless input['subject-alt-names'].empty?
|
56
57
|
|
57
58
|
puppet = Config::Puppet.new(config_path)
|
58
|
-
puppet.load(settings_overrides)
|
59
|
+
puppet.load(settings_overrides, @logger)
|
59
60
|
return 1 if Errors.handle_with_usage(@logger, puppet.errors)
|
60
61
|
|
61
62
|
# Load most secure signing digest we can for cers/crl/csr signing.
|
@@ -130,6 +131,8 @@ ERR
|
|
130
131
|
FileSystem.write_file(location, content, 0640)
|
131
132
|
end
|
132
133
|
|
134
|
+
Puppetserver::Ca::Utils::Config.symlink_to_old_cadir(settings[:cadir], settings[:confdir])
|
135
|
+
|
133
136
|
return []
|
134
137
|
end
|
135
138
|
|
@@ -68,7 +68,7 @@ Options:
|
|
68
68
|
return 1 if Errors.handle_with_usage(@logger, errors)
|
69
69
|
end
|
70
70
|
|
71
|
-
puppet = Config::Puppet.parse(config)
|
71
|
+
puppet = Config::Puppet.parse(config, @logger)
|
72
72
|
return 1 if Errors.handle_with_usage(@logger, puppet.errors)
|
73
73
|
|
74
74
|
filter_names = certnames.any? \
|
@@ -29,7 +29,7 @@ BANNER
|
|
29
29
|
def run(input)
|
30
30
|
config_path = input['config']
|
31
31
|
puppet = Config::Puppet.new(config_path)
|
32
|
-
puppet.load
|
32
|
+
puppet.load({}, @logger)
|
33
33
|
return 1 if HttpClient.check_server_online(puppet.settings, @logger)
|
34
34
|
|
35
35
|
errors = FileSystem.check_for_existing_files(PUPPETSERVER_CA_DIR)
|
@@ -66,14 +66,6 @@ SUCCESS_MESSAGE
|
|
66
66
|
def migrate(old_cadir, new_cadir=PUPPETSERVER_CA_DIR)
|
67
67
|
FileUtils.mv(old_cadir, new_cadir)
|
68
68
|
FileUtils.symlink(new_cadir, old_cadir)
|
69
|
-
# Ensure the symlink has the same ownership as the actual cadir.
|
70
|
-
# This requires using `FileUtils.chown` rather than `File.chown`, as
|
71
|
-
# the latter will update the ownership of the target rather than the
|
72
|
-
# link itself.
|
73
|
-
# Symlink permissions are ignored in favor of the target's permissions,
|
74
|
-
# so we don't have to change those.
|
75
|
-
cadir = File.stat(new_cadir)
|
76
|
-
FileUtils.chown(cadir.uid, cadir.gid, old_cadir)
|
77
69
|
end
|
78
70
|
|
79
71
|
def parse(args)
|
@@ -83,7 +83,7 @@ BANNER
|
|
83
83
|
return 1 if Errors.handle_with_usage(@logger, errors)
|
84
84
|
end
|
85
85
|
|
86
|
-
puppet = Config::Puppet.parse(config)
|
86
|
+
puppet = Config::Puppet.parse(config, @logger)
|
87
87
|
return 1 if Errors.handle_with_usage(@logger, puppet.errors)
|
88
88
|
|
89
89
|
result = revoke_certs(certnames, puppet.settings)
|
@@ -3,6 +3,7 @@ require 'optparse'
|
|
3
3
|
require 'puppetserver/ca/config/puppet'
|
4
4
|
require 'puppetserver/ca/errors'
|
5
5
|
require 'puppetserver/ca/local_certificate_authority'
|
6
|
+
require 'puppetserver/ca/utils/config'
|
6
7
|
require 'puppetserver/ca/utils/cli_parsing'
|
7
8
|
require 'puppetserver/ca/utils/file_system'
|
8
9
|
require 'puppetserver/ca/utils/signing_digest'
|
@@ -55,7 +56,7 @@ BANNER
|
|
55
56
|
settings_overrides[:dns_alt_names] = input['subject-alt-names'] unless input['subject-alt-names'].empty?
|
56
57
|
|
57
58
|
puppet = Config::Puppet.new(config_path)
|
58
|
-
puppet.load(settings_overrides)
|
59
|
+
puppet.load(settings_overrides, @logger)
|
59
60
|
return 1 if Errors.handle_with_usage(@logger, puppet.errors)
|
60
61
|
|
61
62
|
# Load most secure signing digest we can for cers/crl/csr signing.
|
@@ -135,6 +136,8 @@ ERR
|
|
135
136
|
FileSystem.write_file(location, content, 0640)
|
136
137
|
end
|
137
138
|
|
139
|
+
Puppetserver::Ca::Utils::Config.symlink_to_old_cadir(settings[:cadir], settings[:confdir])
|
140
|
+
|
138
141
|
return []
|
139
142
|
end
|
140
143
|
|
@@ -62,7 +62,7 @@ Options:
|
|
62
62
|
return 1 if Errors.handle_with_usage(@logger, errors)
|
63
63
|
end
|
64
64
|
|
65
|
-
puppet = Config::Puppet.parse(config)
|
65
|
+
puppet = Config::Puppet.parse(config, @logger)
|
66
66
|
return 1 if Errors.handle_with_usage(@logger, puppet.errors)
|
67
67
|
|
68
68
|
ca = Puppetserver::Ca::CertificateAuthority.new(@logger, puppet.settings)
|
@@ -23,9 +23,9 @@ module Puppetserver
|
|
23
23
|
# A regex describing valid formats with groups for capturing the value and units
|
24
24
|
TTL_FORMAT = /^(\d+)(y|d|h|m|s)?$/
|
25
25
|
|
26
|
-
def self.parse(config_path)
|
26
|
+
def self.parse(config_path, logger)
|
27
27
|
instance = new(config_path)
|
28
|
-
instance.load
|
28
|
+
instance.load({}, logger)
|
29
29
|
|
30
30
|
return instance
|
31
31
|
end
|
@@ -34,7 +34,7 @@ module Puppetserver
|
|
34
34
|
|
35
35
|
def initialize(supplied_config_path = nil)
|
36
36
|
@using_default_location = !supplied_config_path
|
37
|
-
@config_path = supplied_config_path ||
|
37
|
+
@config_path = supplied_config_path || user_specific_puppet_config
|
38
38
|
|
39
39
|
@settings = nil
|
40
40
|
@errors = []
|
@@ -46,36 +46,28 @@ module Puppetserver
|
|
46
46
|
# on Windows are unsupported.
|
47
47
|
# Note that Puppet Server runs as the [pe-]puppet user but to
|
48
48
|
# start/stop it you must be root.
|
49
|
-
def
|
50
|
-
@
|
51
|
-
if Puppetserver::Ca::Utils::Config.running_as_root?
|
52
|
-
'/etc/puppetlabs/puppet'
|
53
|
-
else
|
54
|
-
"#{ENV['HOME']}/.puppetlabs/etc/puppet"
|
55
|
-
end
|
49
|
+
def user_specific_puppet_confdir
|
50
|
+
@user_specific_puppet_confdir ||= Puppetserver::Ca::Utils::Config.puppet_confdir
|
56
51
|
end
|
57
52
|
|
58
|
-
def
|
59
|
-
|
53
|
+
def user_specific_puppet_config
|
54
|
+
user_specific_puppet_confdir + '/puppet.conf'
|
60
55
|
end
|
61
56
|
|
62
|
-
def load(cli_overrides = {})
|
57
|
+
def load(cli_overrides = {}, logger)
|
63
58
|
if explicitly_given_config_file_or_default_config_exists?
|
64
59
|
results = parse_text(File.read(@config_path))
|
65
60
|
end
|
66
61
|
|
67
62
|
results ||= {}
|
68
63
|
results[:main] ||= {}
|
69
|
-
# The [master] config section is deprecated
|
70
|
-
# We now favor [server], but support both for backwards compatibility
|
71
64
|
results[:master] ||= {}
|
72
|
-
results[:server] ||= {}
|
73
65
|
results[:agent] ||= {}
|
74
66
|
|
75
|
-
overrides = results[:agent].merge(results[:main]).merge(results[:master])
|
67
|
+
overrides = results[:agent].merge(results[:main]).merge(results[:master])
|
76
68
|
overrides.merge!(cli_overrides)
|
77
69
|
|
78
|
-
@settings = resolve_settings(overrides).freeze
|
70
|
+
@settings = resolve_settings(overrides, logger).freeze
|
79
71
|
end
|
80
72
|
|
81
73
|
def default_certname
|
@@ -92,7 +84,7 @@ module Puppetserver
|
|
92
84
|
|
93
85
|
# Resolve settings from default values, with any overrides for the
|
94
86
|
# specific settings or their dependent settings (ssldir, cadir) taken into account.
|
95
|
-
def resolve_settings(overrides = {})
|
87
|
+
def resolve_settings(overrides = {}, logger)
|
96
88
|
unresolved_setting = /\$[a-z_]+/
|
97
89
|
|
98
90
|
# Returning the key for unknown keys (rather than nil) is required to
|
@@ -104,9 +96,8 @@ module Puppetserver
|
|
104
96
|
# These need to be evaluated before we can construct their dependent
|
105
97
|
# defaults below
|
106
98
|
base_defaults = [
|
107
|
-
[:confdir,
|
99
|
+
[:confdir, user_specific_puppet_confdir],
|
108
100
|
[:ssldir,'$confdir/ssl'],
|
109
|
-
[:cadir, '$ssldir/ca'],
|
110
101
|
[:certdir, '$ssldir/certs'],
|
111
102
|
[:certname, default_certname],
|
112
103
|
[:server, 'puppet'],
|
@@ -151,6 +142,13 @@ module Puppetserver
|
|
151
142
|
settings[setting_name] = substitutions[substitution_name] = subbed_value
|
152
143
|
end
|
153
144
|
|
145
|
+
cadir = find_cadir(overrides.fetch(:cadir, false),
|
146
|
+
settings[:confdir],
|
147
|
+
settings[:ssldir],
|
148
|
+
logger)
|
149
|
+
settings[:cadir] = substitutions['$cadir'] = cadir
|
150
|
+
|
151
|
+
|
154
152
|
dependent_defaults.each do |setting_name, default_value|
|
155
153
|
setting_value = overrides.fetch(setting_name, default_value)
|
156
154
|
settings[setting_name] = setting_value
|
@@ -213,6 +211,33 @@ module Puppetserver
|
|
213
211
|
|
214
212
|
private
|
215
213
|
|
214
|
+
|
215
|
+
def find_cadir(configured_cadir, confdir, ssldir, logger)
|
216
|
+
warning = 'The cadir is currently configured to be inside the ' +
|
217
|
+
'%{ssldir} directory. This config setting and the directory ' +
|
218
|
+
'location will not be used in a future version of puppet. ' +
|
219
|
+
'Please run the puppetserver ca tool to migrate out from the ' +
|
220
|
+
'puppet confdir to the /etc/puppetlabs/puppetserver/ca directory. ' +
|
221
|
+
'Use `puppetserver ca migrate --help` for more info.'
|
222
|
+
|
223
|
+
if configured_cadir
|
224
|
+
if configured_cadir.start_with?(ssldir)
|
225
|
+
logger.warn(warning % {ssldir: ssldir})
|
226
|
+
end
|
227
|
+
configured_cadir
|
228
|
+
|
229
|
+
else
|
230
|
+
old_cadir = Puppetserver::Ca::Utils::Config.old_default_cadir(confdir)
|
231
|
+
new_cadir = Puppetserver::Ca::Utils::Config.new_default_cadir(confdir)
|
232
|
+
if File.exist?(old_cadir) && !File.symlink?(old_cadir)
|
233
|
+
logger.warn(warning % {ssldir: ssldir})
|
234
|
+
old_cadir
|
235
|
+
else
|
236
|
+
new_cadir
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
216
241
|
def explicitly_given_config_file_or_default_config_exists?
|
217
242
|
!@using_default_location || File.exist?(@config_path)
|
218
243
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'puppetserver/ca/utils/file_system'
|
2
|
+
|
1
3
|
module Puppetserver
|
2
4
|
module Ca
|
3
5
|
module Utils
|
@@ -19,6 +21,40 @@ module Puppetserver
|
|
19
21
|
end.sort.uniq.join(", ")
|
20
22
|
end
|
21
23
|
|
24
|
+
def self.puppet_confdir
|
25
|
+
if running_as_root?
|
26
|
+
'/etc/puppetlabs/puppet'
|
27
|
+
else
|
28
|
+
"#{ENV['HOME']}/.puppetlabs/etc/puppet"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.puppetserver_confdir(puppet_confdir)
|
33
|
+
File.join(File.dirname(puppet_confdir), 'puppetserver')
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.default_ssldir(confdir = puppet_confdir)
|
37
|
+
File.join(confdir, 'ssl')
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.old_default_cadir(confdir = puppet_confdir)
|
41
|
+
File.join(confdir, 'ssl', 'ca')
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.new_default_cadir(confdir = puppet_confdir)
|
45
|
+
File.join(puppetserver_confdir(confdir), 'ca')
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.symlink_to_old_cadir(current_cadir, puppet_confdir)
|
49
|
+
old_cadir = old_default_cadir(puppet_confdir)
|
50
|
+
new_cadir = new_default_cadir(puppet_confdir)
|
51
|
+
return if current_cadir != new_cadir
|
52
|
+
# This is only run on setup/import, so there should be no files in the
|
53
|
+
# old cadir, so it should be safe to forcibly remove it (which we need
|
54
|
+
# to do in order to create a symlink).
|
55
|
+
Puppetserver::Ca::Utils::FileSystem.forcibly_symlink(new_cadir, old_cadir)
|
56
|
+
end
|
57
|
+
|
22
58
|
end
|
23
59
|
end
|
24
60
|
end
|
@@ -174,7 +174,7 @@ module Puppetserver
|
|
174
174
|
self.new(settings, with_client_cert: false).with_connection(status_url) do |conn|
|
175
175
|
result = conn.get
|
176
176
|
if result.body == "running"
|
177
|
-
logger.err "
|
177
|
+
logger.err "CA service is running. Please stop it before attempting to run this command."
|
178
178
|
true
|
179
179
|
else
|
180
180
|
false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppetserver-ca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: facter
|