puppetserver-ca 1.1.1 → 1.1.2
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
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 8ef4177b1921aaa80d30844823c81a28b3465c65
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e7e494cf9f9f93127cf0b693afeba8cedfcb8659
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 95c956f2395ff96c6e6108d3fb67441052fb7de89581427cdeacee0de73415a46633b5dedc113fa56200e84963e6e3255f84fc58c8cd5676044171673e45f5b2
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 66c067a3f40bc1d5c4c096bf5afb5eda563f8caebd431638a913f3ea26f797ecde05547a18864841755a779426d6003dc00f0d412940e53a643a08c21b0412b3
         
     | 
| 
         @@ -139,6 +139,8 @@ BANNER 
     | 
|
| 
       139 
139 
     | 
    
         | 
| 
       140 
140 
     | 
    
         
             
                      # Generate and save certs and associated keys
         
     | 
| 
       141 
141 
     | 
    
         
             
                      if input['ca-client']
         
     | 
| 
      
 142 
     | 
    
         
            +
                        # Refused to generate certs offfline if the CA service is running
         
     | 
| 
      
 143 
     | 
    
         
            +
                        return 1 if check_server_online(puppet.settings)
         
     | 
| 
       142 
144 
     | 
    
         
             
                        all_passed = generate_authorized_certs(certnames, alt_names, puppet.settings, signer.digest)
         
     | 
| 
       143 
145 
     | 
    
         
             
                      else
         
     | 
| 
       144 
146 
     | 
    
         
             
                        all_passed = generate_certs(certnames, alt_names, puppet.settings, signer.digest)
         
     | 
| 
         @@ -146,6 +148,31 @@ BANNER 
     | 
|
| 
       146 
148 
     | 
    
         
             
                      return all_passed ? 0 : 1
         
     | 
| 
       147 
149 
     | 
    
         
             
                    end
         
     | 
| 
       148 
150 
     | 
    
         | 
| 
      
 151 
     | 
    
         
            +
                    # Queries the simple status endpoint for the status of the CA service.
         
     | 
| 
      
 152 
     | 
    
         
            +
                    # Returns true if it receives back a response of "running", and false if
         
     | 
| 
      
 153 
     | 
    
         
            +
                    # no connection can be made, or a different response is received.
         
     | 
| 
      
 154 
     | 
    
         
            +
                    def check_server_online(settings)
         
     | 
| 
      
 155 
     | 
    
         
            +
                      status_url = HttpClient::URL.new('https', settings[:server], settings[:masterport], 'status', 'v1', 'simple', 'ca')
         
     | 
| 
      
 156 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 157 
     | 
    
         
            +
                        # Generating certs offline is necessary if the master cert has been destroyed
         
     | 
| 
      
 158 
     | 
    
         
            +
                        # or compromised. Since querying the status endpoint does not require a client cert, and
         
     | 
| 
      
 159 
     | 
    
         
            +
                        # we commonly won't have one, don't require one for creating the connection.
         
     | 
| 
      
 160 
     | 
    
         
            +
                        HttpClient.new(settings, with_client_cert: false).with_connection(status_url) do |conn|
         
     | 
| 
      
 161 
     | 
    
         
            +
                          result = conn.get
         
     | 
| 
      
 162 
     | 
    
         
            +
                          if result.body == "running"
         
     | 
| 
      
 163 
     | 
    
         
            +
                            @logger.err "CA service is running. Please stop it before attempting to generate certs offline."
         
     | 
| 
      
 164 
     | 
    
         
            +
                            true
         
     | 
| 
      
 165 
     | 
    
         
            +
                          else
         
     | 
| 
      
 166 
     | 
    
         
            +
                            false
         
     | 
| 
      
 167 
     | 
    
         
            +
                          end
         
     | 
| 
      
 168 
     | 
    
         
            +
                        end
         
     | 
| 
      
 169 
     | 
    
         
            +
                        true
         
     | 
| 
      
 170 
     | 
    
         
            +
                      rescue Errno::ECONNREFUSED => e
         
     | 
| 
      
 171 
     | 
    
         
            +
                        # Couldn't make a connection
         
     | 
| 
      
 172 
     | 
    
         
            +
                        false
         
     | 
| 
      
 173 
     | 
    
         
            +
                      end
         
     | 
| 
      
 174 
     | 
    
         
            +
                    end
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
       149 
176 
     | 
    
         
             
                    # Certs authorized to talk to the CA API need to be signed offline,
         
     | 
| 
       150 
177 
     | 
    
         
             
                    # in order to securely add the special auth extension.
         
     | 
| 
       151 
178 
     | 
    
         
             
                    def generate_authorized_certs(certnames, alt_names, settings, digest)
         
     | 
| 
         @@ -199,21 +226,38 @@ BANNER 
     | 
|
| 
       199 
226 
     | 
    
         | 
| 
       200 
227 
     | 
    
         
             
                        current_alt_names = process_alt_names(alt_names, certname)
         
     | 
| 
       201 
228 
     | 
    
         | 
| 
       202 
     | 
    
         
            -
                         
     | 
| 
       203 
     | 
    
         
            -
             
     | 
| 
       204 
     | 
    
         
            -
                         
     | 
| 
       205 
     | 
    
         
            -
                         
     | 
| 
       206 
     | 
    
         
            -
             
     | 
| 
       207 
     | 
    
         
            -
                          next false unless save_file(result.body, certname, settings[:certdir], "Certificate")
         
     | 
| 
       208 
     | 
    
         
            -
                          next false unless save_keys(certname, settings, key)
         
     | 
| 
      
 229 
     | 
    
         
            +
                        next false unless submit_csr(certname, ca, settings, digest, current_alt_names)
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
      
 231 
     | 
    
         
            +
                        # Check if the CA autosigned the cert
         
     | 
| 
      
 232 
     | 
    
         
            +
                        if download_cert(ca, certname, settings)
         
     | 
| 
      
 233 
     | 
    
         
            +
                          @logger.inform "Certificate for #{certname} was autosigned."
         
     | 
| 
       209 
234 
     | 
    
         
             
                          true
         
     | 
| 
       210 
235 
     | 
    
         
             
                        else
         
     | 
| 
       211 
     | 
    
         
            -
                          false
         
     | 
| 
      
 236 
     | 
    
         
            +
                          next false unless ca.sign_certs([certname])
         
     | 
| 
      
 237 
     | 
    
         
            +
                          download_cert(ca, certname, settings)
         
     | 
| 
       212 
238 
     | 
    
         
             
                        end
         
     | 
| 
       213 
239 
     | 
    
         
             
                      end
         
     | 
| 
       214 
240 
     | 
    
         
             
                      passed.all?
         
     | 
| 
       215 
241 
     | 
    
         
             
                    end
         
     | 
| 
       216 
242 
     | 
    
         | 
| 
      
 243 
     | 
    
         
            +
                    def submit_csr(certname, ca, settings, digest, alt_names)
         
     | 
| 
      
 244 
     | 
    
         
            +
                      key, csr = generate_key_csr(certname, settings, digest, alt_names)
         
     | 
| 
      
 245 
     | 
    
         
            +
                      return false unless csr
         
     | 
| 
      
 246 
     | 
    
         
            +
                      # Always save the keys, since soemtimes the server saves the CSR
         
     | 
| 
      
 247 
     | 
    
         
            +
                      # even when it returns a 400 (e.g. when the CSR contains alt names
         
     | 
| 
      
 248 
     | 
    
         
            +
                      # but the server isn't configured to sign such certs)
         
     | 
| 
      
 249 
     | 
    
         
            +
                      return false unless save_keys(certname, settings, key)
         
     | 
| 
      
 250 
     | 
    
         
            +
                      return false unless ca.submit_certificate_request(certname, csr)
         
     | 
| 
      
 251 
     | 
    
         
            +
                      true
         
     | 
| 
      
 252 
     | 
    
         
            +
                    end
         
     | 
| 
      
 253 
     | 
    
         
            +
             
     | 
| 
      
 254 
     | 
    
         
            +
                    def download_cert(ca, certname, settings)
         
     | 
| 
      
 255 
     | 
    
         
            +
                      if result = ca.get_certificate(certname)
         
     | 
| 
      
 256 
     | 
    
         
            +
                        return false unless save_file(result.body, certname, settings[:certdir], "Certificate")
         
     | 
| 
      
 257 
     | 
    
         
            +
                        true
         
     | 
| 
      
 258 
     | 
    
         
            +
                      end
         
     | 
| 
      
 259 
     | 
    
         
            +
                    end
         
     | 
| 
      
 260 
     | 
    
         
            +
             
     | 
| 
       217 
261 
     | 
    
         
             
                    # For certs signed offline, any alt names are added directly to the cert,
         
     | 
| 
       218 
262 
     | 
    
         
             
                    # rather than to the CSR.
         
     | 
| 
       219 
263 
     | 
    
         
             
                    def generate_key_csr(certname, settings, digest, alt_names = '')
         
     | 
| 
         @@ -41,7 +41,7 @@ module Puppetserver 
     | 
|
| 
       41 
41 
     | 
    
         
             
                                  body: SIGN_BODY,
         
     | 
| 
       42 
42 
     | 
    
         
             
                                  type: :sign)
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                    results.all? {|result| result == :success }
         
     | 
| 
      
 44 
     | 
    
         
            +
                    results.all? { |result| result == :success }
         
     | 
| 
       45 
45 
     | 
    
         
             
                  end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                  def revoke_certs(certnames)
         
     | 
| 
         @@ -50,7 +50,7 @@ module Puppetserver 
     | 
|
| 
       50 
50 
     | 
    
         
             
                                body: REVOKE_BODY,
         
     | 
| 
       51 
51 
     | 
    
         
             
                                type: :revoke)
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                    results.reduce {|prev, curr| worst_result(prev, curr) }
         
     | 
| 
      
 53 
     | 
    
         
            +
                    results.reduce { |prev, curr| worst_result(prev, curr) }
         
     | 
| 
       54 
54 
     | 
    
         
             
                  end
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
                  def submit_certificate_request(certname, csr)
         
     | 
| 
         @@ -60,7 +60,7 @@ module Puppetserver 
     | 
|
| 
       60 
60 
     | 
    
         
             
                                headers: {'Content-Type' => 'text/plain'},
         
     | 
| 
       61 
61 
     | 
    
         
             
                                type: :submit)
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
                    results.all? {|result| result == :success }
         
     | 
| 
      
 63 
     | 
    
         
            +
                    results.all? { |result| result == :success }
         
     | 
| 
       64 
64 
     | 
    
         
             
                  end
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
       66 
66 
     | 
    
         
             
                  # Make an HTTP PUT request to CA
         
     | 
| 
         @@ -15,12 +15,20 @@ module Puppetserver 
     | 
|
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                    attr_reader :store
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
                     
     | 
| 
      
 18 
     | 
    
         
            +
                    # Not all connections require a client cert to be present.
         
     | 
| 
      
 19 
     | 
    
         
            +
                    # For example, when querying the status endpoint.
         
     | 
| 
      
 20 
     | 
    
         
            +
                    def initialize(settings, with_client_cert: true)
         
     | 
| 
       19 
21 
     | 
    
         
             
                      @store = make_store(settings[:localcacert],
         
     | 
| 
       20 
22 
     | 
    
         
             
                                          settings[:certificate_revocation],
         
     | 
| 
       21 
23 
     | 
    
         
             
                                          settings[:hostcrl])
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                       
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                      if with_client_cert
         
     | 
| 
      
 26 
     | 
    
         
            +
                        @cert = load_cert(settings[:hostcert])
         
     | 
| 
      
 27 
     | 
    
         
            +
                        @key = load_key(settings[:hostprivkey])
         
     | 
| 
      
 28 
     | 
    
         
            +
                      else
         
     | 
| 
      
 29 
     | 
    
         
            +
                        @cert = nil
         
     | 
| 
      
 30 
     | 
    
         
            +
                        @key = nil
         
     | 
| 
      
 31 
     | 
    
         
            +
                      end
         
     | 
| 
       24 
32 
     | 
    
         
             
                    end
         
     | 
| 
       25 
33 
     | 
    
         | 
| 
       26 
34 
     | 
    
         
             
                    def load_cert(cert_path)
         
     | 
| 
         @@ -126,4 +134,4 @@ module Puppetserver 
     | 
|
| 
       126 
134 
     | 
    
         
             
                  end
         
     | 
| 
       127 
135 
     | 
    
         
             
                end
         
     | 
| 
       128 
136 
     | 
    
         
             
              end
         
     | 
| 
       129 
     | 
    
         
            -
            end
         
     | 
| 
      
 137 
     | 
    
         
            +
            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.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.1.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Puppet, Inc.
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2018- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-10-18 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: facter
         
     |