Skip to content

Commit 4b93634

Browse files
committed
Merge pull request puppetlabs#678 from npwalker/modules_2321_improve_pg_hba_rule
Decouple pg_hba_rule from postgresql::server
2 parents 7981b09 + 25c1bae commit 4b93634

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,19 @@ This would create a ruleset in `pg_hba.conf` similar to:
700700
# Order: 150
701701
host app app 200.1.2.0/24 md5
702702

703+
By default, `pg_hba_rule` requires that you include `postgresql::server`, however, you can override that behavior by setting target and postgresql_version when declaring your rule. That might look like the following.
704+
705+
postgresql::server::pg_hba_rule { 'allow application network to access app database':
706+
description => "Open up postgresql for access from 200.1.2.0/24",
707+
type => 'host',
708+
database => 'app',
709+
user => 'app',
710+
address => '200.1.2.0/24',
711+
auth_method => 'md5',
712+
target => '/path/to/pg_hba.conf',
713+
postgresql_version => '9.4',
714+
}
715+
703716
####`namevar`
704717
A unique identifier or short description for this rule. The namevar doesn't provide any functional usage, but it is stored in the comments of the produced `pg_hba.conf` so the originating resource can be identified.
705718

@@ -730,6 +743,8 @@ An order for placing the rule in `pg_hba.conf`. Defaults to `150`.
730743
####`target`
731744
This provides the target for the rule, and is generally an internal only property. Use with caution.
732745

746+
####`postgresql_version`
747+
Defaults to the version set in `postgresql::server`. Use this if you want to manage `pg_hba.conf` without managing the entire PostgreSQL instance.
733748

734749
###Resource: postgresql::server::pg\_ident\_rule
735750
This defined type allows you to create user name maps for `pg_ident.conf`. For more details see the [PostgreSQL documentation](http://www.postgresql.org/docs/current/static/auth-username-maps.html).

manifests/server/pg_hba_rule.pp

+12-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@
1212

1313
# Needed for testing primarily, support for multiple files is not really
1414
# working.
15-
$target = $postgresql::server::pg_hba_conf_path
15+
$target = $postgresql::server::pg_hba_conf_path,
16+
$postgresql_version = $postgresql::server::_version
1617
) {
1718

18-
if $postgresql::server::manage_pg_hba_conf == false {
19+
#Allow users to manage pg_hba.conf even if they are not managing the whole PostgreSQL instance
20+
if !defined( 'postgresql::server' ) {
21+
$manage_pg_hba_conf = true
22+
}
23+
else {
24+
$manage_pg_hba_conf = $postgresql::server::manage_pg_hba_conf
25+
}
26+
27+
if $manage_pg_hba_conf == false {
1928
fail('postgresql::server::manage_pg_hba_conf has been disabled, so this resource is now unused and redundant, either enable that option or remove this resource from your manifests')
2029
} else {
2130
validate_re($type, '^(local|host|hostssl|hostnossl)$',
@@ -25,7 +34,7 @@
2534
fail('You must specify an address property when type is host based')
2635
}
2736

28-
$allowed_auth_methods = $postgresql::server::_version ? {
37+
$allowed_auth_methods = $postgresql_version ? {
2938
'9.4' => ['trust', 'reject', 'md5', 'password', 'gss', 'sspi', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam'],
3039
'9.3' => ['trust', 'reject', 'md5', 'password', 'gss', 'sspi', 'krb5', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam'],
3140
'9.2' => ['trust', 'reject', 'md5', 'password', 'gss', 'sspi', 'krb5', 'ident', 'peer', 'ldap', 'radius', 'cert', 'pam'],

0 commit comments

Comments
 (0)