puppetserver-ca 1.10.0 → 2.2.0
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/README.md +3 -4
- 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 +9 -15
- 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 +33 -22
- data/lib/puppetserver/ca/utils/config.rb +17 -0
- data/lib/puppetserver/ca/utils/file_system.rb +13 -0
- data/lib/puppetserver/ca/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92fe6ca44899e2b5aeec75304212ff99b5e4530cbed2e0b451ad2dd77e2bf09a
|
4
|
+
data.tar.gz: c46bc437a85f0a52fde2d3b2b51bda909ad179c1997056810b397d4b27ae4867
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c7ff17130d558382fa05f5f5bcb537ce9f2bc63a13078d1014783f636fcf0b0c02e604a0d4bf5694a486f67a56dec653430cea0c31eb911b7c15c9ea4e7f59d
|
7
|
+
data.tar.gz: 3ad80f74f02aac6a0dab1601cf54aad14756e0b1c0e2e0a30075d1eeafedff03b4546bc7c0cb7bc6dc6197b71abdb9f74816cd4596050b39e6c0f47ca47baf45
|
data/README.md
CHANGED
@@ -84,8 +84,8 @@ To test your changes on a VM:
|
|
84
84
|
1. Copy the gem to your VM: `scp puppetserver-ca-<version>.gem <your-vm>:.`
|
85
85
|
1. Install puppetserver (FOSS) by installing the relevant release package and then installing the puppetserver package. For example:
|
86
86
|
```
|
87
|
-
$ wget http://nightlies.puppet.com/yum/
|
88
|
-
$ rpm -i
|
87
|
+
$ wget http://nightlies.puppet.com/yum/puppet-nightly-release-el-7.noarch.rpm
|
88
|
+
$ rpm -i puppet-nightly-release-el-7.noarch.rpm
|
89
89
|
$ yum update
|
90
90
|
$ yum install -y puppetserver
|
91
91
|
```
|
@@ -97,8 +97,7 @@ To test your changes on a VM:
|
|
97
97
|
1. To confirm that installation was successful, run `puppetserver ca --help`
|
98
98
|
|
99
99
|
### Releasing
|
100
|
-
To release a new version, run the [release pipeline](https://jenkins-platform.delivery.puppetlabs.net/job/platform_puppetserver-ca_init-
|
101
|
-
|
100
|
+
To release a new version, run the [release pipeline](https://jenkins-platform.delivery.puppetlabs.net/job/platform_puppetserver-ca_init-multijob_main/), which will bump the version, tag, build, and release the gem.
|
102
101
|
|
103
102
|
## Contributing & Support
|
104
103
|
|
@@ -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(cli_overrides: settings_overrides, logger: @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(cli_overrides: settings_overrides, logger: @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
|
|
@@ -1,24 +1,26 @@
|
|
1
1
|
require 'puppetserver/ca/utils/cli_parsing'
|
2
2
|
require 'puppetserver/ca/utils/file_system'
|
3
3
|
require 'puppetserver/ca/utils/http_client'
|
4
|
+
require 'puppetserver/ca/utils/config'
|
4
5
|
|
5
6
|
module Puppetserver
|
6
7
|
module Ca
|
7
8
|
module Action
|
8
9
|
class Migrate
|
9
10
|
include Puppetserver::Ca::Utils
|
10
|
-
PUPPETSERVER_CA_DIR =
|
11
|
+
PUPPETSERVER_CA_DIR = Puppetserver::Ca::Utils::Config.new_default_cadir
|
11
12
|
|
12
|
-
SUMMARY = "Migrate the existing CA directory to
|
13
|
+
SUMMARY = "Migrate the existing CA directory to #{PUPPETSERVER_CA_DIR}"
|
13
14
|
BANNER = <<-BANNER
|
14
15
|
Usage:
|
15
16
|
puppetserver ca migrate [--help]
|
16
17
|
puppetserver ca migrate [--config PATH]
|
17
18
|
|
18
19
|
Description:
|
19
|
-
Migrate an existing CA directory to
|
20
|
-
upgrading from Puppet Platform 6.x to Puppet 7.
|
21
|
-
|
20
|
+
Migrate an existing CA directory to #{PUPPETSERVER_CA_DIR}. This is for
|
21
|
+
upgrading from Puppet Platform 6.x to Puppet 7. Uses the default puppet.conf
|
22
|
+
in your installation, or use a different config by supplying the `--config` flag.
|
23
|
+
|
22
24
|
Options:
|
23
25
|
BANNER
|
24
26
|
|
@@ -29,7 +31,7 @@ BANNER
|
|
29
31
|
def run(input)
|
30
32
|
config_path = input['config']
|
31
33
|
puppet = Config::Puppet.new(config_path)
|
32
|
-
puppet.load
|
34
|
+
puppet.load(logger: @logger, ca_dir_warn: false)
|
33
35
|
return 1 if HttpClient.check_server_online(puppet.settings, @logger)
|
34
36
|
|
35
37
|
errors = FileSystem.check_for_existing_files(PUPPETSERVER_CA_DIR)
|
@@ -65,15 +67,7 @@ SUCCESS_MESSAGE
|
|
65
67
|
|
66
68
|
def migrate(old_cadir, new_cadir=PUPPETSERVER_CA_DIR)
|
67
69
|
FileUtils.mv(old_cadir, new_cadir)
|
68
|
-
|
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)
|
70
|
+
FileSystem.forcibly_symlink(new_cadir, old_cadir)
|
77
71
|
end
|
78
72
|
|
79
73
|
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(cli_overrides: settings_overrides, logger: @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: 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,20 +46,15 @@ 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:, ca_dir_warn: true)
|
63
58
|
if explicitly_given_config_file_or_default_config_exists?
|
64
59
|
results = parse_text(File.read(@config_path))
|
65
60
|
end
|
@@ -78,7 +73,7 @@ module Puppetserver
|
|
78
73
|
overrides[:serverport] ||= overrides.delete(:masterport)
|
79
74
|
end
|
80
75
|
|
81
|
-
@settings = resolve_settings(overrides).freeze
|
76
|
+
@settings = resolve_settings(overrides, logger, ca_dir_warn: ca_dir_warn).freeze
|
82
77
|
end
|
83
78
|
|
84
79
|
def default_certname
|
@@ -94,7 +89,7 @@ module Puppetserver
|
|
94
89
|
|
95
90
|
# Resolve settings from default values, with any overrides for the
|
96
91
|
# specific settings or their dependent settings (ssldir, cadir) taken into account.
|
97
|
-
def resolve_settings(overrides = {})
|
92
|
+
def resolve_settings(overrides = {}, logger, ca_dir_warn: true)
|
98
93
|
unresolved_setting = /\$[a-z_]+/
|
99
94
|
|
100
95
|
# Returning the key for unknown keys (rather than nil) is required to
|
@@ -106,7 +101,7 @@ module Puppetserver
|
|
106
101
|
# These need to be evaluated before we can construct their dependent
|
107
102
|
# defaults below
|
108
103
|
base_defaults = [
|
109
|
-
[:confdir,
|
104
|
+
[:confdir, user_specific_puppet_confdir],
|
110
105
|
[:ssldir,'$confdir/ssl'],
|
111
106
|
[:certdir, '$ssldir/certs'],
|
112
107
|
[:certname, default_certname],
|
@@ -153,9 +148,13 @@ module Puppetserver
|
|
153
148
|
end
|
154
149
|
|
155
150
|
cadir = find_cadir(overrides.fetch(:cadir, false),
|
156
|
-
settings[:confdir]
|
151
|
+
settings[:confdir],
|
152
|
+
settings[:ssldir],
|
153
|
+
logger,
|
154
|
+
ca_dir_warn)
|
157
155
|
settings[:cadir] = substitutions['$cadir'] = cadir
|
158
156
|
|
157
|
+
|
159
158
|
dependent_defaults.each do |setting_name, default_value|
|
160
159
|
setting_value = overrides.fetch(setting_name, default_value)
|
161
160
|
settings[setting_name] = setting_value
|
@@ -218,17 +217,29 @@ module Puppetserver
|
|
218
217
|
|
219
218
|
private
|
220
219
|
|
221
|
-
|
220
|
+
|
221
|
+
def find_cadir(configured_cadir, confdir, ssldir, logger, ca_dir_warn)
|
222
|
+
warning = 'The cadir is currently configured to be inside the ' +
|
223
|
+
'%{ssldir} directory. This config setting and the directory ' +
|
224
|
+
'location will not be used in a future version of puppet. ' +
|
225
|
+
'Please run the puppetserver ca tool to migrate out from the ' +
|
226
|
+
'puppet confdir to the /etc/puppetlabs/puppetserver/ca directory. ' +
|
227
|
+
'Use `puppetserver ca migrate --help` for more info.'
|
228
|
+
|
222
229
|
if configured_cadir
|
230
|
+
if ca_dir_warn && configured_cadir.start_with?(ssldir)
|
231
|
+
logger.warn(warning % {ssldir: ssldir})
|
232
|
+
end
|
223
233
|
configured_cadir
|
234
|
+
|
224
235
|
else
|
225
236
|
old_cadir = Puppetserver::Ca::Utils::Config.old_default_cadir(confdir)
|
226
237
|
new_cadir = Puppetserver::Ca::Utils::Config.new_default_cadir(confdir)
|
227
|
-
|
228
|
-
|
229
|
-
new_cadir
|
230
|
-
else
|
238
|
+
if File.exist?(old_cadir) && !File.symlink?(old_cadir)
|
239
|
+
logger.warn(warning % {ssldir: ssldir}) if ca_dir_warn
|
231
240
|
old_cadir
|
241
|
+
else
|
242
|
+
new_cadir
|
232
243
|
end
|
233
244
|
end
|
234
245
|
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
|
@@ -31,6 +33,10 @@ module Puppetserver
|
|
31
33
|
File.join(File.dirname(puppet_confdir), 'puppetserver')
|
32
34
|
end
|
33
35
|
|
36
|
+
def self.default_ssldir(confdir = puppet_confdir)
|
37
|
+
File.join(confdir, 'ssl')
|
38
|
+
end
|
39
|
+
|
34
40
|
def self.old_default_cadir(confdir = puppet_confdir)
|
35
41
|
File.join(confdir, 'ssl', 'ca')
|
36
42
|
end
|
@@ -38,6 +44,17 @@ module Puppetserver
|
|
38
44
|
def self.new_default_cadir(confdir = puppet_confdir)
|
39
45
|
File.join(puppetserver_confdir(confdir), 'ca')
|
40
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
|
+
|
41
58
|
end
|
42
59
|
end
|
43
60
|
end
|
@@ -50,6 +50,19 @@ module Puppetserver
|
|
50
50
|
errors
|
51
51
|
end
|
52
52
|
|
53
|
+
def self.forcibly_symlink(source, link_target)
|
54
|
+
FileUtils.remove_dir(link_target, true)
|
55
|
+
FileUtils.symlink(source, link_target)
|
56
|
+
# Ensure the symlink has the same ownership as the source.
|
57
|
+
# This requires using `FileUtils.chown` rather than `File.chown`, as
|
58
|
+
# the latter will update the ownership of the source rather than the
|
59
|
+
# link itself.
|
60
|
+
# Symlink permissions are ignored in favor of the source's permissions,
|
61
|
+
# so we don't have to change those.
|
62
|
+
source_info = File.stat(source)
|
63
|
+
FileUtils.chown(source_info.uid, source_info.gid, link_target)
|
64
|
+
end
|
65
|
+
|
53
66
|
def initialize
|
54
67
|
@user, @group = find_user_and_group
|
55
68
|
end
|