Skip to content

Commit 8293666

Browse files
committed
pg_hba_rule: Validate userinput in postgresql::server
1 parent 38fa73b commit 8293666

File tree

5 files changed

+133
-4
lines changed

5 files changed

+133
-4
lines changed

manifests/server.pp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@
152152
$password_encryption = $postgresql::params::password_encryption,
153153
$extra_systemd_config = $postgresql::params::extra_systemd_config,
154154

155-
Hash[String, Hash] $roles = {},
156-
Hash[String, Any] $config_entries = {},
157-
Hash[String, Hash] $pg_hba_rules = {},
155+
Hash[String, Hash] $roles = {},
156+
Hash[String, Any] $config_entries = {},
157+
Postgresql::Pg_hba_rules $pg_hba_rules = {},
158158

159159
Boolean $backup_enable = $postgresql::params::backup_enable,
160160
Hash $backup_options = {},
@@ -204,7 +204,7 @@
204204
}
205205
}
206206

207-
$pg_hba_rules.each |$rule_name, $rule| {
207+
$pg_hba_rules.each |String[1] $rule_name, Postgresql::Pg_hba_rule $rule| {
208208
postgresql::server::pg_hba_rule { $rule_name:
209209
* => $rule,
210210
}

spec/type_aliases/pg_hba_rule_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'Postgresql::Pg_hba_rule' do
6+
context 'base valid required data' do
7+
let :data do
8+
{
9+
description: 'pc',
10+
type: 'host',
11+
database: 'all',
12+
user: 'all',
13+
address: '127.0.0.1/32',
14+
auth_method: 'md5',
15+
target: '/foo.conf',
16+
postgresql_version: '14',
17+
order: 3
18+
}
19+
end
20+
21+
it { is_expected.to allow_value(data) }
22+
end
23+
context 'invalid data' do
24+
let :data do
25+
{
26+
description: 'pc',
27+
type: 'host',
28+
database: 'all',
29+
user: 'all',
30+
address: '/32',
31+
auth_method: 'md5',
32+
target: '/foo.conf',
33+
postgres_version: '14'
34+
}
35+
end
36+
37+
it { is_expected.not_to allow_value(data) }
38+
end
39+
context 'empty data' do
40+
let :data do
41+
{}
42+
end
43+
44+
it { is_expected.not_to allow_value(data) }
45+
end
46+
end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'Postgresql::Pg_hba_rules' do
6+
context 'base valid required data' do
7+
let :data do
8+
{
9+
foo: {
10+
description: 'pc',
11+
type: 'host',
12+
database: 'all',
13+
user: 'all',
14+
address: '127.0.0.1/32',
15+
auth_method: 'md5',
16+
target: '/foo.conf',
17+
postgresql_version: '14',
18+
order: 1,
19+
},
20+
foo2: {
21+
description: 'pc',
22+
type: 'host',
23+
database: 'all',
24+
user: 'all',
25+
address: '127.0.0.1/32',
26+
auth_method: 'md5',
27+
target: '/foo.conf',
28+
postgresql_version: '14',
29+
order: 2
30+
}
31+
}
32+
end
33+
34+
it { is_expected.to allow_value(data) }
35+
end
36+
context 'empty' do
37+
let :data do
38+
{}
39+
end
40+
41+
it { is_expected.to allow_value(data) }
42+
end
43+
context 'invalid data' do
44+
let :data do
45+
{
46+
description: 'pc',
47+
type: 'host',
48+
database: 'all',
49+
user: 'all',
50+
address: '/32',
51+
auth_method: 'md5'
52+
}
53+
end
54+
55+
it { is_expected.not_to allow_value(data) }
56+
end
57+
context 'empty value' do
58+
let :data do
59+
{
60+
foo: {}
61+
}
62+
end
63+
64+
it { is_expected.not_to allow_value(data) }
65+
end
66+
end

types/pg_hba_rule.pp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# @summary type for all parameters in the postgresql::server::hba_rule defined resource
2+
# @see https://github.com/puppetlabs/puppetlabs-postgresql/blob/main/manifests/server/pg_hba_rule.pp
3+
type Postgresql::Pg_hba_rule = Struct[{
4+
Optional[description] => String,
5+
type => Postgresql::Pg_hba_rule_type,
6+
database => String,
7+
user => String,
8+
Optional[address] => Optional[Postgresql::Pg_hba_rule_address],
9+
auth_method => String,
10+
Optional[auth_option] => Optional[String],
11+
Optional[order] => Variant[String,Integer],
12+
Optional[target] => Stdlib::Absolutepath,
13+
Optional[postgresql_version] => String,
14+
}]

types/pg_hba_rules.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @summary validates a hash of entries for postgresql::server::pg_hab_conf
2+
# @see https://github.com/puppetlabs/puppetlabs-postgresql/blob/main/manifests/server/pg_hba_rule.pp
3+
type Postgresql::Pg_hba_rules = Hash[String[1], Postgresql::Pg_hba_rule]

0 commit comments

Comments
 (0)