Giter VIP home page Giter VIP logo

puppet-openssl's Introduction

OpenSSL Puppet Module

Build Status Release Puppet Forge Puppet Forge - downloads Puppet Forge - endorsement Puppet Forge - scores puppetmodule.info docs AGPL v3 License Donated by Camptocamp

This module enables Puppet to manage PKI entities such as encryption keys, signing requests and X.509 certificates.

Setup

Include this module in a manifest:

contain openssl

By default, this will ensure OpenSSL and ca-certificates are installed.

Change the defaults to pin specific versions of the packages or keep them up to date:

class { 'openssl':
  package_ensure         => latest,
  ca_certificates_ensure => latest,
}

Usage

Create X.509 certificates

One of the most common use-cases is to generate a private key, a certificate signing request and issue a certificate. This can be done using the openssl::certificate::x509 defined type, e.g.:

openssl::certificate::x509 { 'hostcert':
  commonname => $facts['networking']['fqdn'],
}

This will create a series of resources, i.e. the private key in /etc/ssl/certs/hostcert.key, the certificate signing request in /etc/ssl/certs/hostcert.csr for the subject DN: CN=<fqdn> and the self-signed certificate stored in /etc/ssl/certs/hostcert.crt.

Note that openssl::certificate::x509 is a defined type that provides this abstract functionality by leveraging several other resources of the module, which are also available individually for more advanced use cases.

Create X.509 certificates from a hash

Include the openssl::certificates class in a node's manifest and set the certificates parameter - possibly via Hiera - to a hash of certificate definitions:

contain openssl::certificates
openssl::certificates:
  hostcert:
    commonname: "%{facts['networking']['fqdn']}"
  othercert:
    commonname: "other.example.com"
    owner: www-data

This will generate openssl::certificate::x509 instances for each key in the hash.

Export a key pair to PKCS#12

Use the openssl::export::pkcs12 defined type to generate a PKCS#12 file:

openssl::export::pkcs12 { 'foo':
  ensure   => 'present',
  basedir  => '/path/to/dir',
  pkey     => '/here/is/my/private.key',
  cert     => '/there/is/the/cert.crt',
  in_pass  => 'my_pkey_password',
  out_pass => 'my_pkcs12_password',
}

Export certificate(s) to PEM/x509 format

Use the openssl::export::pem_cert type to export PEM certificates from a pkcs12 container:

openssl::export::pem_cert { 'foo':
  ensure   => 'present',
  pfx_cert => '/here/is/my/certstore.pfx',
  pem_cert => '/here/is/my/cert.pem',
  in_pass  => 'my_pkcs12_password',
}

This definition exports PEM certificates from a DER certificate:

openssl::export::pem_cert { 'foo':
  ensure   => 'present',
  der_cert => '/here/is/my/certstore.der',
  pem_cert => '/here/is/my/cert.pem',
}

Export a key to PEM format

Use openssl::export::pem_key to export PEM key from a pkcs12 container:

openssl::export::pem_key { 'foo':
  ensure   => 'present',
  pfx_cert => '/here/is/my/certstore.pfx',
  pem_key  => '/here/is/my/private.key',
  in_pass  => 'my_pkcs12_password',
  out_pass => 'my_pkey_password',
}

Create Diffie-Hellman parameters

The openssl::dhparam defined type and its back-end resource type dhparam allow to generate Diffie-Hellman parameters.

Simple usage of the Puppet type:

dhparam { '/path/to/dhparam.pem': }

Advanced options:

dhparam { '/path/to/dhparam.pem':
  size => 2048,
}

Or alternatively, using the defined type:

openssl::dhparam { '/path/to/dhparam.pem': }

which is equivalent to:

openssl::dhparam { '/path/to/dhparam.pem':
  ensure => 'present',
  size   => 512,
  owner  => 'root',
  group  => 'root',
  mode   => '0644',
}

Advanced usage:

openssl::dhparam { '/path/to/dhparam.pem':
  ensure => 'present',
  size   => 2048,
  owner  => 'www-data',
  group  => 'adm',
  mode   => '0640',
}

Create a private key

Using the ssl_pkey type allows to generate SSL private keys.

Note, that the private key is not encrypted by default1.

Simple usage:

ssl_pkey { '/path/to/private.key': }

Advanced options:

ssl_pkey { '/path/to/private.key':
  ensure   => 'present',
  password => 'j(D$',
}

Create a certificate signing request

The x509_request type allows to generate SSL certificate signing requests from a private key. You need to deploy an OpenSSL configuration file containing a section for the request engine and reference it in template. You manage configuration files using the openssl::config defined type.

Simple usage:

x509_request { '/path/to/request.csr': }

Advanced options:

x509_request { '/path/to/request.csr':
  ensure      => 'present',
  password    => 'j(D$',
  template    => '/other/path/to/template.cnf',
  private_key => '/there/is/my/private.key',
  force       => false,
  subscribe   => '/other/path/to/template.cnf',
}

Create a certificate

Using the x509_cert type allows to generate SSL certificates. The default provider to this type can create self-signed certificates or use a certification authority - also deployed on the same host - to sign the certificate signing request.

Simple usage:

x509_cert { '/path/to/certificate.crt': }

Advanced options:

x509_cert { '/path/to/certificate.crt':
  ensure      => 'present',
  password    => 'j(D$',
  template    => '/other/path/to/template.cnf',
  private_key => '/there/is/my/private.key',
  days        => 4536,
  force       => false,
  subscribe   => '/other/path/to/template.cnf',
}

Get a certificate from a remote source

The cert_file type controls a file containing a serialized X.509 certificate. It accepts the source in either PEM or DER format and stores it in the desired serialization format to the file.

cert_file { '/path/to/certs/cacert_root1.pem':
  ensure => present,
  source => 'http://www.cacert.org/certs/root_X0F.der',
  format => pem,
}

Attributes:

  • path (namevar): path to the file where the certificate should be stored
  • ensure: present or absent
  • source: the URL the certificate should be downloaded from
  • format: the storage format for the certificate file (pem or der)

Functions

Accessing the CA issuers URL from a certificate

If a certificate contains the authorityInfoAccess extension, the openssl::cert_aia_caissuers function can be used to parse hte certificate for the authorityInfoAccess extension and return with the URL found as caIssuers, or nil if no URL or extension found. Invoking as deferred function, this can be used to download the issuer certificate:

  file { '/ssl/certs/caissuer.crt':
    ensure => file,
    source => Deferred('openssl::cert_aia_caissuers', ["/etc/ssl/certs/${facts['networking']['fqdn']}.crt"]),
  }

Contributing

Please report bugs and feature request using GitHub issue tracker.

For pull requests, it is very much appreciated to check your Puppet manifest with puppet-lint to follow the recommended Puppet style guidelines from the Puppet Labs style guide.

Transfer Notice

This plugin was originally authored by Camptocamp. The maintainer preferred that Puppet Community take ownership of the module for future improvement and maintenance. Existing pull requests and issues were transferred over, please fork and continue to contribute here instead of Camptocamp.

Previously: https://github.com/camptocamp/puppet-openssl

Footnotes

  1. In every case, not providing the password (or setting it to undef, which is the default) means that the private key won't be encrypted with any symmetric cipher so it is protected by filesystem access mode only. โ†ฉ

puppet-openssl's People

Contributors

bandwith avatar bastelfreak avatar cjeanneret avatar ckaenzig avatar coreone avatar edestecd avatar fabbks avatar foonix avatar gaima8 avatar jcpunk avatar josephholsten avatar kenyon avatar kronos-pbrideau avatar mcanevet avatar mikerenfro avatar olavmrk avatar pataquets avatar raphink avatar robbat2 avatar rpasing avatar rtib avatar runejuhl avatar saimonn avatar sliim avatar smortex avatar trefzer avatar trentl avatar treydock avatar tylerwalts avatar zilchms avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppet-openssl's Issues

creating a cert doesn't include altnames

I'm creating a self-signed cert with openssl::certificate::x509, like so:

 ssl_prefix => 'ukprd'
 servicename => "uk.example.com",
 altnames   => ['uk.example.com','server.example.co.uk'],

then using:

 openssl::certificate::x509 { "${ssl_prefix}":
    ensure       => present,
    country      => 'GB',
    organization => 'My Company Ltd',
    commonname   => "$servicename",
    state        => 'London',
    locality     => 'London',
    unit         => 'Engineering',
    altnames     => $altnames,
    email        => '[email protected]',
    days         => 3650,
    base_dir     => "/www/${name}/ssl",
    owner        => 'root',
    password     => "$ssl_pass",
    force        => false,
 }

and in the resulting CSR, I see everything as it should be:

$ openssl req -text -noout -in ./server.example.com/ssl/ukprd.csr
Certificate Request:
  Data:
    Version: 0 (0x0)
    Subject: C=GB, ST=London, L=London, O=My Company Ltd, OU=Engineering, CN=uk.example.com/[email protected]
...
    Attributes:
    Requested Extensions:
        X509v3 Subject Alternative Name: 
            DNS:uk.example.com, DNS:server.example.co.uk
...

(as per the generated ukprd.cnf OpenSSL configuration file)

but the created certificate doesn't include those alternative names:

$ openssl x509 -text -in ./server.example.com/ssl/ukprd.crt -noout

Certificate:
   Data:
       Version: 1 (0x0)
       Serial Number:
           99:57:4b:c4:5c:7c:99:e6
       Signature Algorithm: sha1WithRSAEncryption
       Issuer: C=GB, ST=London, L=London, O=My Company Ltd, OU=Engineering, CN=uk.example.com/[email protected]
...
       Subject: C=GB, ST=London, L=London, O=My Company Ltd, OU=Engineering, CN=uk.example.com/[email protected]
...

RFE: Allow DER certs to be converted to PEM format

At time certs come in DER format which is generally unusable for Unix environments. Being able to convert them to PEM using automation would allow internally signed certs from AD cert manager to seemly make its way into unix/linux environments.

Regenerate dhparams if the key size has changed

If the โ€˜sizeโ€™ of the resource has changed, new dhparams should be generated.

Why? Given the logjam vulnerability and to prevent regression in the event of a dhparams file being manually overwritten.

This would work nicely for the case where the user, having managed their dhparams via this lovely puppet module (like myself), needs to upgrade a whole bunch of dhparams in one goโ€ฆ

Similarly, since regenerating based on size will require puppet to parse a dhparams file I think it would also make sense for an invalid /corrupted dhparams file to be regenerated.

I've done a little experimentation so far making the type use size as a property and get the following:

Given a dhparam managed like this in puppet

dhparam { '/tmp/dhparam.pem':
    size   => 2048,
}

and then overriding it:

openssl dhparam -out /tmp/dhparam.pem 16

I get the following:

Notice: /Stage[main]/Openssl/Dhparam[/tmp/dhparam.pem]/size: size changed '16' to '2048'
Notice: Applied catalog in 46.97 seconds

similarly for a file that is not a valid dhparams :

Notice: /Stage[main]/Openssl/Dhparam[/tmp/dhparam.pem]/size: size changed '' to '2048'
Notice: Applied catalog in 67.06 seconds

No way to set desired openssl package version

May I suggest adding an $ensure paramter similar to:

class openssl (
  $package_ensure => present,
){
}

class openssl::packages {
  package { 'openssl':
    ensure => $openssl::package_ensure,
  }
}

If no one has any objection, I will make the change and submit a pull request.

Any thoughts?

Wrong command called

Hello,

your module calls /usr/local/sbin/generate-ssl-cert.sh but /usr/local/sbin/generate-x509-cert.sh is the correct name.

Regards.

Bug/Maintenance in/for configuration templates

This is a bug report and a discussion (hopefully) at the same time.
This module offers 2 templates (one .erb and one .epp) for configurations and a parameter in the certificate::x509 class to change the configuration file to be used (defaults to: openssl/cert.cnf.erb). This works perfectly fine as long as one uses the .erb template. However as soon as someone wants to change the path-parameter to use the cert.cnf.epp template instead, syntax errors occure. This is caused by the use of the template function (which does not allow epp template files; the appropriate function for epp-templates would be epp() ).

This bug could surely be fixed by specialcasing based on the file-ending or similar means, but in my opinion this doesnt tackle the underlying issue of how the configuration file is managed. Is there a reason to allow users to exchange templates accross modules?
In my opinion this is bad practice and should someone need a very custom configuration file, we should either expand our template to be generic enough for all use-cases, or the user can generate this file themselfes and pass it through the cnf parameter of the same class. Albeit I am not sure if there should be a check added to only manage the cnf file if the cnf-parameter is empty.
At the same time it seems the templates have diverged in their features and functionalities, this is bad for maintainability.

In my opinion the steps to correct this bug and improve maintainability, we should merge the features of the two templates into one template (probably best done in one .epp template), use the correct function for rendering the template and possibly get rid of the cnf_tpl parameter as cross referencing templates from other modules seems wrong on a very basic level.

In the end there should only exist one template (that provides all functionalities/configuration options a user needs) and all features someone suggest get added to this one template to ensure this is maintainable.

Maybe a maintainer can provide some thoughts, if this would be appreciated? I can provide code/tests and documentation should the changes be wanted.

dhparam doesn't work without 'ensure'

This doesn't create the file unless ensure is uncommented, which should be the default operation.

dhparam { '/etc/openvpn/dh2048.pem': 
    size         => 2048,
    require    => Package['openvpn'],
    # ensure => 'present'    
 }

Generating pkcs12 Certificate

I am trying to generate a pkcs12 certificate for Tomcat. The private key is password protected.

The export command fails because a prompt is asking for the private key password which is not supplied (see 'User interface error' below)

pkcs12.pp needs to use the -passin option to decrypt the private key (see https://www.openssl.org/docs/apps/pkcs12.html).

Notice: /Stage[main]/Profile::Tomcat/Certificate::Pkcs12[tomcat.self.signed]/Openssl::Export::Pkcs12[tomcat.self.signed]/Exec[Export tomcat.self.signed to /var/www/ssl/tomcat.self.signed.p12]/returns: Enter pass phrase for /var/www/ssl/tomcat.self.signed.key:
Notice: /Stage[main]/Profile::Tomcat/Certificate::Pkcs12[tomcat.self.signed]/Openssl::Export::Pkcs12[tomcat.self.signed]/Exec[Export tomcat.self.signed to /var/www/ssl/tomcat.self.signed.p12]/returns: User interface error
Notice: /Stage[main]/Profile::Tomcat/Certificate::Pkcs12[tomcat.self.signed]/Openssl::Export::Pkcs12[tomcat.self.signed]/Exec[Export tomcat.self.signed to /var/www/ssl/tomcat.self.signed.p12]/returns: unable to load private key
Notice: /Stage[main]/Profile::Tomcat/Certificate::Pkcs12[tomcat.self.signed]/Openssl::Export::Pkcs12[tomcat.self.signed]/Exec[Export tomcat.self.signed to /var/www/ssl/tomcat.self.signed.p12]/returns: 139988079081120:error:0906A068:PEM routines:PEM_do_header:bad password read:pem_lib.c:458:
Notice: /Stage[main]/Profile::Tomcat/Certificate::Pkcs12[tomcat.self.signed]/Openssl::Export::Pkcs12[tomcat.self.signed]/Exec[Export tomcat.self.signed to /var/www/ssl/tomcat.self.signed.p12]/returns: unable to write 'random state'
Error: openssl pkcs12 -export -in /var/www/ssl/tomcat.self.signed.crt -inkey /var/www/ssl/tomcat.self.signed.key -out /var/www/ssl/tomcat.self.signed.p12 -name tomcat.self.signed -nodes -noiter -passout pass:9hC9X9Sn4Tew returned 1 instead of one of [0]
Error: /Stage[main]/Profile::Tomcat/Certificate::Pkcs12[tomcat.self.signed]/Openssl::Export::Pkcs12[tomcat.self.signed]/Exec[Export tomcat.self.signed to /var/www/ssl/tomcat.self.signed.p12]/returns: change from notrun to 0 failed: openssl pkcs12 -export -in /var/www/ssl/tomcat.self.signed.crt -inkey /var/www/ssl/tomcat.self.signed.key -out /var/www/ssl/tomcat.self.signed.p12 -name tomcat.self.signed -nodes -noiter -passout pass:9hC9X9Sn4Tew returned 1 instead of one of [0]

Error "failure to load inifile" resulting in failed Puppet run

While working on the manifests for one of my servers, I started getting errors, seemingly out of nowhere:

Error: Could not run Puppet configuration client: cannot load such file -- inifile
Error: Could not run: can't convert Puppet::Util::Log into Integer

A little searching suggested that this might be a missing gem. Once I added it, things started working again:

bshacklett@[redacted]:/etc/postfix$ sudo gem install inifile
Fetching: inifile-3.0.0.gem (100%)
Successfully installed inifile-3.0.0
1 gem installed
Installing ri documentation for inifile-3.0.0...
Installing RDoc documentation for inifile-3.0.0...
bshacklett@[redacted]:/etc/postfix$ sudo puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for [redacted]
Info: Applying configuration version '1458314904'
Notice: Finished catalog run in 0.35 seconds

Does the module handle the installation of this gem? If not, how is it supposed to be installed? It seems odd that it was working, then stopped out of nowhere and required that the gem be installed manually.

Dead code

I was reviewing the below code, because of suspected failing its purpose:

ini_file = Puppet::Util::IniConfig::PhysicalFile.new(resource[:template])
if (req_ext = ini_file.get_section('req_ext'))
if (value = req_ext['subjectAltName']) && (value.delete(' ').gsub(%r{^"|"$}, '') != alt_name.delete(' ').gsub(%r{^"|"$}, '').gsub('IPAddress', 'IP'))
return false
end
elsif (req_dn = ini_file.get_section('req_distinguished_name'))
if (value = req_dn['commonName']) && (value != cdata['CN'])
return false
end
end

My analysis unveiled, that neither the if nor the elsif branches are ever executed. This is because the ini_file's initialize method does not read and parse the file itself, thus each call to its get_section method is returning nil.

An instance of Puppet::Util::IniConfig::PhysicalFile would need the invocation of its read method to read and parse the file, but that's never happen. Using this class to parse an OpenSSL config file constructed by this module's templates/cert.cnf.epp would, however, end up raising IniParseError with the message Property with key HOME outside of a section from puppet/util/inifile.rb#L185. AFAIK, there is no specification for the format of ini files, however, Microsoft and OpenSSL seem to treat them differently. Nevertheless, Puppet::Util::IniConfig::PhysicalFile.parse method does not support keys before the first section header, thus it seems not suitable for parsing OpenSSL style config files.

In that sense the old_cert_is_equal method of the x509_cert openssl provider would need to be reviewed.

Request for ability to create unencrypted private key

OpenLDAP unfortunately does not like encrypted private keys. As it stands, the current output generates encrypted keys always as it directly uses the ruby SSL calls. Interestingly, the PKCS12 export uses the commandline with the -nodes option, which is what we need for the ssl_pkey creation as well.

Ideally, I'd like to have a flag on ssl_pkey and the openssl::certificate::x509 that allows us to turn encryption off.

openssl_version fact resolves to nil

Problem description

The custom fact openssl_version resolves to nil:

/opt/puppetlabs/bin/facter -p -d --no-color 2>&1 | grep openssl
[2021-12-29 00:12:43.868917 ] DEBUG Facter::Core::Execution::Posix - Executing command: /bin/openssl version 2>&1 
[2021-12-29 00:12:43.891068 ] DEBUG Facter::Util::Fact - value for openssl_version is still nil 

Environment

voxpupuli/puppet-openssl 2.0.0

CentOS 8.5.2111
Puppet Agent 7.13.1
Facter 4.2.6

$ /bin/openssl version
OpenSSL 1.1.1k  FIPS 25 Mar 2021

Additional context

AFAICT this issue should not exist, it was resolved in 5fe38f9 but still doesn't work for me.

Errors with inifile 3.0

Error: Could not run Puppet configuration client: /usr/lib/ruby/gems/1.8/gems/inifile-3.0.0/lib/inifile.rb:558: undefined (?...) sequence: /\A"(.*)(?<!\\)"\z/

This is on the current HEAD.

feature request: manage certificate authority and allow signing certs with a CA

If I interpret this correctly, in #39 there have been attempts made to generate and manage a CA.
However, as the original pull request was closed by the original author without apparent reason, there is currently no way to create and manage a CA and generate certificates signed by the managed CA (or any CA for that matter).

I would like to push a discussion, if this is a feature that is wanted/planned as well as find some pointers on how we could implement this. I have thus far looked into the module and roughly understood how it works. Unfortunately I dont think I have the necessary knowledge yet to implement a fitting solution.

Additionally I think, this could be split into several features:

  • Generate a CA
  • Manage a CA (can be coupled with the generation)
  • Allow the possibility to sign certs against an existing CA file (this i think can be done independently of the other features)

Any comments, pointers and help in general is very appreciated :)

Add "fastmode" for dhparam generation

dhparam generation can be quite time expensive but openssl provides a flag for faster generation named -dsaparam
details on https://security.stackexchange.com/a/95184

the following code is just quick test implementation:

define openssl::dhparam(
  $path,
  $ensure = present,
  $size = 512,
  $owner = 'root',
  $group = 'root',
  $mode = '0644',
  $fastmode = true,
) {

  validate_absolute_path($path)
  validate_re($ensure, '^(present|absent)$',
    "\$ensure must be either 'present' or 'absent', got '${ensure}'")
  validate_integer($size, '', 1) # positive integer
  validate_string($owner)
  validate_string($group)
  validate_string($mode)

  dhparam { $path:
    ensure => $ensure,
    size   => $size,
    fastmode => $fastmode,
  }

  # Set file access
  file { $path:
      ensure  => $ensure,
      owner   => $owner,
      group   => $group,
      mode    => $mode,
      require => Dhparam[$path];
  }
}
require 'pathname'
Puppet::Type.newtype(:dhparam) do
  desc 'A Diffie Helman parameter file'

  ensurable

  newparam(:path, :namevar => true) do
    validate do |value|
      path = Pathname.new(value)
      unless path.absolute?
        raise ArgumentError, "Path must be absolute: #{path}"
      end
    end
  end


  newparam(:size) do
    desc 'The key size'
    newvalues /\d+/
    defaultto 512
    validate do |value|
      size = value.to_i
      if size <= 0 || value.to_s != size.to_s
        raise ArgumentError, "Size must be a positive integer: #{value.inspect}"
      end
    end
  end

  newparam(:fastmode) do
    desc 'Enable fast mode'
    defaultto false
    #validate do |value|
      #size = value.to_i
      #if size <= 0 || value.to_s != size.to_s
      #  raise ArgumentError, "Size must be a positive integer: #{value.inspect}"
      #end
    #end
  end
end
require 'pathname'
Puppet::Type.type(:dhparam).provide(:openssl) do
  desc 'Manages dhparam files with OpenSSL'

  commands :openssl => 'openssl'

  def exists?
    Pathname.new(resource[:path]).exist?
  end

  def create
    if resource[:fastmode]
        fastmode="-dsaparam"
    else
        fastmode=""
    end


    options = [
      'dhparam',
      fastmode,
      '-out', resource[:path],
      resource[:size]
    ]
    openssl options
  end

  def destroy
    Pathname.new(resource[:path]).delete
  end
end

feature request: make keys and certificates exportable

It would be nice if this module allows users to export signed certificates and import them on other hosts.
For example: define and export a certificate on host1, then import and realize the certificate on host2
Right now the contents of the certificate are created life on the importing host (making the contents of the certificate different than they are on the exported host).

I have no idea if this is even possible. My guess is this would need some work in the cert/key providers, if this even at all possible in puppet.

Replace expired certificate?

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 7.24.0
  • Ruby:
  • Distribution: CentOS Stream 9
  • Module version: 2.0.1

How to reproduce (e.g Puppet code you use)

class { '::openssl::certificate':
     x509_certs => { '/path/to/certificate.crt' => {  ensure      => 'present',
                                                      password    => 'j(D$',
                                                      private_key => '/there/is/my/private.key',
                                                      days        => 4,
                                                      force       => false,}
                    }
}

What are you seeing

When the certificate expires, puppet doesn't appear to care

What behaviour did you expect instead

When the certificate expires, a new cert would be generated from the private key

Output log

Any additional information you'd like to impart

Can't add SAN records

I just wanted to create single certificate for multiple domains, but that feature doesn't seem to work.

My Puppet manifest:

openssl::certificate::x509 { 'test1':
  country      => 'US',
  organization => 'Dev',
  commonname   => 'domain.tld',
  altnames     => ['anotherdomain.tld', 'subdomain.domain.tld'],
}

Created certificate contains domain.tld as "Common Name", but there are no records about SAN (Subject Alternative Names).

feature request: function to read certificate expiration date

It would be good to have a function to read certificate expiration date.

My use case would be along these lines:

  • if certificate expires more than X days in the future, do nothing
  • if it expires less than or equal to X days in the future, notify an exec that would delete the certificate file and its key
  • then openssl::certificate::x509 (which I'd mark to require the exec before it, to force correct ordering) would simply re-generate a new key and a new cert
  • then anything subscribing openssl::certificate::x509 would take care of application reloads and the like

dhparam generation fails

How to reproduce:

  1. setup clear ubuntu 14.04 (for me docker was good enough)
  2. setup puppet, default version in 14.04 is 3.4.3, but seems this error can be reproduced on any puppet version
    apt-get install puppet
  3. install module
    puppet module install camptocamp-openssl
  4. run puppet apply
    puppet apply -e "dhparam { '/tmp/dhparam.pem': ensure => present, size => 2048 }" --modulepath=/etc/puppet/modules --verbose
  5. receive following message:
    Error: Parameter size failed on Dhparam[/tmp/dhparam.pem]: comparison of String with 0 failed at line 1 Wrapped exception: comparison of String with 0 failed

x509_request doesn't handle refresh

x509_request doesn't implement a refresh function, so you can't notify it or subscript it to the .cnf file. On refresh the CSR file should be created again.

Puppet 4 failure at x509

Puppet 4 has more strict typing, and certain params fail to validate.

2016-04-11 19:33:52,886 ERROR [puppet-server] Puppet Evaluation Error: Error while evaluating a Function Call, validate_re(): input needs to be a String, not a Fixnum
2016-04-11 19:33:53,132 ERROR [puppet-server] Puppet Evaluation Error: Error while evaluating a Function Call, 0 is not a string.  It looks to be a Fixnum
2016-04-11 19:33:53,133 ERROR [puppet-server] Puppet Evaluation Error: Error while evaluating a Function Call, 0 is not a string.  It looks to be a Fixnum at /etc/puppet/environments/production/modules/openssl/manifests/certificate/x509.pp:144:3 on node box.domain.com
2016-04-11 19:33:53,133 ERROR [puppet-server] Puppet Evaluation Error: Error while evaluating a Function Call, 0 is not a string.  It looks to be a Fixnum

ssl_pkey should default to ensure=>present

As of version v1.10.0,

ssl_pkey { '/path/to/private.key': }

does not create a private key but

ssl_pkey { '/path/to/private.key':
  ensure => 'present',
}

does. ensure => present should be the default.

Parameters for openssl.cnf

Hello,

Would you please make openssl config parameters accessible via class parameters? This would allow us to use hiera to manage parameters more gracefully than with individual template files.

stdlib 9 support

Please add support for stdlib 9 (or add <10.0.0 as upper boundry).

RANDFILE not correct on ubuntu 12.04.04

RANDFILE has an incorrect value ($ENV::HOME) on ubuntu 12.04.04.

Steps to reproduce the bug:

  • Using current RANDFILE value ($ENV::HOME) on Ubuntu 12.04.04, openssl version 1.0.1-4ubuntu3
  • Apply the following manifest:
  openssl::certificate::x509 { 'test.example.com':
    ensure       => present,
    country      => 'ES',
    organization => 'example.com',
    commonname   => $fqdn,
    base_dir     => '/tmp',
    owner        => 'root',
    password     => 'fake',
  }

Current behaviour:

  • The following error is shown:
Error: Execution of '/usr/bin/openssl req -new -key /tmp/test.example.com -config /tmp/mail.awsdev.netquestapps.com.cnf -out /tmp/test.example.com.csr -passin pass:fake' returned 1: error on line 6 of /tmp/test.example.com.cnf
139940285789856:error:0E065068:configuration file routines:STR_COPY:variable has no value:conf_def.c:618:line 6

Expected behaviour:

  • Certificates should be generated.

Way to fix the bug:

  • Use absolute path (using /root/.rnd fixes the bug)

Configure top-level class?

Let's say that we have a separate tool for managing certificates (Comodo Certificate Manager in our case) and that we want to manage our openssl.cnf independently of any specific certificate we generate. Being able to configure the top-level class in this way would be exceptionally helpful, especially for setting package versions or site-wide options. I suppose that this could be done within the context of a private key (SSL's useless without one), but being able to configure the overall class and not just individual keys/csrs/ certs would be valuable.

No password on openssl::export::pkcs12 not working as expected

The default of false for out_pass does not work.

Per this, you need to specify a blank password to get no password.
This is our experience as well.
http://stackoverflow.com/questions/27497723/export-a-pkcs12-file-without-an-export-password

A current workaround is to set

out_pass => ''

However this is not a permanent solution and the default should really work.

I think this code should fix it:

      $passout_opt = $out_pass ? {
        false   => '-passout pass:',
        default => "-passout pass:${out_pass}",
      }

Readme for dhparam wrong?

according the readme the following should work:

dhparam { '/path/to/dhparam.pem': }
dhparam { '/path/to/dhparam.pem':
  size => 2048,
}

but looking at the code $path is not set to $name by default. so the code has to be changed like this:

define openssl::dhparam(
  $path = $name,
  ...
) {

or the readme should be changed:

dhparam { 'mainfile': path => '/path/to/dhparam.pem': }
dhparam { 'mainfile':
  path => '/path/to/dhparam.pem'
  size => 2048,
}

openssl_version fact resolves to nil

  • Puppet: 6.28.0
  • Ruby: ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]
  • Distribution: Rocky Linux release 8.6
  • Module version: 2.0.1
[root@server ~]# cat /etc/rocky-release
Rocky Linux release 8.6 (Green Obsidian)
[root@server ~]# facter -p openssl_version

[root@server ~]# openssl version
OpenSSL 1.1.1k  FIPS 25 Mar 2021

Using the regex found in the fact code:

irb(main):001:0> a = 'OpenSSL 1.1.1k  FIPS 25 Mar 2021'
=> "OpenSSL 1.1.1k  FIPS 25 Mar 2021"
irb(main):002:0> b = %r{^OpenSSL ([\w.\-]+)( FIPS)?( +)([\d.]+)( +)([\w.]+)( +)([\d.]+)}.match(a)
=> nil

I did further testing, and it seems it starts failing at [w.\-]. To me, it doesn't look like [\w.\-]+ will match 1.1.1k, even though for some reason it does work on CentOS 7.9 with "OpenSSL 1.0.2k-fips".

For me, this seems work better:
(Focussing on the version substring and "fips" parts, with OpenSSL version strings found on Rocky Linux 8.6 and CentOS 7.9)

irb(main):001:0> a = 'OpenSSL 1.1.1k  FIPS 25 Mar 2021'
=> "OpenSSL 1.1.1k  FIPS 25 Mar 2021"
irb(main):002:0> b = %r{ \d.\d.\d\w?([\s]+|\-)(fips|FIPS)?}.match(a)
=> #<MatchData " 1.1.1k  FIPS" 1:"  " 2:"FIPS">
irb(main):003:0> b[0].strip() if b
=> "1.1.1k  FIPS"

irb(main):011:0> c = 'OpenSSL 1.0.2k-fips  26 Jan 2017'
=> "OpenSSL 1.0.2k-fips  26 Jan 2017"
irb(main):012:0> d = %r{ \d.\d.\d\w?([\s]+|\-)(fips|FIPS)?}.match(c)
=> #<MatchData " 1.0.2k-fips" 1:"-" 2:"fips">
irb(main):013:0> d[0].strip() if d
=> "1.0.2k-fips"

I'm by no means a Ruby nor regex expert, and I'm only improvising with the regex currently present in the fact. Therefore, I'm hesitant to create a PR, because I'm unsure if it will work correctly in all cases. But, maybe this helps.

Move on from puppet6

So, this module needs a few things to bring it up to standard. As puppet6 is EOL, puppet7 being the default standard right now and puppet8 release just happened, this module needs to migrate upwards.

Steps:

  • First enable puppet7 support additionally to puppet6 (migration version)
  • Then drop support for puppet6
  • Then maybe add support for puppet8

bastelfreak did some things with modulesync here:
#139 and #160 but the CI seems to not like any of it; #139 CI run is too old to have logs, so we might want to rerun the workflow or open a new PR

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.