# Copyright (c) 2024, PostgreSQL Global Development Group use strict; use warnings FATAL => 'all'; use PostgreSQL::Test::Cluster; use PostgreSQL::Test::Utils; use Test::More; if (!$ENV{PG_TEST_EXTRA} || $ENV{PG_TEST_EXTRA} !~ /\bsepgsql\b/) { plan skip_all => 'Potentially unsafe test sepgsql not enabled in PG_TEST_EXTRA'; } note "checking selinux environment"; # matchpathcon must be present to assess whether the installation environment # is OK. note "checking for matchpathcon"; if (system('matchpathcon -n . >/dev/null 2>&1') != 0) { diag </dev/null 2>&1') != 0) { diag </dev/null 2>&1') != 0) { diag </dev/null`)[2]; note "current user domain is '$DOMAIN'"; if ($DOMAIN ne 'unconfined_t') { diag <<'EOS'; The regression tests must be launched from the unconfined_t domain. The unconfined_t domain is typically the default domain for user shell processes. If the default has been changed on your system, you can revert the changes like this: $ sudo semanage login -d `whoami` Or, you can add a setting to log in using the unconfined_t domain: $ sudo semanage login -a -s unconfined_u -r s0-s0:c0.c255 `whoami` EOS die; } # SELinux must be configured in enforcing mode note "checking selinux operating mode"; my $CURRENT_MODE = (split /: */, `LANG=C sestatus | grep '^Current mode:'`)[1]; chomp $CURRENT_MODE; note "current operating mode is '$CURRENT_MODE'"; if ($CURRENT_MODE eq 'enforcing') { # OK } elsif ($CURRENT_MODE eq 'permissive' || $CURRENT_MODE eq 'disabled') { diag <<'EOS'; Before running the regression tests, SELinux must be enabled and must be running in enforcing mode. If SELinux is currently running in permissive mode, you can switch to enforcing mode using the 'setenforce' command. $ sudo setenforce 1 The system default setting is configured in /etc/selinux/config, or using a kernel boot parameter. EOS die; } else { diag <new('test'); $node->init; $node->append_conf('postgresql.conf', 'log_statement=none'); { local %ENV = $node->_get_env(); my $result = run_log( [ 'postgres', '--single', '-F', '-c' => 'exit_on_error=true', '-D' => $node->data_dir, 'template0' ], '<' => $ENV{share_contrib_dir} . '/sepgsql.sql'); ok($result, 'sepgsql installation script'); } $node->append_conf('postgresql.conf', 'shared_preload_libraries=sepgsql'); $node->start; my @tests = qw(label dml ddl alter misc); # Check if the truncate permission exists in the loaded policy, and if so, # run the truncate test # # Testing the TRUNCATE regression test can be done by manually adding # the permission with CIL if necessary: # sudo semodule -cE base # sudo sed -i -E 's/(class db_table.*?) \)/\1 truncate\)/' base.cil # sudo semodule -i base.cil push @tests, 'truncate' if -f '/sys/fs/selinux/class/db_table/perms/truncate'; $node->command_ok( [ $ENV{PG_REGRESS}, '--bindir' => '', '--inputdir' => '.', '--launcher' => './launcher', @tests ], 'sepgsql tests'); done_testing();