Skip to content

Commit

Permalink
Updating CI scripts after recent changes (percona#129)
Browse files Browse the repository at this point in the history
This commit removes outdated keyring configuration code, and
adds vault support to all runners.

Also contains fixes to the vault and file providers.
  • Loading branch information
dutow authored Feb 29, 2024
1 parent 57cf804 commit c4b549d
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 149 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/postgresql-16-pgdg-package-pgxs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jobs:
libjson-c-dev libcurl4-openssl-dev
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install -y vault
- name: Install PG Distribution Postgresql 16
run: |
Expand Down Expand Up @@ -57,15 +61,20 @@ jobs:

- name: Start pg_tde tests
run: |
TV=$(mktemp)
{ exec >$TV; vault server -dev; } &
sleep 10
export ROOT_TOKEN=$(cat $TV | grep "Root Token" | cut -d ":" -f 2 | xargs echo -n)
echo "Root token: $ROOT_TOKEN"
sudo psql -V
sudo service postgresql stop
echo "shared_preload_libraries = 'pg_tde'" |
sudo tee -a /etc/postgresql/16/main/postgresql.conf
echo "pg_tde.keyringConfigFile = '/tmp/keyring.json'" |
sudo tee -a /etc/postgresql/16/main/postgresql.conf
cp keyring.json /tmp/keyring.json
sudo service postgresql start
sudo psql -V
sudo -u postgres bash -c 'make installcheck USE_PGXS=1'
sudo -u postgres bash -c "export ROOT_TOKEN=$ROOT_TOKEN && make installcheck USE_PGXS=1"
working-directory: src/pg_tde

- name: Report on test fail
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/postgresql-16-src-make-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: macos-12
steps:
- name: Install dependencies
run: brew install json-c # All other required deps already installed in this image.
run: brew install json-c vault gnu-sed # All other required deps already installed in this image.

- name: Clone postgres repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -47,13 +47,15 @@ jobs:
initdb -D $HOME/pgsql/data
echo "shared_preload_libraries = 'pg_tde'" >> \
/$HOME/pgsql/data/postgresql.conf
echo "pg_tde.keyringConfigFile = '/tmp/keyring.json'" >> \
$HOME/pgsql/data/postgresql.conf
cp src/contrib/pg_tde/keyring.json /tmp/keyring.json
pg_ctl -D $HOME/pgsql/data -l logfile start
- name: Test pg_tde
run: |
TV=$(mktemp)
{ exec >$TV; vault server -dev; } &
sleep 10
export ROOT_TOKEN=$(cat $TV | grep "Root Token" | cut -d ":" -f 2 | xargs echo -n)
echo "Root token: $ROOT_TOKEN"
make installcheck
working-directory: src/contrib/pg_tde

Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/postgresql-16-src-make-ssl11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
uuid-dev liblz4-dev libjson-c-dev libcurl4-openssl-dev
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install -y vault
- name: Clone postgres repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -66,13 +69,15 @@ jobs:
initdb -D /opt/pgsql/data
echo "shared_preload_libraries = 'pg_tde'" >> \
/opt/pgsql/data/postgresql.conf
echo "pg_tde.keyringConfigFile = '/tmp/keyring.json'" >> \
/opt/pgsql/data/postgresql.conf
cp src/contrib/pg_tde/keyring.json /tmp/keyring.json
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Test pg_tde
run: |
TV=$(mktemp)
{ exec >$TV; vault server -dev; } &
sleep 10
export ROOT_TOKEN=$(cat $TV | grep "Root Token" | cut -d ":" -f 2 | xargs echo -n)
echo "Root token: $ROOT_TOKEN"
make installcheck
working-directory: src/contrib/pg_tde

Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/postgresql-16-src-make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
uuid-dev liblz4-dev libjson-c-dev libcurl4-openssl-dev
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install -y vault
- name: Clone postgres repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -66,13 +69,15 @@ jobs:
initdb -D /opt/pgsql/data
echo "shared_preload_libraries = 'pg_tde'" >> \
/opt/pgsql/data/postgresql.conf
echo "pg_tde.keyringConfigFile = '/tmp/keyring.json'" >> \
/opt/pgsql/data/postgresql.conf
cp src/contrib/pg_tde/keyring.json /tmp/keyring.json
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Test pg_tde
run: |
TV=$(mktemp)
{ exec >$TV; vault server -dev; } &
sleep 10
export ROOT_TOKEN=$(cat $TV | grep "Root Token" | cut -d ":" -f 2 | xargs echo -n)
echo "Root token: $ROOT_TOKEN"
make installcheck
working-directory: src/contrib/pg_tde

Expand Down
14 changes: 2 additions & 12 deletions .github/workflows/postgresql-16-src-meson-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,13 @@ jobs:
cd build && ninja && ninja install
working-directory: src

- name: Test pg_tde with keyring_file
run: |
cp ../contrib/pg_tde/keyring.json /tmp/keyring.json
meson test --suite setup -v
meson test --suite pg_tde -v --num-processes 1
working-directory: src/build

- name: Test pg_tde with keyring_vault
- name: Test pg_tde
run: |
TV=$(mktemp)
{ exec >$TV; vault server -dev; } &
sleep 10
ROOT_TOKEN=$(cat $TV | grep "Root Token" | cut -d ":" -f 2 | xargs echo -n)
export ROOT_TOKEN=$(cat $TV | grep "Root Token" | cut -d ":" -f 2 | xargs echo -n)
echo "Root token: $ROOT_TOKEN"
cp ../contrib/pg_tde/keyring-vault.json /tmp/keyring.json
gsed -i "s/ROOT_TOKEN/$ROOT_TOKEN/g" /tmp/keyring.json
cat /tmp/keyring.json
meson test --suite setup -v
meson test --suite pg_tde -v --num-processes 1
working-directory: src/build
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/postgresql-16-src-meson-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
sysbench libcurl4-openssl-dev
sudo /usr/bin/perl -MCPAN -e 'install IPC::RUN'
sudo /usr/bin/perl -MCPAN -e 'install Text::Trim'
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install -y vault
- name: Clone postgres repository
uses: actions/checkout@v2
Expand All @@ -58,7 +62,12 @@ jobs:

- name: Test pg_tde
run: |
cp ../contrib/pg_tde/keyring.json /tmp/keyring.json
TV=$(mktemp)
{ exec >$TV; vault server -dev; } &
sleep 10
export ROOT_TOKEN=$(cat $TV | grep "Root Token" | cut -d ":" -f 2 | xargs echo -n)
echo "Root token: $ROOT_TOKEN"
meson test --suite setup -v
meson test --suite pg_tde -v --num-processes 1
working-directory: src/build
Expand Down
27 changes: 4 additions & 23 deletions .github/workflows/postgresql-16-src-meson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,14 @@ jobs:
cd build && ninja && ninja install
working-directory: src

- name: Test pg_tde with keyring_file
run: |
cp ../contrib/pg_tde/keyring.json /tmp/keyring.json
meson test --suite setup -v
meson test --suite pg_tde -v --num-processes 1
working-directory: src/build

- name: Report on test fail
uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: Regressions diff and postgresql log
path: |
src/build/testrun/pg_tde/regress/
retention-days: 3

- name: Test pg_tde with keyring_vault
- name: Test pg_tde
run: |
TV=$(mktemp)
{ exec >$TV; vault server -dev; } &
sleep 10
ROOT_TOKEN=$(cat $TV | grep "Root Token" | cut -d ":" -f 2 | xargs echo -n)
export ROOT_TOKEN=$(cat $TV | grep "Root Token" | cut -d ":" -f 2 | xargs echo -n)
echo "Root token: $ROOT_TOKEN"
cp ../contrib/pg_tde/keyring-vault.json /tmp/keyring.json
sed -i "s/ROOT_TOKEN/$ROOT_TOKEN/g" /tmp/keyring.json
cat /tmp/keyring.json
meson test --suite setup -v
meson test --suite pg_tde -v --num-processes 1
working-directory: src/build
Expand All @@ -93,5 +75,4 @@ jobs:
name: Regressions diff and postgresql log
path: |
src/build/testrun/pg_tde/regress/
retention-days: 3

retention-days: 3
3 changes: 2 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ update_compare_indexes \
pgtde_is_encrypted \
multi_insert \
trigger_on_view \
insert_update_delete
insert_update_delete \
vault_v2_test
TAP_TESTS = 1

OBJS = src/encryption/enc_tde.o \
Expand Down
2 changes: 0 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ RUN cp /usr/share/postgresql/postgresql.conf.sample /etc/postgresql/postgresql.c
echo "shared_preload_libraries = 'pg_tde'" >> /etc/postgresql/postgresql.conf; \
# echo "log_min_messages = debug3" >> /etc/postgresql/postgresql.conf; \
# echo "log_min_error_statement = debug3" >> /etc/postgresql/postgresql.conf; \
echo "pg_tde.keyringConfigFile = '/etc/postgresql/tde_conf.json'" >> /etc/postgresql/postgresql.conf; \
echo "{'provider': 'file','datafile': '/etc/postgresql/pgkeyring',}" > /etc/postgresql/tde_conf.json; \
chown postgres /etc/postgresql/tde_conf.json; \
mkdir -p /docker-entrypoint-initdb.d
COPY ./docker/pg-tde-create-ext.sh /docker-entrypoint-initdb.d/pg-tde-create-ext.sh
Expand Down
12 changes: 12 additions & 0 deletions expected/insert_update_delete.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
CREATE EXTENSION pg_tde;
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
pg_tde_add_key_provider_file
------------------------------
1
(1 row)

SELECT pg_tde_set_master_key('test-db-master-key','file-vault');
pg_tde_set_master_key
-----------------------

(1 row)

CREATE TABLE albums (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
artist VARCHAR(256),
Expand Down
3 changes: 2 additions & 1 deletion expected/vault_v2_test.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE EXTENSION pg_tde;
SELECT pg_tde_add_key_provider_vault_v2('vault-v2','ROOT_TOKEN','http://127.0.0.1:8200','secret',NULL);
\getenv root_token ROOT_TOKEN
SELECT pg_tde_add_key_provider_vault_v2('vault-v2',:'root_token','http://127.0.0.1:8200','secret',NULL);
pg_tde_add_key_provider_vault_v2
----------------------------------
1
Expand Down
6 changes: 0 additions & 6 deletions keyring-vault.json

This file was deleted.

4 changes: 0 additions & 4 deletions keyring.json

This file was deleted.

1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ tests += {
'multi_insert',
'trigger_on_view',
'insert_update_delete',
'vault_v2_test',
],
'regress_args': ['--temp-config', files('pg_tde.conf')],
'runningcheck': false,
Expand Down
1 change: 0 additions & 1 deletion pg_tde.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
shared_preload_libraries = 'pg_tde'
pg_tde.keyringConfigFile = '/tmp/keyring.json'
3 changes: 3 additions & 0 deletions sql/insert_update_delete.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CREATE EXTENSION pg_tde;

SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
SELECT pg_tde_set_master_key('test-db-master-key','file-vault');

CREATE TABLE albums (
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
artist VARCHAR(256),
Expand Down
3 changes: 2 additions & 1 deletion sql/vault_v2_test.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE EXTENSION pg_tde;

SELECT pg_tde_add_key_provider_vault_v2('vault-v2','ROOT_TOKEN','http://127.0.0.1:8200','secret',NULL);
\getenv root_token ROOT_TOKEN
SELECT pg_tde_add_key_provider_vault_v2('vault-v2',:'root_token','http://127.0.0.1:8200','secret',NULL);
SELECT pg_tde_set_master_key('vault-v2-master-key','vault-v2');

CREATE TABLE test_enc(
Expand Down
2 changes: 0 additions & 2 deletions src/include/keyring/keyring_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ enum KeyringProvider
} ;

extern enum KeyringProvider keyringProvider;
extern char* keyringConfigFile;
extern char* keyringKeyPrefix;

void keyringRegisterVariables(void);

Expand Down
74 changes: 1 addition & 73 deletions src/keyring/keyring_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,11 @@

#include "utils/guc.h"

char* keyringConfigFile = "";
char* keyringKeyPrefix = "";
enum KeyringProvider keyringProvider = PROVIDER_UNKNOWN;

static bool keyringCheckKeyPrefix(char **newval, void **extra, GucSource source)
{
if(*newval == NULL || strlen(*newval) == 0)
{
return 1; // empty
}

if(strlen(*newval) > 32)
{
elog(ERROR, "The maximum length of pg_tde.keyringKeyPrefix is 32 characters.");
return 0;
}

return 1;
}

static bool keyringCheckConfigFile(char **newval, void **extra, GucSource source)
{
if(*newval == NULL || strlen(*newval) == 0)
{
return 1; // empty
}

if(access(*newval, R_OK) != 0)
{
elog(ERROR, "The file referenced by pg_tde.keyringConfigFile doesn't exists, or is not readable to postgres");
return 0;
}

if(access(*newval, W_OK) == 0)
{
elog(WARNING, "The file referenced by pg_tde.keyringConfigFile is writable for the database process");
}

return 1;
}

static void keyringAssignConfigFile(const char *newval, void *extra)
{
// TODO: make sure we only load the configuration once...
if(newval == NULL || strlen(newval) == 0)
{
//elog(WARNING, "pg_tde.keyringConfigFile is empty. Encryption features will not be available.");
return;
}
}

void keyringRegisterVariables(void)
{

DefineCustomStringVariable("pg_tde.keyringConfigFile", /* name */
"Location of the configuration file for the keyring", /* short_desc */
NULL, /* long_desc */
&keyringConfigFile, /* value address */
"", /* boot value */
PGC_POSTMASTER, /* context */
0, /* flags */
&keyringCheckConfigFile, /* check_hook */
&keyringAssignConfigFile, /* assign_hook */
NULL /* show_hook */
);

DefineCustomStringVariable("pg_tde.keyringKeyPrefix", /* name */
"Location of the configuration file for the keyring", /* short_desc */
NULL, /* long_desc */
&keyringKeyPrefix, /* value address */
"", /* boot value */
PGC_POSTMASTER, /* context */
0, /* flags */
&keyringCheckKeyPrefix, /* check_hook */
NULL, /* assign_hook */
NULL /* show_hook */
);
// nop for now
}

const char* keyringParseStringParam(json_object* object)
Expand Down
Loading

0 comments on commit c4b549d

Please sign in to comment.