2013-02-10 01:36:12 +01:00
# This resource manages an individual rule that applies to the file defined in
2013-08-27 22:43:47 +02:00
# $ target. See README. md for more details.
define postgresql: : server: : pg_hba_rule(
2013-02-10 01:36:12 +01:00
$ type ,
$da tabase,
$ user,
$a uth_method,
2013-08-27 22:43:47 +02:00
$add ress = undef,
2013-02-10 01:36:12 +01:00
$de scription = 'none' ,
$a uth_option = undef,
2013-08-27 22:43:47 +02:00
$ order = '150' ,
# Needed for testing primarily, support for multiple files is not really
# working.
$ target = $ postgresql: : server: : pg_hba_conf_path
2013-02-10 01:36:12 +01:00
) {
2013-12-04 21:09:56 +01:00
if $ postgresql: : server: : manage_pg_hba_conf = = false {
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' )
2013-10-02 14:43:21 +02:00
} else {
validate_re( $ type , '^(local|host|hostssl|hostnossl)$' ,
2013-02-10 01:36:12 +01:00
"The type you specified [${type}] must be one of: local, host, hostssl, hostnosssl" )
2013-10-02 14:43:21 +02:00
if( $ type = ~ / ^ host/ and $add ress = = undef) {
fail( 'You must specify an address property when type is host based' )
}
2013-02-10 01:36:12 +01:00
2013-10-02 14:43:21 +02:00
$a llowed_auth_methods = $ postgresql: : server: : version ? {
'9.3' = > [ 'trust' , 'reject' , 'md5' , 'sha1' , 'password' , 'gss' , 'sspi' , 'krb5' , 'ident' , 'peer' , 'ldap' , 'radius' , 'cert' , 'pam' ] ,
'9.2' = > [ 'trust' , 'reject' , 'md5' , 'sha1' , 'password' , 'gss' , 'sspi' , 'krb5' , 'ident' , 'peer' , 'ldap' , 'radius' , 'cert' , 'pam' ] ,
'9.1' = > [ 'trust' , 'reject' , 'md5' , 'sha1' , 'password' , 'gss' , 'sspi' , 'krb5' , 'ident' , 'peer' , 'ldap' , 'radius' , 'cert' , 'pam' ] ,
'9.0' = > [ 'trust' , 'reject' , 'md5' , 'sha1' , 'password' , 'gss' , 'sspi' , 'krb5' , 'ident' , 'ldap' , 'radius' , 'cert' , 'pam' ] ,
'8.4' = > [ 'trust' , 'reject' , 'md5' , 'sha1' , 'password' , 'gss' , 'sspi' , 'krb5' , 'ident' , 'ldap' , 'cert' , 'pam' ] ,
'8.3' = > [ 'trust' , 'reject' , 'md5' , 'sha1' , 'crypt' , 'password' , 'gss' , 'sspi' , 'krb5' , 'ident' , 'ldap' , 'pam' ] ,
'8.2' = > [ 'trust' , 'reject' , 'md5' , 'crypt' , 'password' , 'krb5' , 'ident' , 'ldap' , 'pam' ] ,
'8.1' = > [ 'trust' , 'reject' , 'md5' , 'crypt' , 'password' , 'krb5' , 'ident' , 'pam' ] ,
default = > [ 'trust' , 'reject' , 'md5' , 'password' , 'gss' , 'sspi' , 'krb5' , 'ident' , 'peer' , 'ldap' , 'radius' , 'cert' , 'pam' , 'crypt' ]
}
2013-09-22 22:35:18 +02:00
2013-10-19 18:04:04 +02:00
$a uth_method_regex = join( [ '^(' , join( $a llowed_auth_methods, '|' ) , ')$' ] , '' )
2013-10-02 14:43:21 +02:00
validate_re( $a uth_method, $a uth_method_regex,
2013-10-19 18:04:04 +02:00
join( [ "The auth_method you specified [${auth_method}] must be one of: " , join( $a llowed_auth_methods, ', ' ) ] , '' ) )
2013-09-22 22:35:18 +02:00
2013-10-02 14:43:21 +02:00
# Create a rule fragment
$f ragname = "pg_hba_rule_${name}"
concat: : fragment { $f ragname:
target = > $ target,
content = > template( 'postgresql/pg_hba_rule.conf' ) ,
order = > $ order,
}
2013-02-10 01:36:12 +01:00
}
}