Skip to content

Commit 41513a9

Browse files
committed
Revert "Send passwords via environment variables"
This broke several things and needs some fixes. This reverts commit 25df787.
1 parent a38c6ad commit 41513a9

File tree

6 files changed

+30
-58
lines changed

6 files changed

+30
-58
lines changed

lib/puppet/provider/x509_cert/openssl.rb

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

5959
def create
60-
env = {}
61-
6260
if resource[:csr]
6361
options = [
6462
'x509',
@@ -94,12 +92,9 @@ def create
9492

9593
password = resource[:cakey_password] || resource[:password]
9694

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

105100
def destroy

lib/puppet/provider/x509_request/openssl.rb

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

3030
def create
31-
env = {}
3231
options = [
3332
'req', '-new',
3433
'-key', resource[:private_key],
3534
'-config', resource[:template],
3635
'-out', resource[:path]
3736
]
3837

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

45-
openssl options, environment: env
41+
openssl options
4642
end
4743

4844
def destroy

manifests/export/pem_cert.pp

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

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 = []
47+
$passin_opt = $in_pass ? {
48+
undef => [],
49+
default => ['-nokeys', '-passin', "pass:${in_pass}"],
5350
}
5451

5552
if $ensure == 'present' {
@@ -65,10 +62,9 @@
6562
}
6663

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

manifests/export/pem_key.pp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,14 @@
2525
Optional[String] $out_pass = undef,
2626
) {
2727
if $ensure == 'present' {
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 = []
28+
$passin_opt = $in_pass ? {
29+
undef => [],
30+
default => ['-passin', "pass:${in_pass}"],
3431
}
3532

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 = []
33+
$passout_opt = $out_pass ? {
34+
undef => ['-nodes'],
35+
default => ['-passout', "pass:${out_pass}"],
4236
}
4337

4438
$cmd = [
@@ -58,10 +52,9 @@
5852
}
5953

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

manifests/export/pkcs12.pp

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

3535
if $ensure == 'present' {
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 = []
36+
$pass_opt = $in_pass ? {
37+
undef => [],
38+
default => ['-passin', "pass:${in_pass}"],
4239
}
4340

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 = []
41+
$passout_opt = $out_pass ? {
42+
undef => [],
43+
default => ['-passout', "pass:${out_pass}"],
5044
}
5145

5246
$chain_opt = $chaincert ? {
@@ -61,7 +55,7 @@
6155
'-out', $full_path,
6256
'-name', $name,
6357
'-nodes', '-noiter',
64-
] + $chain_opt + $passin_opt + $passout_opt
58+
] + $chain_opt + $pass_opt + $passout_opt
6559

6660
if $dynamic {
6761
$exec_params = {
@@ -73,10 +67,9 @@
7367
}
7468

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

spec/defines/openssl_export_pem_cert_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@
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', 'env:CERTIFICATE_PASSIN'],
83-
environment: ['CERTIFICATE_PASSIN=5r$}^'],
82+
command: ['openssl', 'pkcs12', '-in', '/etc/ssl/certs/foo.pfx', '-out', '/etc/ssl/certs/foo.pem', '-nokeys', '-passin', 'pass:5r$}^'],
8483
creates: '/etc/ssl/certs/foo.pem',
8584
path: '/usr/bin:/bin:/usr/sbin:/sbin'
8685
)

0 commit comments

Comments
 (0)