Skip to content

Commit fdb5223

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 8f52b31 commit fdb5223

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+
"pg_tde_restore_encrypt gets a WAL segment of invalid size";
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
@@ -15,6 +15,7 @@ our ($tde_template_dir);
1515
BEGIN
1616
{
1717
$ENV{TDE_MODE_NOSKIP} = 0 unless defined($ENV{TDE_MODE_NOSKIP});
18+
$ENV{TDE_MODE_WAL} = 1 unless defined($ENV{TDE_MODE_WAL});
1819
}
1920

2021
sub init
@@ -28,6 +29,12 @@ sub init
2829

2930
$self->_tde_init_principal_key;
3031

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

@@ -46,6 +53,63 @@ sub append_conf
4653
$self->SUPER::append_conf($filename, $str);
4754
}
4855

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