Skip to content

Commit b53234f

Browse files
committed
Support schema privileges in default_privileges
1 parent b23b4dd commit b53234f

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

manifests/server/default_privileges.pp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
/(?i:^ROUTINES$)/,
2222
/(?i:^SEQUENCES$)/,
2323
/(?i:^TABLES$)/,
24-
/(?i:^TYPES$)/
24+
/(?i:^TYPES$)/,
25+
/(?i:^SCHEMAS$)/
2526
] $object_type,
2627
String $schema = 'public',
2728
String $psql_db = $postgresql::server::default_database,
@@ -129,6 +130,18 @@
129130
}
130131
$_check_type = 'T'
131132
}
133+
'SCHEMAS': {
134+
if $schema != '' {
135+
fail('Cannot alter default schema permissions within a schema')
136+
}
137+
case $_privilege {
138+
/^ALL$/: { $_check_privilege = 'UC' }
139+
/^USAGE$/: { $_check_privilege = 'U' }
140+
/^CREATE$/: { $_check_privilege = 'C' }
141+
default: { fail('Illegal value for $privilege parameter') }
142+
}
143+
$_check_type = 'n'
144+
}
132145
default: {
133146
fail("Missing privilege validation for object type ${_object_type}")
134147
}

spec/unit/defines/server/default_privileges_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,50 @@
133133

134134
it { is_expected.to compile.and_raise_error(%r{Illegal value for \$privilege parameter}) }
135135
end
136+
137+
context 'schemas' do
138+
let :params do
139+
{
140+
db: 'test',
141+
role: 'test',
142+
privilege: 'all',
143+
object_type: 'schemas',
144+
schema: '',
145+
}
146+
end
147+
148+
let :pre_condition do
149+
"class {'postgresql::server':}"
150+
end
151+
152+
it { is_expected.to compile.with_all_deps }
153+
it { is_expected.to contain_postgresql__server__default_privileges('test') }
154+
it do
155+
# rubocop:disable Layout/LineLength
156+
is_expected.to contain_postgresql_psql('default_privileges:test')
157+
.with_command('ALTER DEFAULT PRIVILEGES GRANT ALL ON SCHEMAS TO "test"')
158+
.with_unless("SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE 'test=UC' = ANY (defaclacl) and defaclobjtype = 'n')")
159+
# rubocop:enable Layout/LineLength
160+
end
161+
end
162+
163+
context 'nested schemas are invalid' do
164+
let :params do
165+
{
166+
db: 'test',
167+
role: 'test',
168+
privilege: 'all',
169+
object_type: 'schemas',
170+
schema: 'public',
171+
}
172+
end
173+
174+
let :pre_condition do
175+
"class {'postgresql::server':}"
176+
end
177+
178+
it { is_expected.to compile.and_raise_error(%r{Cannot alter default schema permissions within a schema}) }
179+
end
136180
end
137181

138182
context 'with specific db connection settings - default port' do

0 commit comments

Comments
 (0)