Skip to content

Commit 4287df8

Browse files
author
Cocker Koch
committed
Use Puppet-Datatype Sensitive
- use Puppet-Datatype Sensitive for Users-Array, as it contains Secrets - use EPP instead of ERB, as it is able to handle Sensitive Data
1 parent 1d2065a commit 4287df8

File tree

4 files changed

+45
-21
lines changed

4 files changed

+45
-21
lines changed

manifests/userlist.pp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Optional. Path of the config file where this entry will be added.
2626
# Assumes that the parent directory exists.
2727
# Default: $haproxy::params::config_file
28-
#
28+
#
2929
# @param instance
3030
# Optional. Defaults to 'haproxy'
3131
#
@@ -34,15 +34,26 @@
3434
# Jeremy Kitchen <[email protected]>
3535
#
3636
define haproxy::userlist (
37-
$users = undef,
38-
$groups = undef,
39-
String $instance = 'haproxy',
40-
String $section_name = $name,
41-
Optional[Stdlib::Absolutepath] $config_file = undef,
37+
Optional[Array[Variant[String, Sensitive[String]]]] $users = undef,
38+
Optional[Array[String]] $groups = undef,
39+
String $instance = 'haproxy',
40+
String $section_name = $name,
41+
Optional[Stdlib::Absolutepath] $config_file = undef,
4242
) {
4343

4444
include ::haproxy::params
4545

46+
$content = epp(
47+
'haproxy/haproxy_userlist_block.epp',
48+
{
49+
epp_users => $users,
50+
epp_groups => $groups,
51+
epp_section_name => $section_name,
52+
},
53+
)
54+
# we have to unwrap here, as "concat" cannot handle Sensitive Data
55+
$_content = if $content =~ Sensitive { $content.unwrap } else { $content }
56+
4657
if $instance == 'haproxy' {
4758
$instance_name = 'haproxy'
4859
$_config_file = pick($config_file, $haproxy::config_file)
@@ -51,10 +62,9 @@
5162
$_config_file = pick($config_file, inline_template($haproxy::params::config_file_tmpl))
5263
}
5364

54-
# Template uses $section_name, $users, $groups
5565
concat::fragment { "${instance_name}-${section_name}_userlist_block":
5666
order => "12-${section_name}-00",
5767
target => $_config_file,
58-
content => template('haproxy/haproxy_userlist_block.erb'),
68+
content => $_content,
5969
}
6070
}

spec/defines/userlist_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
name: 'admins',
2020
users: [
2121
'scott insecure-password elgato',
22-
'kitchen insecure-password foobar',
22+
sensitive('kitchen insecure-password foobar'),
2323
],
2424
groups: [
2525
'superadmins users kitchen scott',

templates/haproxy_userlist_block.epp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<%- |
2+
Optional[Array[Variant[String, Sensitive[String]]]] $epp_users,
3+
Optional[Array[String]] $epp_groups,
4+
String $epp_section_name,
5+
| -%>
6+
7+
userlist <%= $epp_section_name %>
8+
<%-
9+
$epp_groups.each |String $group| {
10+
unless $group.empty {
11+
-%>
12+
group <%= $group %>
13+
<%-
14+
}
15+
}
16+
$epp_users.each |Variant[String, Sensitive[String]] $user| {
17+
# TODO: remove this Workaround, as soon as Function empty() can handle
18+
# Sensitive (Pullrequest pending)
19+
$user_unsensitive = if $user =~ Sensitive { $user.unwrap } else { $user }
20+
unless $user_unsensitive.empty {
21+
-%>
22+
user <%= $user_unsensitive %>
23+
<%-
24+
}
25+
}
26+
-%>

templates/haproxy_userlist_block.erb

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)