Skip to content

Commit 8854a1c

Browse files
author
Michael Watters
committed
Change - Ensure that postgres directories have proper SELinux labels
The postgresql data directory and log directory need to have proper SELinux labels set when SELinux is enabled.
1 parent 46a9bfb commit 8854a1c

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

manifests/server/initdb.pp

+24-11
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,43 @@
2222
cwd => $module_workdir,
2323
}
2424

25+
if $::osfamily == 'RedHat' and $::selinux == true {
26+
$seltype = 'postgresql_db_t'
27+
$logdir_type = 'postgresql_log_t'
28+
}
29+
30+
else {
31+
$seltype = undef
32+
$logdir_type = undef
33+
}
34+
2535
# Make sure the data directory exists, and has the correct permissions.
2636
file { $datadir:
27-
ensure => directory,
28-
owner => $user,
29-
group => $group,
30-
mode => '0700',
37+
ensure => directory,
38+
owner => $user,
39+
group => $group,
40+
mode => '0700',
41+
seltype => $seltype,
3142
}
3243

3344
if($xlogdir) {
3445
# Make sure the xlog directory exists, and has the correct permissions.
3546
file { $xlogdir:
36-
ensure => directory,
37-
owner => $user,
38-
group => $group,
39-
mode => '0700',
47+
ensure => directory,
48+
owner => $user,
49+
group => $group,
50+
mode => '0700',
51+
seltype => $seltype,
4052
}
4153
}
4254

4355
if($logdir) {
4456
# Make sure the log directory exists, and has the correct permissions.
4557
file { $logdir:
46-
ensure => directory,
47-
owner => $user,
48-
group => $group,
58+
ensure => directory,
59+
owner => $user,
60+
group => $group,
61+
seltype => $logdir_type,
4962
}
5063
}
5164

spec/unit/classes/server/config_spec.rb

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
:kernel => 'Linux',
1616
:id => 'root',
1717
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
18+
:selinux => true,
1819
}
1920
end
2021
it 'should have the correct systemd-override file' do
@@ -62,6 +63,7 @@ class { 'postgresql::server': }
6263
:kernel => 'Linux',
6364
:id => 'root',
6465
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
66+
:selinux => true,
6567
}
6668
end
6769
it 'should have the correct systemd-override file' do
@@ -117,6 +119,7 @@ class { 'postgresql::server': }
117119
:kernel => 'Linux',
118120
:id => 'root',
119121
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
122+
:selinux => false,
120123
}
121124
end
122125
it 'should have the correct systemd-override file' do

spec/unit/classes/server/initdb_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
:kernel => 'Linux',
1515
:id => 'root',
1616
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
17+
:selinux => true,
1718
}
1819
end
1920
it { is_expected.to contain_file('/var/lib/pgsql/data').with_ensure('directory') }
@@ -28,6 +29,7 @@
2829
:kernel => 'Linux',
2930
:id => 'root',
3031
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
32+
:selinux => true,
3133
}
3234
end
3335
it { is_expected.to contain_file('/var/lib/pgsql92/data').with_ensure('directory') }
@@ -43,6 +45,7 @@
4345
:kernel => 'Linux',
4446
:id => 'root',
4547
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
48+
:selinux => true,
4649
}
4750
end
4851
let (:pre_condition) do
@@ -71,6 +74,7 @@ class { 'postgresql::server': }
7174
:kernel => 'Linux',
7275
:id => 'root',
7376
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
77+
:selinux => true,
7478
}
7579
end
7680
let (:pre_condition) do
@@ -99,6 +103,7 @@ class { 'postgresql::server': }
99103
:kernel => 'Linux',
100104
:id => 'root',
101105
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
106+
:selinux => true,
102107
}
103108
end
104109

spec/unit/classes/server/plpython_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:kernel => 'Linux',
1111
:id => 'root',
1212
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
13+
:selinux => true,
1314
}
1415
end
1516

spec/unit/defines/server/config_entry_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:concat_basedir => tmpfilename('contrib'),
1111
:id => 'root',
1212
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
13+
:selinux => true,
1314
}
1415
end
1516

@@ -39,6 +40,7 @@
3940
:concat_basedir => tmpfilename('contrib'),
4041
:id => 'root',
4142
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
43+
:selinux => true,
4244
}
4345
end
4446
let(:params) {{ :ensure => 'present', :name => 'port_spec', :value => '5432' }}
@@ -58,6 +60,7 @@
5860
:concat_basedir => tmpfilename('contrib'),
5961
:id => 'root',
6062
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
63+
:selinux => true,
6164
}
6265
end
6366
let(:params) {{ :ensure => 'present', :name => 'port_spec', :value => '5432' }}
@@ -77,6 +80,7 @@
7780
:concat_basedir => tmpfilename('contrib'),
7881
:id => 'root',
7982
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
83+
:selinux => true,
8084
}
8185
end
8286
let(:params) {{ :ensure => 'present', :name => 'port_spec', :value => '5432' }}

0 commit comments

Comments
 (0)