puppetserver-ca 1.10.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7200d67071717855a415f5b10ea96e2d008eb9e758b6c1bfcf367d41be1355c4
4
- data.tar.gz: 9b94632f35b636420a5bb80fe6e1878daefb77b4d113aed5122a116113e7ff20
3
+ metadata.gz: 813b9f6f9913cd98abd4b81219cfb4882e7c9c1ace77f024218706be07411d7a
4
+ data.tar.gz: 8f7bd49d04fc6f23f4674006f1d159756286f9b3ae50a686cb4faa5b7b71832d
5
5
  SHA512:
6
- metadata.gz: 82cca168aa2217dd81a68acb3acaabdaddcc06d494a783a04a27a03965110d0ca66fe5a3eee01e4d949073e4e8594d61a3203f83066e8e64b2e857344a723566
7
- data.tar.gz: 95708d9c5f670001c8c3018cf9804fd189d44cb52bcee4e0e86665c4b8d5fd114ebb7480a6576fcffe81fd2289ba28b1fe2c61a8d610d0733b6d6f947df0f04a
6
+ metadata.gz: a2dbfac65155e9dbd593931305b9f99079f2610bd02d64c20e1be00f8f61058f85bfcf410f5987439de892b6adf9e46beadb60d85a4f970c07a4eec2643c54d9
7
+ data.tar.gz: 26964af97f64152d3d5e1bfbcc931daa102734b1facf2ef588890552aee36791be3a6091e5e5563d328254149133035597773486c53e67ddd8e1624327f289bb
data/README.md CHANGED
@@ -55,6 +55,11 @@ To create a new keypair and certificate for a certname:
55
55
  puppetserver ca generate --certname foo.example.com
56
56
  ```
57
57
 
58
+ To remove duplicated entries from Puppet's CRL:
59
+ ```
60
+ puppetserver ca prune
61
+ ```
62
+
58
63
  To enable verbose mode:
59
64
  ```
60
65
  puppetserver ca --verbose <action>
@@ -0,0 +1,116 @@
1
+ require 'optparse'
2
+ require 'openssl'
3
+ require 'puppetserver/ca/errors'
4
+ require 'puppetserver/ca/utils/cli_parsing'
5
+ require 'puppetserver/ca/utils/file_system'
6
+ require 'puppetserver/ca/utils/config'
7
+ require 'puppetserver/ca/x509_loader'
8
+
9
+ module Puppetserver
10
+ module Ca
11
+ module Action
12
+ class Prune
13
+ include Puppetserver::Ca::Utils
14
+
15
+ SUMMARY = "Prune the local CRL on disk to remove any duplicated certificates"
16
+ BANNER = <<-BANNER
17
+ Usage:
18
+ puppetserver ca prune [--help]
19
+ puppetserver ca prune [--config]
20
+
21
+ Description:
22
+ Prune the list of revoked certificates of any duplication within it. This command
23
+ will only prune the CRL issued by Puppet's CA cert.
24
+
25
+ Options:
26
+ BANNER
27
+
28
+ def initialize(logger)
29
+ @logger = logger
30
+ end
31
+
32
+ def run(inputs)
33
+ config_path = inputs['config']
34
+
35
+ # Validate the config path.
36
+ if config_path
37
+ errors = FileSystem.validate_file_paths(config_path)
38
+ return 1 if Errors.handle_with_usage(@logger, errors)
39
+ end
40
+
41
+ # Validate puppet config setting.
42
+ puppet = Config::Puppet.new(config_path)
43
+ puppet.load(logger: @logger)
44
+ return 1 if Errors.handle_with_usage(@logger, puppet.errors)
45
+
46
+ # Validate that we are offline
47
+ return 1 if HttpClient.check_server_online(puppet.settings, @logger)
48
+
49
+ # Getting the CRL(s)
50
+ loader = X509Loader.new(puppet.settings[:cacert], puppet.settings[:cakey], puppet.settings[:cacrl])
51
+
52
+ puppet_crl = loader.crls.select { |crl| crl.verify(loader.key) }
53
+ prune_CRLs(puppet_crl)
54
+ update_pruned_CRL(puppet_crl, loader.key)
55
+ FileSystem.write_file(puppet.settings[:cacrl], loader.crls, 0644)
56
+
57
+ @logger.inform("Finished pruning Puppet's CRL")
58
+ return 0
59
+ end
60
+
61
+ def prune_CRLs(crl_list)
62
+ crl_list.each do |crl|
63
+ existed_serial_number = Set.new()
64
+ revoked_list = crl.revoked
65
+ @logger.debug("Pruning duplicate entries in CRL for issuer " \
66
+ "#{crl.issuer.to_s(OpenSSL::X509::Name::RFC2253)}") if @logger.debug?
67
+
68
+ revoked_list.delete_if do |revoked|
69
+ if existed_serial_number.add?(revoked.serial)
70
+ false
71
+ else
72
+ @logger.debug("Removing duplicate of #{revoked.serial}, " \
73
+ "revoked on #{revoked.time}\n") if @logger.debug?
74
+ true
75
+ end
76
+ end
77
+ crl.revoked=(revoked_list)
78
+ end
79
+ end
80
+
81
+ def update_pruned_CRL(crl_list, pkey)
82
+ crl_list.each do |crl|
83
+ crl.version=(crl.version + 1)
84
+ crl.sign(pkey, OpenSSL::Digest::SHA256.new)
85
+ end
86
+ end
87
+
88
+ def self.parser(parsed = {})
89
+ OptionParser.new do |opts|
90
+ opts.banner = BANNER
91
+ opts.on('--help', 'Display this command-specific help output') do |help|
92
+ parsed['help'] = true
93
+ end
94
+ opts.on('--config CONF', 'Path to the puppet.conf file on disk') do |conf|
95
+ parsed['config'] = conf
96
+ end
97
+ end
98
+ end
99
+
100
+ def parse(args)
101
+ results = {}
102
+ parser = self.class.parser(results)
103
+ errors = CliParsing.parse_with_errors(parser, args)
104
+ errors_were_handled = Errors.handle_with_usage(@logger, errors, parser.help)
105
+
106
+ if errors_were_handled
107
+ exit_code = 1
108
+ else
109
+ exit_code = nil
110
+ end
111
+ return results, exit_code
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -8,6 +8,7 @@ require 'puppetserver/ca/action/list'
8
8
  require 'puppetserver/ca/action/revoke'
9
9
  require 'puppetserver/ca/action/setup'
10
10
  require 'puppetserver/ca/action/sign'
11
+ require 'puppetserver/ca/action/prune'
11
12
  require 'puppetserver/ca/action/migrate'
12
13
  require 'puppetserver/ca/errors'
13
14
  require 'puppetserver/ca/logger'
@@ -25,11 +26,12 @@ Manage the Private Key Infrastructure for
25
26
  Puppet Server's built-in Certificate Authority
26
27
  BANNER
27
28
 
28
- INIT_ACTIONS = {
29
+ ADMIN_ACTIONS = {
29
30
  'import' => Action::Import,
30
31
  'setup' => Action::Setup,
31
- 'enable' => Action::Enable,
32
- 'migrate' => Action::Migrate,
32
+ 'enable' => Action::Enable,
33
+ 'migrate' => Action::Migrate,
34
+ 'prune' => Action::Prune
33
35
  }
34
36
 
35
37
  MAINT_ACTIONS = {
@@ -40,15 +42,15 @@ BANNER
40
42
  'sign' => Action::Sign
41
43
  }
42
44
 
43
- VALID_ACTIONS = INIT_ACTIONS.merge(MAINT_ACTIONS).sort.to_h
45
+ VALID_ACTIONS = ADMIN_ACTIONS.merge(MAINT_ACTIONS).sort.to_h
44
46
 
45
47
  ACTION_LIST = "\nAvailable Actions:\n\n" +
46
48
  " Certificate Actions (requires a running Puppet Server):\n\n" +
47
49
  MAINT_ACTIONS.map do |action, cls|
48
50
  " #{action}\t#{cls::SUMMARY}"
49
51
  end.join("\n") + "\n\n" +
50
- " Initialization Actions (requires Puppet Server to be stopped):\n\n" +
51
- INIT_ACTIONS.map do |action, cls|
52
+ " Administrative Actions (requires Puppet Server to be stopped):\n\n" +
53
+ ADMIN_ACTIONS.map do |action, cls|
52
54
  " #{action}\t#{cls::SUMMARY}"
53
55
  end.join("\n")
54
56
 
@@ -17,8 +17,12 @@ module Puppetserver
17
17
  @level
18
18
  end
19
19
 
20
+ def debug?
21
+ return @level >= LEVELS[:debug]
22
+ end
23
+
20
24
  def debug(text)
21
- if @level >= LEVELS[:debug]
25
+ if debug?
22
26
  @out.puts(text)
23
27
  end
24
28
  end
@@ -1,5 +1,5 @@
1
1
  module Puppetserver
2
2
  module Ca
3
- VERSION = "1.10.0"
3
+ VERSION = "1.11.0"
4
4
  end
5
5
  end
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: 1.10.0
4
+ version: 1.11.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: 2021-07-06 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facter
@@ -100,6 +100,7 @@ files:
100
100
  - lib/puppetserver/ca/action/import.rb
101
101
  - lib/puppetserver/ca/action/list.rb
102
102
  - lib/puppetserver/ca/action/migrate.rb
103
+ - lib/puppetserver/ca/action/prune.rb
103
104
  - lib/puppetserver/ca/action/revoke.rb
104
105
  - lib/puppetserver/ca/action/setup.rb
105
106
  - lib/puppetserver/ca/action/sign.rb