1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-05-22 10:15:16 +02:00

Remove pgbackrest test user.

This user was created before we tested in containers to ensure isolation between the pg and repo hosts which were then just directories.  The downside is that this resulted in a lot of sudos to set the pgbackrest user and to remove files which did not belong to the main test user.

Containers provide isolation without needing separate users so we can now safely remove the pgbackrest user.  This allows us to remove most sudos, except where they are explicitly needed in tests.

While we're at it, remove the code that installed the Perl C library (which also required sudo) and simply add the build path to @INC instead.
This commit is contained in:
David Steele
2019-10-12 09:45:18 -04:00
parent 6f0e7f00af
commit 11c7c8fabb
26 changed files with 190 additions and 303 deletions
@@ -273,7 +273,6 @@ sub buildMakefile
('#' x 132) . "\n" .
buildMakefileObjectCompile($oStorage, {rhOption => $rhOption});
# Return from function and log return values if any
return logDebugReturn
(
@@ -28,12 +28,6 @@ use pgBackRestTest::Common::VmTest;
####################################################################################################################################
# User/group definitions
####################################################################################################################################
use constant POSTGRES_GROUP => 'postgres';
push @EXPORT, qw(POSTGRES_GROUP);
use constant POSTGRES_GROUP_ID => 5000;
use constant POSTGRES_USER => POSTGRES_GROUP;
use constant POSTGRES_USER_ID => 5000;
use constant TEST_USER => getpwuid($UID) . '';
push @EXPORT, qw(TEST_USER);
use constant TEST_USER_ID => $UID;
@@ -41,18 +35,6 @@ use constant TEST_GROUP => getgrgid(
push @EXPORT, qw(TEST_GROUP);
use constant TEST_GROUP_ID => getgrnam(TEST_GROUP) . '';
use constant BACKREST_USER => 'pgbackrest';
push @EXPORT, qw(BACKREST_USER);
use constant BACKREST_USER_ID => getpwnam(BACKREST_USER) ? getpwnam(BACKREST_USER) . '' : undef;
####################################################################################################################################
# Package constants
####################################################################################################################################
use constant LIB_COVER_VERSION => '1.29-2';
push @EXPORT, qw(LIB_COVER_VERSION);
use constant LIB_COVER_EXE => '/usr/bin/cover';
push @EXPORT, qw(LIB_COVER_EXE);
####################################################################################################################################
# Cert file constants
####################################################################################################################################
@@ -74,18 +56,6 @@ use constant CONTAINER_DEBUG => false;
####################################################################################################################################
my $hContainerCache;
####################################################################################################################################
# Generate Devel::Cover package name
####################################################################################################################################
sub packageDevelCover
{
my $strArch = shift;
return 'libdevel-cover-perl_' . LIB_COVER_VERSION . "_${strArch}.deb";
}
push @EXPORT, qw(packageDevelCover);
####################################################################################################################################
# Container repo - defines the Docker repository where the containers will be located
####################################################################################################################################
@@ -463,11 +433,6 @@ sub containerBuild
#---------------------------------------------------------------------------------------------------------------------------
if (!$bDeprecated)
{
$strScript .= sectionHeader() .
"# Create PostgreSQL user/group with known ids for testing\n" .
' ' . groupCreate($strOS, POSTGRES_GROUP, POSTGRES_GROUP_ID) . " && \\\n" .
' ' . userCreate($strOS, POSTGRES_USER, POSTGRES_USER_ID, POSTGRES_GROUP);
$strScript .= sectionHeader() .
"# Install PostgreSQL packages\n";
@@ -567,8 +532,6 @@ sub containerBuild
$strImage = "${strOS}-build";
$strCopy = undef;
my $strPkgDevelCover = packageDevelCover($oVm->{$strOS}{&VM_ARCH});
$strScript = sectionHeader() .
"# Create test user\n" .
' ' . groupCreate($strOS, TEST_GROUP, TEST_GROUP_ID) . " && \\\n" .
@@ -643,13 +606,6 @@ sub containerBuild
$strScript .=
sshSetup($strOS, TEST_USER, TEST_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
$strScript .= sectionHeader() .
"# Create pgbackrest user\n" .
' ' . userCreate($strOS, BACKREST_USER, BACKREST_USER_ID, TEST_GROUP);
$strScript .=
sshSetup($strOS, BACKREST_USER, TEST_GROUP, $$oVm{$strOS}{&VM_CONTROL_MASTER});
$strScript .= sectionHeader() .
"# Make " . TEST_USER . " home dir readable\n" .
' chmod g+r,g+x /home/' . TEST_USER;
+5 -5
View File
@@ -84,7 +84,7 @@ sub testPathRemove
my $strPath = shift;
my $bSuppressError = shift;
executeTest('sudo rm -rf ' . $strPath, {bSuppressError => $bSuppressError});
executeTest('rm -rf ' . $strPath, {bSuppressError => $bSuppressError});
}
push(@EXPORT, qw(testPathRemove));
@@ -170,7 +170,7 @@ sub forceStorageMode
# Mode commands are ignored on S3
if ($oStorage->type() ne STORAGE_S3)
{
executeTest('sudo chmod ' . ($bRecurse ? '-R ' : '') . "${strMode} " . $oStorage->pathGet($strPathExp));
executeTest('chmod ' . ($bRecurse ? '-R ' : '') . "${strMode} " . $oStorage->pathGet($strPathExp));
}
# Return from function and log return values if any
@@ -237,7 +237,7 @@ sub forceStorageMove
# Else remove using filesystem commands
else
{
executeTest('sudo mv ' . $oStorage->pathGet($strSourcePathExp) . ' ' . $oStorage->pathGet($strDestinationPathExp));
executeTest('mv ' . $oStorage->pathGet($strSourcePathExp) . ' ' . $oStorage->pathGet($strDestinationPathExp));
}
# Return from function and log return values if any
@@ -272,7 +272,7 @@ sub forceStorageOwner
# Owner commands are ignored on S3
if ($oStorage->type() ne STORAGE_S3)
{
executeTest('sudo chown ' . ($bRecurse ? '-R ' : '') . "${strOwner} " . $oStorage->pathGet($strPathExp));
executeTest('chown ' . ($bRecurse ? '-R ' : '') . "${strOwner} " . $oStorage->pathGet($strPathExp));
}
# Return from function and log return values if any
@@ -318,7 +318,7 @@ sub forceStorageRemove
}
else
{
executeTest('sudo rm -f' . ($bRecurse ? 'r ' : ' ') . $oStorage->pathGet($strPathExp));
executeTest('rm -f' . ($bRecurse ? 'r ' : ' ') . $oStorage->pathGet($strPathExp));
}
# Return from function and log return values if any
+5 -9
View File
@@ -57,6 +57,7 @@ sub new
$self->{strTestPath},
$self->{oTest},
$self->{bDryRun},
$self->{strVmHost},
$self->{bVmOut},
$self->{iVmIdx},
$self->{iVmMax},
@@ -87,6 +88,7 @@ sub new
{name => 'strTestPath'},
{name => 'oTest'},
{name => 'bDryRun'},
{name => 'strVmHost'},
{name => 'bVmOut'},
{name => 'iVmIdx'},
{name => 'iVmMax'},
@@ -232,9 +234,7 @@ sub run
# If testing Perl code (or C code that calls Perl code) install bin and Perl C Library
if ($self->{oTest}->{&TEST_VM} ne VM_NONE && (!$self->{oTest}->{&TEST_C} || $self->{oTest}->{&TEST_PERL_REQ}))
{
jobInstallC(
$self->{strBackRestBase}, $self->{oTest}->{&TEST_VM}, $strImage,
!$self->{oTest}->{&TEST_C} && !$self->{oTest}->{&TEST_INTEGRATION});
jobInstallC($self->{strBackRestBase}, $self->{oTest}->{&TEST_VM}, $strImage);
}
}
}
@@ -269,6 +269,7 @@ sub run
($self->{oTest}->{&TEST_CONTAINER} ? 'docker exec -i -u ' . TEST_USER . " ${strImage} " : '') .
abs_path($0) .
" --test-path=${strVmTestPath}" .
" --vm-host=$self->{strVmHost}" .
" --vm=$self->{oTest}->{&TEST_VM}" .
" --vm-id=$self->{iVmIdx}" .
" --module=" . $self->{oTest}->{&TEST_MODULE} .
@@ -753,7 +754,7 @@ sub end
containerRemove("test-$self->{iVmIdx}");
}
executeTest(($self->{oTest}->{&TEST_VM} ne VM_NONE ? "sudo " : '') . "rm -rf ${strHostTestPath}");
executeTest("rm -rf ${strHostTestPath}");
}
$bDone = true;
@@ -776,20 +777,15 @@ sub jobInstallC
my $strBasePath = shift;
my $strVm = shift;
my $strImage = shift;
my $bCopyLibC = shift;
# Install Perl C Library
my $oVm = vmGet();
my $strBuildPath = "${strBasePath}/test/.vagrant/bin/${strVm}";
my $strBuildLibCPath = "${strBuildPath}/libc";
my $strBuildBinPath = "${strBuildPath}/src";
my $strPerlAutoPath = $oVm->{$strVm}{&VMDEF_PERL_ARCH_PATH} . '/auto/pgBackRest/LibC';
executeTest(
"docker exec -i -u root ${strImage} bash -c '" .
(defined($bCopyLibC) && $bCopyLibC ?
"mkdir -p -m 755 ${strPerlAutoPath} && " .
"cp ${strBuildLibCPath}/blib/arch/auto/pgBackRest/LibC/LibC.so ${strPerlAutoPath} && " : '') .
"cp ${strBuildBinPath}/" . PROJECT_EXE . ' /usr/bin/' . PROJECT_EXE . ' && ' .
'chmod 755 /usr/bin/' . PROJECT_EXE . "'");
}
@@ -38,8 +38,6 @@ use constant TEST_MODULE => 'module';
push @EXPORT, qw(TEST_MODULE);
use constant TEST_NAME => 'test';
push @EXPORT, qw(TEST_NAME);
use constant TEST_PERL_ARCH_PATH => VMDEF_PERL_ARCH_PATH;
push @EXPORT, qw(TEST_PERL_ARCH_PATH);
use constant TEST_PERL_REQ => 'perl-req';
push @EXPORT, qw(TEST_PERL_REQ);
use constant TEST_PGSQL_BIN => 'pgsql-bin';
@@ -174,7 +172,6 @@ sub testListGet
&TEST_CONTAINER => defined($hTest->{&TESTDEF_CONTAINER}) ?
$hTest->{&TESTDEF_CONTAINER} : $hModule->{&TESTDEF_CONTAINER},
&TEST_PGSQL_BIN => $strPgSqlBin,
&TEST_PERL_ARCH_PATH => $$oyVm{$strTestOS}{&VMDEF_PERL_ARCH_PATH},
&TEST_PERL_REQ => $hTest->{&TESTDEF_PERL_REQ},
&TEST_INTEGRATION => $hTest->{&TESTDEF_INTEGRATION},
&TEST_MODULE => $strModule,
+1 -4
View File
@@ -90,7 +90,7 @@ sub cleanTest
{
my $self = shift;
executeTest('sudo rm -rf ' . $self->testPath() . '/*');
executeTest('rm -rf ' . $self->testPath() . '/*');
}
####################################################################################################################################
@@ -126,7 +126,6 @@ sub process
$self->{bCleanup},
$self->{bLogForce},
$self->{strPgUser},
$self->{strBackRestUser},
$self->{strGroup},
) =
logDebugParam
@@ -148,7 +147,6 @@ sub process
{name => 'bCleanup'},
{name => 'bLogForce'},
{name => 'strPgUser'},
{name => 'strBackRestUser'},
{name => 'strGroup'},
);
@@ -544,7 +542,6 @@ push(@EXPORT, qw(storageTest));
####################################################################################################################################
sub archBits {return vmArchBits(shift->{strVm})}
sub backrestExe {return shift->{strBackRestExe}}
sub backrestUser {return shift->{strBackRestUser}}
sub basePath {return shift->{strBasePath}}
sub dataPath {return shift->basePath() . '/test/data'}
sub doCleanup {return shift->{bCleanup}}
+3 -15
View File
@@ -43,8 +43,6 @@ use constant VM_OS_REPO => 'os-repo'
push @EXPORT, qw(VM_OS_REPO);
use constant VMDEF_PGSQL_BIN => 'pgsql-bin';
push @EXPORT, qw(VMDEF_PGSQL_BIN);
use constant VMDEF_PERL_ARCH_PATH => 'perl-arch-path';
push @EXPORT, qw(VMDEF_PERL_ARCH_PATH);
use constant VMDEF_WITH_BACKTRACE => 'with-backtrace';
push @EXPORT, qw(VMDEF_WITH_BACKTRACE);
@@ -129,12 +127,11 @@ my $oyVm =
# None
&VM_NONE =>
{
&VM_OS_BASE => VM_OS_BASE_RHEL,
&VM_OS => VM_OS_CENTOS,
&VM_OS_BASE => VM_OS_BASE_DEBIAN,
&VM_OS => VM_OS_UBUNTU,
&VM_ARCH => VM_ARCH_AMD64,
&VMDEF_COVERAGE_C => true,
&VMDEF_PGSQL_BIN => '/usr/pgsql-{[version]}/bin',
&VMDEF_PERL_ARCH_PATH => '/usr/local/lib64/perl5',
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VM_DB =>
[
@@ -155,7 +152,6 @@ my $oyVm =
&VM_IMAGE => 'centos:6',
&VM_ARCH => VM_ARCH_AMD64,
&VMDEF_PGSQL_BIN => '/usr/pgsql-{[version]}/bin',
&VMDEF_PERL_ARCH_PATH => '/usr/local/lib64/perl5',
&VM_DB =>
[
@@ -185,7 +181,6 @@ my $oyVm =
&VM_IMAGE => 'centos:7',
&VM_ARCH => VM_ARCH_AMD64,
&VMDEF_PGSQL_BIN => '/usr/pgsql-{[version]}/bin',
&VMDEF_PERL_ARCH_PATH => '/usr/local/lib64/perl5',
&VMDEF_DEBUG_INTEGRATION => false,
@@ -212,7 +207,6 @@ my $oyVm =
&VM_IMAGE => 'fedora:30',
&VM_ARCH => VM_ARCH_AMD64,
&VMDEF_PGSQL_BIN => '/usr/pgsql-{[version]}/bin',
&VMDEF_PERL_ARCH_PATH => '/usr/local/lib64/perl5',
&VMDEF_DEBUG_INTEGRATION => false,
@@ -241,7 +235,6 @@ my $oyVm =
&VM_IMAGE => 'debian:8',
&VM_ARCH => VM_ARCH_AMD64,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_PERL_ARCH_PATH => '/usr/local/lib/x86_64-linux-gnu/perl/5.20.2',
&VM_DB =>
[
@@ -272,7 +265,6 @@ my $oyVm =
&VM_IMAGE => 'debian:9',
&VM_ARCH => VM_ARCH_AMD64,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_PERL_ARCH_PATH => '/usr/local/lib/i386-linux-gnu/perl/5.24.1',
&VM_DB_TEST =>
[
@@ -300,7 +292,6 @@ my $oyVm =
&VM_IMAGE => 'i386/ubuntu:12.04',
&VM_ARCH => VM_ARCH_I386,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_PERL_ARCH_PATH => '/usr/local/lib/perl/5.14.2',
&VM_DB =>
[
@@ -330,7 +321,6 @@ my $oyVm =
&VM_IMAGE => 'ubuntu:14.04',
&VM_ARCH => VM_ARCH_AMD64,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_PERL_ARCH_PATH => '/usr/local/lib/perl/5.18.2',
&VM_DB =>
[
@@ -361,7 +351,6 @@ my $oyVm =
&VM_IMAGE => 'ubuntu:16.04',
&VM_ARCH => VM_ARCH_AMD64,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_PERL_ARCH_PATH => '/usr/local/lib/x86_64-linux-gnu/perl/5.22.1',
&VMDEF_WITH_BACKTRACE => true,
@@ -394,7 +383,6 @@ my $oyVm =
&VM_ARCH => VM_ARCH_AMD64,
&VMDEF_COVERAGE_C => true,
&VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',
&VMDEF_PERL_ARCH_PATH => '/usr/local/lib/x86_64-linux-gnu/perl/5.26.1',
&VMDEF_WITH_BACKTRACE => true,