2017-06-23 00:22:49 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# S3 SSL Certificate Tests
|
|
|
|
#
|
|
|
|
# Verify that SSL certificate validation works on live S3 servers.
|
|
|
|
####################################################################################################################################
|
2018-04-24 15:12:25 +02:00
|
|
|
package pgBackRestTest::Module::Storage::StorageS3CertPerlTest;
|
2017-06-23 00:22:49 +02:00
|
|
|
use parent 'pgBackRestTest::Env::ConfigEnvTest';
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
use English '-no_match_vars';
|
|
|
|
|
|
|
|
use Storable qw(dclone);
|
|
|
|
|
|
|
|
use pgBackRest::Common::Exception;
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::Wait;
|
|
|
|
use pgBackRest::Config::Config;
|
|
|
|
use pgBackRest::Protocol::Storage::Helper;
|
|
|
|
|
|
|
|
use pgBackRestTest::Common::RunTest;
|
|
|
|
use pgBackRestTest::Common::VmTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# run
|
|
|
|
####################################################################################################################################
|
|
|
|
sub run
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Use long random string so bucket lookups will fail and expose access errors
|
|
|
|
my $strBucket = 'bnBfyKpXR8ZqQY5RXszxemRgvtmjXd4tf5HkFYhTpT9BndUCYMDy5NCCyRz';
|
|
|
|
my $strEndpoint = 's3-us-west-2.amazonaws.com';
|
|
|
|
my $strRegion = 'us-west-2';
|
|
|
|
|
|
|
|
# Options
|
2017-08-25 22:47:47 +02:00
|
|
|
$self->optionTestSet(CFGOPT_REPO_TYPE, CFGOPTVAL_REPO_TYPE_S3);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_KEY, BOGUS);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_KEY_SECRET, BOGUS);
|
2018-05-02 20:06:40 +02:00
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_TOKEN, BOGUS);
|
2017-08-25 22:47:47 +02:00
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_BUCKET, $strBucket);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_ENDPOINT, $strEndpoint);
|
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_REGION, $strRegion);
|
|
|
|
$self->optionTestSet(CFGOPT_STANZA, $self->stanza());
|
2017-06-23 00:22:49 +02:00
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
$self->configTestLoad(CFGCMD_ARCHIVE_PUSH);
|
2017-06-23 00:22:49 +02:00
|
|
|
|
|
|
|
################################################################################################################################
|
|
|
|
if ($self->begin('validation'))
|
|
|
|
{
|
2017-06-27 21:58:02 +02:00
|
|
|
if ($self->vm eq VM_U12)
|
2017-06-23 00:22:49 +02:00
|
|
|
{
|
2017-06-27 21:58:02 +02:00
|
|
|
&log(INFO, 'cannot test - certificates are no longer maintained for ' . $self->vm());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($self->vm() eq VM_CO7)
|
|
|
|
{
|
|
|
|
# Tests fails on co7 because by default certs cannot be located. This logic may need to be changed in the future if
|
|
|
|
# this bug gets fixed by Red Hat.
|
|
|
|
$self->testException(
|
|
|
|
sub {storageRepo({strStanza => 'test1'})->list('/')}, ERROR_HOST_CONNECT,
|
|
|
|
'IO::Socket::IP configuration failed SSL connect attempt failed.*certificate verify failed',
|
|
|
|
'cert verify fails on ' . VM_CO7);
|
|
|
|
|
|
|
|
# It should work when verification is disabled
|
2017-08-25 22:47:47 +02:00
|
|
|
$self->optionTestSetBool(CFGOPT_REPO_S3_VERIFY_SSL, false);
|
|
|
|
$self->configTestLoad(CFGCMD_ARCHIVE_PUSH);
|
2017-06-27 21:58:02 +02:00
|
|
|
|
|
|
|
$self->testException(
|
|
|
|
sub {storageRepo({strStanza => 'test2'})->list('/')}, ERROR_PROTOCOL, 'S3 request error \[403\] Forbidden.*',
|
|
|
|
'connection succeeds with verification disabled, (expected) error on invalid access key');
|
2017-08-25 22:47:47 +02:00
|
|
|
|
|
|
|
$self->optionTestClear(CFGOPT_REPO_S3_VERIFY_SSL);
|
|
|
|
$self->configTestLoad(CFGCMD_ARCHIVE_PUSH);
|
2017-06-27 21:58:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
# CO7 doesn't locate certs automatically so specify the path
|
|
|
|
if ($self->vm() eq VM_CO7)
|
|
|
|
{
|
2017-08-25 22:47:47 +02:00
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_CA_FILE, '/etc/pki/tls/certs/ca-bundle.crt');
|
|
|
|
$self->configTestLoad(CFGCMD_ARCHIVE_PUSH);
|
2017-06-27 21:58:02 +02:00
|
|
|
}
|
2017-06-23 00:22:49 +02:00
|
|
|
|
|
|
|
$self->testException(
|
2017-06-27 21:58:02 +02:00
|
|
|
sub {storageRepo({strStanza => 'test3'})->list('/')}, ERROR_PROTOCOL, 'S3 request error \[403\] Forbidden.*',
|
|
|
|
'connection succeeds, (expected) error on invalid access key');
|
2017-06-23 00:22:49 +02:00
|
|
|
|
2017-08-25 22:47:47 +02:00
|
|
|
if ($self->vm() eq VM_CO7)
|
|
|
|
{
|
|
|
|
$self->optionTestClear(CFGOPT_REPO_S3_CA_FILE);
|
|
|
|
$self->configTestLoad(CFGCMD_ARCHIVE_PUSH);
|
|
|
|
}
|
|
|
|
|
2017-06-27 21:58:02 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2017-08-25 22:47:47 +02:00
|
|
|
$self->optionTestSet(CFGOPT_REPO_S3_CA_PATH, '/bogus');
|
|
|
|
$self->configTestLoad(CFGCMD_ARCHIVE_PUSH);
|
2017-06-23 00:22:49 +02:00
|
|
|
|
2017-06-27 21:58:02 +02:00
|
|
|
$self->testException(
|
|
|
|
sub {storageRepo({strStanza => 'test4'})->list('/')}, ERROR_HOST_CONNECT,
|
|
|
|
$self->vm() eq VM_CO6 ? 'IO::Socket::INET configuration failed' : 'SSL_ca_path /bogus does not exist',
|
|
|
|
'invalid ca path');
|
2017-06-23 00:22:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|