Skip to content
Snippets Groups Projects

Resolve "Handle intermediate CA"

Merged Fabien Combernous requested to merge 5-handle-sub-ca into main
9 files
+ 308
57
Compare changes
  • Side-by-side
  • Inline
Files
9
+ 63
0
 
# @summary A short summary of the purpose of this defined type.
 
#
 
# A description of what this defined type does
 
#
 
# @example
 
# cfssl::ca::intermediate { 'namevar': }
 
define cfssl::ca::intermediate (
 
Hash $subject = { 'C' => 'FR', 'L' => 'MONTPELLIER', 'O' => 'EXEMPLE ORG', },
 
String[1] $expiry = '26280h',
 
Cfssl::Ca::Key $key = { algo => 'rsa', size => 2048 },
 
) {
 
require cfssl::ca::root
 
 
$_rootca_name = regsubst($cfssl::ca::root::cn, '\s', '', 'G')
 
$_rootca_cert = "${cfssl::confdir}/ca/${_rootca_name}.pem"
 
$_rootca_privkey = "${cfssl::confdir}/ca/${_rootca_name}-key.pem"
 
 
$_intermediatecn = $name
 
$_intermediateca_name = regsubst($name, '\s', '', 'G')
 
$_intermediateca_csr = {
 
cn => $_intermediatecn,
 
names => [$subject],
 
key => $key,
 
}
 
$_intermediateca_csr_json = to_json($_intermediateca_csr)
 
 
$_root_to_intermediate_config = {
 
signing => {
 
'default' => {
 
expiry => $expiry,
 
ca_constraint => {
 
is_ca => true,
 
max_path_len => 1,
 
},
 
usages => [
 
'cert sign',
 
'crl sign',
 
],
 
},
 
},
 
}
 
$_root_to_intermediate_config_file = "${cfssl::confdir}/ca/root-to-intermediate-${_intermediateca_name}_config.json"
 
 
file { $_root_to_intermediate_config_file:
 
ensure => file,
 
mode => '0600',
 
owner => $cfssl::sysuser,
 
group => $cfssl::sysgroup,
 
content => to_json_pretty($_root_to_intermediate_config),
 
}
 
-> exec { "genkey ${_intermediatecn}":
 
path => "/usr/bin:${cfssl::binpath}",
 
command => "echo '${_intermediateca_csr_json}' | cfssl genkey - | cfssljson -bare ${cfssl::confdir}/ca/${_intermediateca_name}",
 
creates => "${cfssl::confdir}/ca/${_intermediateca_name}-key.pem",
 
user => $cfssl::sysuser,
 
}
 
-> exec { "${cfssl::ca::root::cn} sign ${_intermediatecn} csr":
 
path => "/usr/bin:${cfssl::binpath}",
 
command => "cfssl sign -ca ${_rootca_cert} -ca-key ${_rootca_privkey} -config ${_root_to_intermediate_config_file} ${cfssl::confdir}/ca/${_intermediateca_name}.csr | cfssljson -bare ${cfssl::confdir}/ca/${_intermediateca_name}",
 
creates => "${cfssl::confdir}/ca/${_intermediateca_name}.pem",
 
user => $cfssl::sysuser,
 
}
 
}
Loading