Skip to content

Commit a38c6ad

Browse files
authored
Merge commit from fork
Send passwords via environment variables
2 parents d89062c + 25df787 commit a38c6ad

File tree

6 files changed

+58
-30
lines changed

6 files changed

+58
-30
lines changed

lib/puppet/provider/x509_cert/openssl.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def exists?
5757
end
5858

5959
def create
60+
env = {}
61+
6062
if resource[:csr]
6163
options = [
6264
'x509',
@@ -92,9 +94,12 @@ def create
9294

9395
password = resource[:cakey_password] || resource[:password]
9496

95-
options << ['-passin', "pass:#{password}"] if password
97+
if password
98+
options << ['-passin', 'env:CERTIFICATE_PASSIN']
99+
env['CERTIFICATE_PASSIN'] = password
100+
end
96101
options << ['-extensions', 'v3_req'] if resource[:req_ext] != :false
97-
openssl options
102+
openssl options, environment: env
98103
end
99104

100105
def destroy

lib/puppet/provider/x509_request/openssl.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@ def exists?
2828
end
2929

3030
def create
31+
env = {}
3132
options = [
3233
'req', '-new',
3334
'-key', resource[:private_key],
3435
'-config', resource[:template],
3536
'-out', resource[:path]
3637
]
3738

38-
options << ['-passin', "pass:#{resource[:password]}"] if resource[:password]
39+
if resource[:password]
40+
options << ['-passin', 'env:CERTIFICATE_PASSIN']
41+
env['CERTIFICATE_PASSIN'] = resource[:password]
42+
end
3943
options << ['-nodes'] unless resource[:encrypted]
4044

41-
openssl options
45+
openssl options, environment: env
4246
end
4347

4448
def destroy

manifests/export/pem_cert.pp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@
4444
$in_cert = $pfx_cert
4545
}
4646

47-
$passin_opt = $in_pass ? {
48-
undef => [],
49-
default => ['-nokeys', '-passin', "pass:${in_pass}"],
47+
if $in_pass {
48+
$passin_opt = ['-nokeys', '-passin', 'env:CERTIFICATE_PASSIN']
49+
$passin_env = ["CERTIFICATE_PASSIN=${in_pass}"]
50+
} else {
51+
$passin_opt = []
52+
$passin_env = []
5053
}
5154

5255
if $ensure == 'present' {
@@ -62,9 +65,10 @@
6265
}
6366

6467
exec { "Export ${in_cert} to ${pem_cert}":
65-
command => $cmd,
66-
path => $facts['path'],
67-
* => $exec_params,
68+
command => $cmd,
69+
environment => $passin_env
70+
path => $facts['path'],
71+
* => $exec_params,
6872
}
6973
} else {
7074
file { $pem_cert:

manifests/export/pem_key.pp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@
2525
Optional[String] $out_pass = undef,
2626
) {
2727
if $ensure == 'present' {
28-
$passin_opt = $in_pass ? {
29-
undef => [],
30-
default => ['-passin', "pass:${in_pass}"],
28+
if $in_pass {
29+
$passin_opt = ['-nokeys', '-passin', 'env:CERTIFICATE_PASSIN']
30+
$passin_env = ["CERTIFICATE_PASSIN=${in_pass}"]
31+
} else {
32+
$passin_opt = []
33+
$passin_env = []
3134
}
3235

33-
$passout_opt = $out_pass ? {
34-
undef => ['-nodes'],
35-
default => ['-passout', "pass:${out_pass}"],
36+
if $out_pass {
37+
$passout_opt = ['-nokeys', '-passout', 'env:CERTIFICATE_PASSOUT']
38+
$passout_env = ["CERTIFICATE_PASSOUT=${out_pass}"]
39+
} else {
40+
$passout_opt = []
41+
$passout_env = []
3642
}
3743

3844
$cmd = [
@@ -52,9 +58,10 @@
5258
}
5359

5460
exec { "Export ${pfx_cert} to ${pem_key}":
55-
command => $cmd,
56-
path => $facts['path'],
57-
* => $exec_params,
61+
command => $cmd,
62+
environment => $passin_env + $passout_env,
63+
path => $facts['path'],
64+
* => $exec_params,
5865
}
5966
} else {
6067
file { $pem_key:

manifests/export/pkcs12.pp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,20 @@
3333
$full_path = "${basedir}/${name}.p12"
3434

3535
if $ensure == 'present' {
36-
$pass_opt = $in_pass ? {
37-
undef => [],
38-
default => ['-passin', "pass:${in_pass}"],
36+
if $in_pass {
37+
$passin_opt = ['-nokeys', '-passin', 'env:CERTIFICATE_PASSIN']
38+
$passin_env = ["CERTIFICATE_PASSIN=${in_pass}"]
39+
} else {
40+
$passin_opt = []
41+
$passin_env = []
3942
}
4043

41-
$passout_opt = $out_pass ? {
42-
undef => [],
43-
default => ['-passout', "pass:${out_pass}"],
44+
if $out_pass {
45+
$passout_opt = ['-nokeys', '-passout', 'env:CERTIFICATE_PASSOUT']
46+
$passout_env = ["CERTIFICATE_PASSOUT=${out_pass}"]
47+
} else {
48+
$passout_opt = []
49+
$passout_env = []
4450
}
4551

4652
$chain_opt = $chaincert ? {
@@ -55,7 +61,7 @@
5561
'-out', $full_path,
5662
'-name', $name,
5763
'-nodes', '-noiter',
58-
] + $chain_opt + $pass_opt + $passout_opt
64+
] + $chain_opt + $passin_opt + $passout_opt
5965

6066
if $dynamic {
6167
$exec_params = {
@@ -67,9 +73,10 @@
6773
}
6874

6975
exec { "Export ${name} to ${full_path}":
70-
command => $cmd,
71-
path => $facts['path'],
72-
* => $exec_params,
76+
command => $cmd,
77+
environment => $passin_env + $passout_env,
78+
path => $facts['path'],
79+
* => $exec_params,
7380
}
7481
} else {
7582
file { $full_path:

spec/defines/openssl_export_pem_cert_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979

8080
it {
8181
is_expected.to contain_exec('Export /etc/ssl/certs/foo.pfx to /etc/ssl/certs/foo.pem').with(
82-
command: ['openssl', 'pkcs12', '-in', '/etc/ssl/certs/foo.pfx', '-out', '/etc/ssl/certs/foo.pem', '-nokeys', '-passin', 'pass:5r$}^'],
82+
command: ['openssl', 'pkcs12', '-in', '/etc/ssl/certs/foo.pfx', '-out', '/etc/ssl/certs/foo.pem', '-nokeys', '-passin', 'env:CERTIFICATE_PASSIN'],
83+
environment: ['CERTIFICATE_PASSIN=5r$}^'],
8384
creates: '/etc/ssl/certs/foo.pem',
8485
path: '/usr/bin:/bin:/usr/sbin:/sbin'
8586
)

0 commit comments

Comments
 (0)