Skip to content

Commit f629286

Browse files
committed
PS-9771 fix of component_keyring_kmip test fro useage with PyKMIP docker
https://perconadev.atlassian.net/browse/PS-9771 Tests results updated to pass with PyKMIP docker image from https://github.com/Percona-Lab/pxb-jenkins-images; README added to de-mystify KMIP tests; No cleanup after KMIP tests, we use new docker every time. The KMIP keyring backend now checks connexction during initialization, reports error and fails if connection is not successful.
1 parent 820c4fc commit f629286

File tree

10 files changed

+90
-77
lines changed

10 files changed

+90
-77
lines changed

components/keyrings/keyring_kmip/backend/backend.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,19 @@ using keyring_common::utils::get_random_data;
4646

4747
Keyring_kmip_backend::Keyring_kmip_backend(config::Config_pod const &config)
4848
: valid_(false), config_(config) {
49-
valid_ = true;
49+
// check network connection before declaring valid
50+
try {
51+
auto ctx = kmip_ctx();
52+
valid_ = true;
53+
} catch (std::exception const &e) {
54+
valid_ = false;
55+
std::string err_msg =
56+
"Can not connect to KMIP server. Config: " + config_.server_addr + " " +
57+
config_.server_port + " " + config_.client_ca + " " +
58+
config_.client_key + " " + config_.server_ca + " " +
59+
"Exception:" + e.what();
60+
LogComponentErr(ERROR_LEVEL, ER_LOG_PRINTF_MSG, err_msg.c_str());
61+
}
5062
}
5163

5264
bool Keyring_kmip_backend::load_cache(

mysql-test/std_data/kmip_clear.py

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## HOW TO run KMIP test suite
2+
3+
The [PyKMIP](https://github.com/OpenKMIP/PyKMIP) server is used to run this test suite. It could be run locally or in the Docker. The source of the docker image is [here](https://github.com/Percona-Lab/pxb-jenkins-images).
4+
5+
This is simple script to run this image:
6+
```
7+
#!/bin/bash
8+
CERTS_DIR=/tmp/certs
9+
docker stop kmip
10+
docker run -d --security-opt seccomp=unconfined --cap-add=NET_ADMIN --rm -p 5696:5696 --name kmip satyapercona/kmip:latest
11+
mkdir /tmp/certs
12+
docker cp kmip:/opt/certs/root_certificate.pem $CERTS_DIR/vault-kmip-ca.pem
13+
docker cp kmip:/opt/certs/client_key_jane_doe.pem $CERTS_DIR/mysql-client-key.pem
14+
docker cp kmip:/opt/certs/client_certificate_jane_doe.pem $CERTS_DIR/mysql-client-cert.pem
15+
```
16+
17+
Please note, that certificates and keys are copied to the certain location and renamed.This is important, because some tests from the suite are sensitive to that names.
18+
19+
Before running the test suite, the following environment variables should be exported:
20+
21+
```
22+
CERTS_DIR=/tmp/certs
23+
export KMIP_ADDR="127.0.0.1"
24+
export KMIP_PORT="5696"
25+
export KMIP_CLIENT_CA="$CERTS_DIR/mysql-client-cert.pem"
26+
export KMIP_CLIENT_KEY="$CERTS_DIR/mysql-client-key.pem"
27+
export KMIP_SERVER_CA="$CERTS_DIR/vault-kmip-ca.pem"
28+
```
29+
Now you can run KMIP keyring tests:
30+
31+
```
32+
./mtr --big-test --suite component_keyring_kmip
33+
```
34+
If you want to run the test with other KMIP server, please note the following:
35+
1. Copy keys and certificates to ```/tmp/certs``` directory with names as above and export variables.
36+
2. Some servers does not support RSA-512 keys used by all keyring tests, so you can have some failing tests.
37+
3. To setup KMIP servers, please refer to [this document](https://www.notion.so/percona/KMIP-Testing-1fb674d091f3809cbfbdf31369e22d35).

mysql-test/suite/component_keyring_kmip/inc/setup_component.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
# Create local keyring config
2424
--let KEYRING_KMIP_PATH = `SELECT CONCAT( '$MYSQLTEST_VARDIR', '/keyring_kmip')`
25-
--let KEYRING_CONFIG_CONTENT = `SELECT CONCAT('{ \"path\": \"', '$KEYRING_KMIP_PATH', '\", \"server_addr\": \"', '$KMIP_ADDR', '\", \"server_port\": \"', '$KMIP_PORT', '\", \"client_ca\": \"', '$KMIP_CLIENT_CA', '\", \"client_key\": \"', '$KMIP_CLIENT_KEY', '\", \"server_ca\": \"', '$KMIP_SERVER_CA', '\" }')`
25+
--let KEYRING_CONFIG_CONTENT = `SELECT CONCAT('{ \"path\": \"', '$KEYRING_KMIP_PATH', '\", \"server_addr\": \"', '$KMIP_ADDR', '\", \"server_port\": \"', '$KMIP_PORT', '\", \"client_ca\": \"', '$KMIP_CLIENT_CA', '\", \"client_key\": \"', '$KMIP_CLIENT_KEY', '\", \"server_ca\": \"', '$KMIP_SERVER_CA', '\", \"object_group\": \"', 'test-object-group', '\" }')`
2626
--source include/keyring_tests/helper/local_keyring_create_config.inc
2727

2828
# Create local manifest file for current server instance

mysql-test/suite/component_keyring_kmip/inc/setup_component_customized.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Create global keyring config
1616
--let KEYRING_KMIP_PATH = `SELECT CONCAT( '$MYSQLTEST_VARDIR', '/keyring_kmip')`
17-
--let KEYRING_CONFIG_CONTENT = `SELECT CONCAT('{ \"path\": \"', '$KEYRING_KMIP_PATH','\", \"server_addr\": \"127.0.0.1\", \"server_port\": \"5696\", \"client_ca\": \"/home/dutow/.local/etc/pykmip/client_certificate_jane_doe.pem\", \"client_key\":\"/home/dutow/.local/etc/pykmip/client_key_jane_doe.pem\", \"server_ca\":\"/home/dutow/.local/etc/pykmip/root_certificate.pem\" }')`
17+
--let KEYRING_CONFIG_CONTENT = `SELECT CONCAT('{ \"path\": \"', '$KEYRING_KMIP_PATH','\", \"server_addr\": \"127.0.0.1\", \"server_port\": \"5696\", \"client_ca\": \"/tmp/certs/mysql-client-cert.pem\", \"client_key\":\"/tmp/certs/mysql-client-key.pem\", \"server_ca\":\"/tmp/certs/vault-kmip-ca.pem\" }')`
1818
--source include/keyring_tests/helper/global_keyring_create_customized_config.inc
1919

2020
# Restart server with manifest file

mysql-test/suite/component_keyring_kmip/inc/teardown_component.inc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@
1717
# Restart server without manifest file
1818
--source include/keyring_tests/helper/cleanup_server_with_manifest.inc
1919
--echo # ----------------------------------------------------------------------
20-
21-
--exec python std_data/kmip_clear.py

mysql-test/suite/component_keyring_kmip/t/import_compress_encrypt.result

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ SELECT c1, HEX(SUBSTRING(c2, 10, 10)), HEX(SUBSTRING(c3, 10, 10)),
3030
HEX(SUBSTRING(c4, 10, 10)), HEX(b)
3131
FROM t1 ORDER BY c1 limit 10;
3232
c1 HEX(SUBSTRING(c2, 10, 10)) HEX(SUBSTRING(c3, 10, 10)) HEX(SUBSTRING(c4, 10, 10)) HEX(b)
33-
50001 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
34-
50002 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
35-
50003 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
36-
50004 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
37-
50005 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
38-
50006 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
39-
50007 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
40-
50008 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
41-
50009 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
42-
50010 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
33+
50001 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
34+
50002 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
35+
50003 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
36+
50004 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
37+
50005 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
38+
50006 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
39+
50007 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
40+
50008 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
41+
50009 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
42+
50010 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
4343
# Flush tables for export
4444
FLUSH TABLES t1 FOR EXPORT;
4545
# Copy .cfp .cfg .ibd file to temp
@@ -59,16 +59,16 @@ ALTER TABLE t1 IMPORT TABLESPACE;
5959
SELECT c1, HEX(SUBSTRING(c2, 10, 10)), HEX(SUBSTRING(c3, 10, 10)),
6060
HEX(SUBSTRING(c4, 10, 10)), HEX(b) FROM t1 ORDER BY c1 limit 10;
6161
c1 HEX(SUBSTRING(c2, 10, 10)) HEX(SUBSTRING(c3, 10, 10)) HEX(SUBSTRING(c4, 10, 10)) HEX(b)
62-
50001 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
63-
50002 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
64-
50003 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
65-
50004 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
66-
50005 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
67-
50006 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
68-
50007 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
69-
50008 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
70-
50009 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
71-
50010 066C8ADC3EC72175CA77 6C8ADC3EC72175CA77CE 77CEF1FBCA5BFE739000 A
62+
50001 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
63+
50002 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
64+
50003 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
65+
50004 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
66+
50005 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
67+
50006 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
68+
50007 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
69+
50008 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
70+
50009 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
71+
50010 51AB8660A7143704DEA7 AB8660A7143704DEA78C A78C87578839E440B5B3 A
7272
# Cleanup
7373
DROP TABLE t1;
7474

mysql-test/suite/component_keyring_kmip/t/keyring_component_status.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ Version 1.0
2020
Component_status Active
2121
Server_addr 127.0.0.1
2222
Server_port 5696
23-
Client_ca /home/dutow/.local/etc/pykmip/client_certificate_jane_doe.pem
24-
Client_key /home/dutow/.local/etc/pykmip/client_key_jane_doe.pem
25-
Server_ca /home/dutow/.local/etc/pykmip/root_certificate.pem
26-
Object_group <NONE>
23+
Client_ca /tmp/certs/mysql-client-cert.pem
24+
Client_key /tmp/certs/mysql-client-key.pem
25+
Server_ca /tmp/certs/vault-kmip-ca.pem
26+
Object_group test-object-group
2727
SELECT PRIO, ERROR_CODE, SUBSYSTEM, DATA FROM performance_schema.error_log WHERE ERROR_CODE='MY-013712';
2828
PRIO ERROR_CODE SUBSYSTEM DATA
2929
# Restarting server without keyring component

mysql-test/suite/component_keyring_kmip/t/log_encrypt_3.result

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ USE tde_db;
1111
# Kill the server
1212
SELECT @@global.innodb_redo_log_encrypt ;
1313
@@global.innodb_redo_log_encrypt
14-
ON
14+
1
1515
SET GLOBAL innodb_redo_log_encrypt = 1;
1616
SELECT @@global.innodb_redo_log_encrypt ;
1717
@@global.innodb_redo_log_encrypt
18-
ON
18+
1
1919
CREATE TABLE tde_db.t1 (a BIGINT PRIMARY KEY, b LONGBLOB) ENGINE=InnoDB;
2020
INSERT INTO t1 (a, b) VALUES (1, REPEAT('a', 6*512*512));
2121
SELECT a,LEFT(b,10) FROM tde_db.t1;
@@ -30,7 +30,7 @@ a LEFT(b,10)
3030
SET GLOBAL innodb_redo_log_encrypt = 0;
3131
SELECT @@global.innodb_redo_log_encrypt ;
3232
@@global.innodb_redo_log_encrypt
33-
OFF
33+
0
3434
CREATE TABLE tde_db.t3 (a BIGINT PRIMARY KEY, b LONGBLOB) ENGINE=InnoDB;
3535
INSERT INTO t3 (a, b) VALUES (1, REPEAT('a', 6*512*512));
3636
SELECT a,LEFT(b,10) FROM tde_db.t3;
@@ -59,7 +59,7 @@ a LEFT(b,10)
5959
DROP TABLE tde_db.t1,tde_db.t2,tde_db.t3,tde_db.t4;
6060
SELECT @@global.innodb_redo_log_encrypt ;
6161
@@global.innodb_redo_log_encrypt
62-
ON
62+
1
6363
CREATE TABLE tde_db.t1 (a BIGINT PRIMARY KEY, b LONGBLOB) ENGINE=InnoDB;
6464
CREATE TABLE tde_db.t2 (a BIGINT PRIMARY KEY, b LONGBLOB)
6565
ENCRYPTION='Y' ENGINE=InnoDB;
@@ -91,7 +91,7 @@ START TRANSACTION;
9191
SET GLOBAL innodb_redo_log_encrypt = 0;
9292
SELECT @@global.innodb_redo_log_encrypt ;
9393
@@global.innodb_redo_log_encrypt
94-
OFF
94+
0
9595
INSERT INTO t3 (a, b) VALUES (1, REPEAT('a', 6*512*512));
9696
INSERT INTO t4 (a, b) VALUES (1, REPEAT('a', 6*512*512));
9797
SELECT a,LEFT(b,10) FROM tde_db.t3;
@@ -127,7 +127,7 @@ a LEFT(b,10)
127127
SET GLOBAL innodb_redo_log_encrypt = 0;
128128
SELECT @@global.innodb_redo_log_encrypt ;
129129
@@global.innodb_redo_log_encrypt
130-
OFF
130+
0
131131
ALTER INSTANCE ROTATE INNODB MASTER KEY;
132132
SELECT a,LEFT(b,10) FROM tde_db.t1;
133133
a LEFT(b,10)
@@ -144,7 +144,7 @@ a LEFT(b,10)
144144
SET GLOBAL innodb_redo_log_encrypt = 1;
145145
SELECT @@global.innodb_redo_log_encrypt ;
146146
@@global.innodb_redo_log_encrypt
147-
ON
147+
1
148148
ALTER INSTANCE ROTATE INNODB MASTER KEY;
149149
SELECT a,LEFT(b,10) FROM tde_db.t1;
150150
a LEFT(b,10)
@@ -164,12 +164,12 @@ FLUSH PRIVILEGES;
164164
# In connection 1 - with encryptnonprivuser
165165
SELECT @@global.innodb_redo_log_encrypt ;
166166
@@global.innodb_redo_log_encrypt
167-
ON
167+
1
168168
SET GLOBAL innodb_redo_log_encrypt = 0;
169169
ERROR 42000: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation
170170
SELECT @@global.innodb_redo_log_encrypt ;
171171
@@global.innodb_redo_log_encrypt
172-
ON
172+
1
173173
SET GLOBAL innodb_undo_log_encrypt = 0;
174174
ERROR 42000: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation
175175
SELECT @@global.innodb_undo_log_encrypt ;
@@ -179,7 +179,7 @@ SET GLOBAL innodb_redo_log_encrypt = 1;
179179
ERROR 42000: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation
180180
SELECT @@global.innodb_redo_log_encrypt ;
181181
@@global.innodb_redo_log_encrypt
182-
ON
182+
1
183183
SET GLOBAL innodb_undo_log_encrypt = 1;
184184
ERROR 42000: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation
185185
SELECT @@global.innodb_undo_log_encrypt ;

mysql-test/suite/component_keyring_kmip/t/tablespace_encrypt_3.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ events_stages_history YES
5252
events_stages_history_long YES
5353
SELECT * FROM performance_schema.setup_instruments
5454
WHERE NAME LIKE "%encryption%";
55-
NAME ENABLED TIMED PROPERTIES VOLATILITY DOCUMENTATION
56-
wait/synch/mutex/innodb/resume_encryption_cond_mutex YES YES 0 NULL
57-
wait/synch/cond/innodb/resume_encryption_cond YES YES 0 NULL
58-
stage/innodb/alter tablespace (encryption) YES YES progress 0 NULL
55+
NAME ENABLED TIMED PROPERTIES FLAGS VOLATILITY DOCUMENTATION
56+
wait/synch/mutex/innodb/resume_encryption_cond_mutex YES YES NULL 0 NULL
57+
wait/synch/cond/innodb/resume_encryption_cond YES YES NULL 0 NULL
58+
stage/innodb/alter tablespace (encryption) YES YES progress NULL 0 NULL
5959
select count(*) from performance_schema.events_stages_current
6060
WHERE EVENT_NAME='stage/innodb/alter tablespace (encryption)';
6161
count(*)

0 commit comments

Comments
 (0)