Skip to content

Commit ebdde20

Browse files
committed
Support grants and revokes for PUBLIC pseudo role
1 parent 59b18ac commit ebdde20

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

manifests/server/grant.pp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@
5353
default: {
5454
# default is 'present'
5555
$sql_command = 'GRANT %s ON %s "%s%s" TO "%s"'
56+
$sql_command_public = 'GRANT %s ON %s "%s%s" TO PUBLIC'
5657
$sql_command_unquoted = 'GRANT %s ON %s %s%s TO "%s"'
58+
$sql_command_unquoted_public = 'GRANT %s ON %s %s%s TO PUBLIC'
5759
$unless_is = true
5860
}
5961
'absent': {
6062
$sql_command = 'REVOKE %s ON %s "%s%s" FROM "%s"'
63+
$sql_command_public = 'REVOKE %s ON %s "%s%s" FROM PUBLIC'
6164
$sql_command_unquoted = 'REVOKE %s ON %s %s%s FROM "%s"'
65+
$sql_command_unquoted_public = 'REVOKE %s ON %s %s%s FROM PUBLIC'
6266
$unless_is = false
6367
}
6468
}
@@ -452,9 +456,20 @@
452456
default => undef,
453457
}
454458

455-
$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),
459+
case $role {
460+
default: {
461+
$grant_cmd = $_enquote_object ? {
462+
false => sprintf($sql_command_unquoted, $_privilege, $_object_type, $_togrant_object, $arguments, $role),
463+
default => sprintf($sql_command, $_privilege, $_object_type, $_togrant_object, $arguments, $role),
464+
}
465+
}
466+
'PUBLIC': {
467+
# For internal PUBLIC role, we do not want to quote it
468+
$grant_cmd = $_enquote_object ? {
469+
false => sprintf($sql_command_unquoted_public, $_privilege, $_object_type, $_togrant_object, $arguments, $role),
470+
default => sprintf($sql_command_public, $_privilege, $_object_type, $_togrant_object, $arguments, $role),
471+
}
472+
}
458473
}
459474

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

spec/unit/defines/server/grant_spec.rb

Lines changed: 1 addition & 1 deletion
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)