Skip to content

Commit 91d04e8

Browse files
authored
Merge pull request puppetlabs#1266 from opus-codium/revoke-public
MODULES-11047 - Allow managing rights for PUBLIC role
2 parents 32b3314 + 7b295fb commit 91d04e8

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

manifests/server/grant.pp

+12-6
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,23 @@
5252
case $ensure {
5353
default: {
5454
# default is 'present'
55-
$sql_command = 'GRANT %s ON %s "%s%s" TO "%s"'
56-
$sql_command_unquoted = 'GRANT %s ON %s %s%s TO "%s"'
55+
$sql_command = 'GRANT %s ON %s "%s%s" TO %s'
56+
$sql_command_unquoted = 'GRANT %s ON %s %s%s TO %s'
5757
$unless_is = true
5858
}
5959
'absent': {
60-
$sql_command = 'REVOKE %s ON %s "%s%s" FROM "%s"'
61-
$sql_command_unquoted = 'REVOKE %s ON %s %s%s FROM "%s"'
60+
$sql_command = 'REVOKE %s ON %s "%s%s" FROM %s'
61+
$sql_command_unquoted = 'REVOKE %s ON %s %s%s FROM %s'
6262
$unless_is = false
6363
}
6464
}
6565

66+
# Quote the role if not PUBLIC
67+
$_query_role = $role ? {
68+
'PUBLIC' => 'PUBLIC',
69+
default => "\"${role}\""
70+
}
71+
6672
if ! $object_name {
6773
$_object_name = $db
6874
} else {
@@ -453,8 +459,8 @@
453459
}
454460

455461
$grant_cmd = $_enquote_object ? {
456-
false => sprintf($sql_command_unquoted, $_privilege, $_object_type, $_togrant_object, $arguments, $role),
457-
default => sprintf($sql_command, $_privilege, $_object_type, $_togrant_object, $arguments, $role),
462+
false => sprintf($sql_command_unquoted, $_privilege, $_object_type, $_togrant_object, $arguments, $_query_role),
463+
default => sprintf($sql_command, $_privilege, $_object_type, $_togrant_object, $arguments, $_query_role),
458464
}
459465

460466
postgresql_psql { "grant:${name}":

spec/unit/defines/server/grant_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class {'postgresql::server':}
240240
it { is_expected.to contain_postgresql__server__role('test') }
241241
it do
242242
is_expected.to contain_postgresql_psql('grant:test')
243-
.with_command(%r{GRANT ALL ON TABLE "myschema"."mytable" TO\s* "PUBLIC"}m)
243+
.with_command(%r{GRANT ALL ON TABLE "myschema"."mytable" TO\s* PUBLIC}m)
244244
.with_unless(%r{SELECT 1 WHERE has_table_privilege\('public',\s*'myschema.mytable', 'INSERT'\)}m)
245245
end
246246
end

0 commit comments

Comments
 (0)