Skip to content

Commit 6a2b088

Browse files
committed
PG-1870 Enable WAL encryption in TAP tests
This enables WAL encryption by default when the TAP tests are run with TDE_MODE=1. Use TDE_MODE_WAL=0 to disable wal encryption while still having pg_tde enabled.
1 parent 36e548b commit 6a2b088

File tree

12 files changed

+127
-0
lines changed

12 files changed

+127
-0
lines changed

src/bin/pg_basebackup/t/010_pg_basebackup.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
use PostgreSQL::Test::Utils;
1111
use Test::More;
1212

13+
if ($ENV{TDE_MODE_WAL} and not $ENV{TDE_MODE_NOSKIP})
14+
{
15+
plan skip_all =>
16+
"pg_basebackup without -E from server with encrypted WAL produces broken backups";
17+
}
18+
1319
program_help_ok('pg_basebackup');
1420
program_version_ok('pg_basebackup');
1521
program_options_handling_ok('pg_basebackup');

src/bin/pg_combinebackup/t/003_timeline.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
use PostgreSQL::Test::Utils;
1111
use Test::More;
1212

13+
if ($ENV{TDE_MODE_WAL} and not $ENV{TDE_MODE_NOSKIP})
14+
{
15+
plan skip_all =>
16+
"pg_basebackup without -E from server with encrypted WAL produces broken backups";
17+
}
18+
1319
# Can be changed to test the other modes.
1420
my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
1521

src/bin/pg_combinebackup/t/006_db_file_copy.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
use PostgreSQL::Test::Utils;
88
use Test::More;
99

10+
if ($ENV{TDE_MODE_WAL} and not $ENV{TDE_MODE_NOSKIP})
11+
{
12+
plan skip_all =>
13+
"pg_basebackup without -E from server with encrypted WAL produces broken backups";
14+
}
15+
1016
# Can be changed to test the other modes.
1117
my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
1218

src/bin/pg_combinebackup/t/008_promote.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
use PostgreSQL::Test::Utils;
1111
use Test::More;
1212

13+
if ($ENV{TDE_MODE_WAL} and not $ENV{TDE_MODE_NOSKIP})
14+
{
15+
plan skip_all =>
16+
"pg_basebackup without -E from server with encrypted WAL produces broken backups";
17+
}
18+
1319
# Can be changed to test the other modes.
1420
my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy';
1521

src/bin/pg_rewind/t/001_basic.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
use RewindTest;
1313

14+
if ($ENV{TDE_MODE_WAL} and not $ENV{TDE_MODE_NOSKIP})
15+
{
16+
plan skip_all =>
17+
"copies WAL directly to archive without using archive_command";
18+
}
19+
1420
sub run_test
1521
{
1622
my $test_mode = shift;

src/bin/pg_verifybackup/t/009_extract.pl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
use PostgreSQL::Test::Cluster;
1111
use PostgreSQL::Test::Utils;
1212
use Test::More;
13+
14+
if ($ENV{TDE_MODE_WAL} and not $ENV{TDE_MODE_NOSKIP})
15+
{
16+
plan skip_all =>
17+
"pg_basebackup without -E from server with encrypted WAL produces broken backups";
18+
}
19+
1320
my $primary = PostgreSQL::Test::Cluster->new('primary');
1421
$primary->init(allows_streaming => 1);
1522
$primary->start;

src/bin/pg_waldump/t/001_basic.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
use PostgreSQL::Test::Utils;
88
use Test::More;
99

10+
if ($ENV{TDE_MODE_WAL} and not $ENV{TDE_MODE_NOSKIP})
11+
{
12+
plan skip_all => "pg_waldump needs extra options for encrypted WAL";
13+
}
14+
1015
program_help_ok('pg_waldump');
1116
program_version_ok('pg_waldump');
1217
program_options_handling_ok('pg_waldump');

src/bin/pg_waldump/t/002_save_fullpage.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
use PostgreSQL::Test::Utils;
1010
use Test::More;
1111

12+
if ($ENV{TDE_MODE_WAL} and not $ENV{TDE_MODE_NOSKIP})
13+
{
14+
plan skip_all => "pg_waldump needs extra options for encrypted WAL";
15+
}
16+
1217
my ($blocksize, $walfile_name);
1318

1419
# Function to extract the LSN from the given block structure

src/test/perl/PostgreSQL/Test/TdeCluster.pm

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ our ($tde_template_dir);
1414
BEGIN
1515
{
1616
$ENV{TDE_MODE_NOSKIP} = 0 unless defined($ENV{TDE_MODE_NOSKIP});
17+
$ENV{TDE_MODE_WAL} = 1 unless defined($ENV{TDE_MODE_WAL});
1718
}
1819

1920
sub init
@@ -27,6 +28,12 @@ sub init
2728

2829
$self->_tde_init_principal_key;
2930

31+
if ($ENV{TDE_MODE_WAL})
32+
{
33+
$self->SUPER::append_conf('postgresql.conf',
34+
'pg_tde.wal_encrypt = on');
35+
}
36+
3037
return;
3138
}
3239

@@ -45,6 +52,63 @@ sub append_conf
4552
$self->SUPER::append_conf($filename, $str);
4653
}
4754

55+
sub backup
56+
{
57+
my ($self, $backup_name, %params) = @_;
58+
my $backup_dir = $self->backup_dir . '/' . $backup_name;
59+
60+
mkdir $backup_dir or die "mkdir($backup_dir) failed: $!";
61+
62+
if ($ENV{TDE_MODE_WAL})
63+
{
64+
PostgreSQL::Test::Utils::system_log('cp', '-R', '-P', '-p',
65+
$self->pg_tde_dir, $backup_dir . '/pg_tde',);
66+
67+
# TODO: More thorough checking for options incompatible with --encrypt-wal
68+
$params{backup_options} = [] unless defined $params{backup_options};
69+
unless (
70+
List::Util::any { $_ eq '-Ft' or $_ eq '-Xnone' }
71+
@{ $params{backup_options} })
72+
{
73+
push @{ $params{backup_options} }, '--encrypt-wal';
74+
}
75+
}
76+
77+
$self->SUPER::backup($backup_name, %params);
78+
}
79+
80+
sub enable_archiving
81+
{
82+
my ($self) = @_;
83+
my $path = $self->archive_dir;
84+
85+
$self->SUPER::enable_archiving;
86+
if ($ENV{TDE_MODE_WAL})
87+
{
88+
$self->adjust_conf('postgresql.conf', 'archive_command',
89+
qq('pg_tde_archive_decrypt %f %p "cp \\"%%p\\" \\"$path/%%f\\""')
90+
);
91+
}
92+
93+
return;
94+
}
95+
96+
sub enable_restoring
97+
{
98+
my ($self, $root_node, $standby) = @_;
99+
my $path = $root_node->archive_dir;
100+
101+
$self->SUPER::enable_restoring($root_node, $standby);
102+
if ($ENV{TDE_MODE_WAL})
103+
{
104+
$self->adjust_conf('postgresql.conf', 'restore_command',
105+
qq('pg_tde_restore_encrypt %f %p "cp \\"$path/%%f\\" \\"%%p\\""')
106+
);
107+
}
108+
109+
return;
110+
}
111+
48112
sub pg_tde_dir
49113
{
50114
my ($self) = @_;

src/test/recovery/t/039_end_of_wal.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
use integer; # causes / operator to use integer math
1515

16+
if ($ENV{TDE_MODE_WAL} and not $ENV{TDE_MODE_NOSKIP})
17+
{
18+
plan skip_all => 'uses write_wal to hack wal directly';
19+
}
20+
1621
# Is this a big-endian system ("network" byte order)? We can't use 'Q' in
1722
# pack() calls because it's not available in some perl builds, so we need to
1823
# break 64 bit LSN values into two 'I' values. Fortunately we don't need to

0 commit comments

Comments
 (0)