Skip to content

Commit a106968

Browse files
authored
Merge pull request #570 from ionut-arm/sqlite-kim-default
Make SQLite KIM default
2 parents e8a2c4e + 06c81f8 commit a106968

17 files changed

+165
-135
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ jobs:
118118
# When running the container built on the CI
119119
# run: CONTAINER_TAG=parsec-service-test-all ./fuzz.sh test
120120

121-
sqlite-kim:
122-
name: SQLiteKIM E2E tests on all providers
121+
on-disk-kim:
122+
name: OnDiskKIM E2E tests on all providers
123123
runs-on: ubuntu-latest
124124
steps:
125125
- uses: actions/checkout@v2
@@ -128,9 +128,9 @@ jobs:
128128
# run: pushd e2e_tests/docker_image && docker build -t parsec-service-test-all -f parsec-service-test-all.Dockerfile . && popd
129129
- name: Run the container to execute the test script
130130
run:
131-
docker run -v $(pwd):/tmp/parsec -w /tmp/parsec ghcr.io/parallaxsecond/parsec-service-test-all /tmp/parsec/ci.sh sqlite-kim
131+
docker run -v $(pwd):/tmp/parsec -w /tmp/parsec ghcr.io/parallaxsecond/parsec-service-test-all /tmp/parsec/ci.sh on-disk-kim
132132
# When running the container built on the CI
133-
# run: docker run -v $(pwd):/tmp/parsec -w /tmp/parsec -t parsec-service-test-all /tmp/parsec/ci.sh sqlite-kim
133+
# run: docker run -v $(pwd):/tmp/parsec -w /tmp/parsec -t parsec-service-test-all /tmp/parsec/ci.sh on-disk-kim
134134

135135
cross-compilation:
136136
# Currently only the Mbed Crypto, PKCS 11, and TPM providers are tested as the other ones need to cross-compile other libraries.

ci.sh

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ where PROVIDER_NAME can be one of:
4242
- cryptoauthlib
4343
- all
4444
- coverage
45-
- sqlite-kim
45+
- on-disk-kim
4646
"
4747
}
4848

@@ -106,6 +106,25 @@ run_key_mappings_tests() {
106106
RUST_BACKTRACE=1 cargo test $TEST_FEATURES --manifest-path ./e2e_tests/Cargo.toml key_mappings
107107
}
108108

109+
setup_mappings() {
110+
# Add the Docker image's mappings in this Parsec service for the key mappings
111+
# test.
112+
# The key mappings test in e2e_tests/tests/per_provider/key_mappings.rs will try
113+
# to use the key generated via the generate-keys.sh script in the test image.
114+
cp -r /tmp/mappings/ .
115+
# Add the fake mappings for the key mappings test as well. The test will check that
116+
# those keys have successfully been deleted.
117+
# TODO: add fake mappings for the Trusted Service and CryptoAuthLib providers.
118+
cp -r $(pwd)/e2e_tests/fake_mappings/* mappings
119+
# As Mbed Crypto saves its keys on the current directory we need to move them
120+
# as well.
121+
if [ "$PROVIDER_NAME" = "mbed-crypto" ]; then
122+
cp /tmp/*.psa_its .
123+
fi
124+
125+
reload_service
126+
}
127+
109128
# Parse arguments
110129
NO_CARGO_CLEAN=
111130
NO_STRESS_TEST=
@@ -119,20 +138,21 @@ while [ "$#" -gt 0 ]; do
119138
--no-stress-test )
120139
NO_STRESS_TEST="True"
121140
;;
122-
mbed-crypto | pkcs11 | tpm | trusted-service | cryptoauthlib | all | cargo-check | sqlite-kim)
141+
mbed-crypto | pkcs11 | tpm | trusted-service | cryptoauthlib | all | cargo-check | on-disk-kim)
123142
if [ -n "$PROVIDER_NAME" ]; then
124143
error_msg "Only one provider name must be given"
125144
fi
126145
PROVIDER_NAME=$1
127146

128-
# Copy provider specific config, unless CI is running `cargo-check` or `sqlite-kim` CI
129-
if [ "$PROVIDER_NAME" != "cargo-check" ] && [ "$PROVIDER_NAME" != "sqlite-kim" ]; then
147+
# Copy provider specific config, unless CI is running `cargo-check` or `on-disk-kim` CI
148+
if [ "$PROVIDER_NAME" != "cargo-check" ] && [ "$PROVIDER_NAME" != "on-disk-kim" ]; then
130149
cp $(pwd)/e2e_tests/provider_cfg/$1/config.toml $CONFIG_PATH
131-
elif [ "$PROVIDER_NAME" = "sqlite-kim" ]; then
132-
cp $(pwd)/e2e_tests/provider_cfg/all/sqlite-kim-all-providers.toml $CONFIG_PATH
150+
elif [ "$PROVIDER_NAME" = "on-disk-kim" ]; then
151+
PROVIDER_NAME=all
152+
cp $(pwd)/e2e_tests/provider_cfg/all/on-disk-kim-all-providers.toml $CONFIG_PATH
133153
fi
134154

135-
if [ "$PROVIDER_NAME" = "all" ] || [ "$PROVIDER_NAME" = "cargo-check" ] || [ "$PROVIDER_NAME" = "sqlite-kim" ]; then
155+
if [ "$PROVIDER_NAME" = "all" ] || [ "$PROVIDER_NAME" = "cargo-check" ]; then
136156
FEATURES="--features=all-providers,all-authenticators"
137157
TEST_FEATURES="--features=all-providers"
138158
else
@@ -157,7 +177,7 @@ fi
157177

158178
trap cleanup EXIT
159179

160-
if [ "$PROVIDER_NAME" = "tpm" ] || [ "$PROVIDER_NAME" = "all" ] || [ "$PROVIDER_NAME" = "coverage" ] || [ "$PROVIDER_NAME" = "sqlite-kim" ]; then
180+
if [ "$PROVIDER_NAME" = "tpm" ] || [ "$PROVIDER_NAME" = "all" ] || [ "$PROVIDER_NAME" = "coverage" ]; then
161181
# Copy the NVChip for previously stored state. This is needed for the key mappings test.
162182
cp /tmp/NVChip .
163183
# Start and configure TPM server
@@ -179,7 +199,7 @@ if [ "$PROVIDER_NAME" = "tpm" ] || [ "$PROVIDER_NAME" = "all" ] || [ "$PROVIDER_
179199
popd
180200
fi
181201

182-
if [ "$PROVIDER_NAME" = "pkcs11" ] || [ "$PROVIDER_NAME" = "all" ] || [ "$PROVIDER_NAME" = "coverage" ] || [ "$PROVIDER_NAME" = "sqlite-kim" ]; then
202+
if [ "$PROVIDER_NAME" = "pkcs11" ] || [ "$PROVIDER_NAME" = "all" ] || [ "$PROVIDER_NAME" = "coverage" ]; then
183203
pushd e2e_tests
184204
# This command suppose that the slot created by the container will be the first one that appears
185205
# when printing all the available slots.
@@ -237,7 +257,7 @@ if [ "$PROVIDER_NAME" = "coverage" ]; then
237257
exit 0
238258
fi
239259

240-
if [ "$PROVIDER_NAME" = "all" ] || [ "$PROVIDER_NAME" = "sqlite-kim" ]; then
260+
if [ "$PROVIDER_NAME" = "all" ]; then
241261
# Start SPIRE server and agent
242262
pushd /tmp/spire-0.11.1
243263
./bin/spire-server run -config conf/server/server.conf &
@@ -255,22 +275,6 @@ if [ "$PROVIDER_NAME" = "all" ] || [ "$PROVIDER_NAME" = "sqlite-kim" ]; then
255275
popd
256276
fi
257277

258-
# Test the SQLite KIM
259-
if [ "$PROVIDER_NAME" = "sqlite-kim" ]; then
260-
echo "Start Parsec for end-to-end tests with sqlite-kim"
261-
RUST_LOG=info RUST_BACKTRACE=1 cargo run --release $FEATURES -- --config $CONFIG_PATH &
262-
# Sleep time needed to make sure Parsec is ready before launching the tests.
263-
wait_for_service
264-
265-
echo "Execute all-providers sqlite-kim normal tests"
266-
RUST_BACKTRACE=1 cargo test $TEST_FEATURES --manifest-path ./e2e_tests/Cargo.toml all_providers::normal
267-
268-
echo "Shutdown Parsec"
269-
stop_service
270-
271-
exit 0
272-
fi
273-
274278
echo "Build test"
275279

276280
if [ "$PROVIDER_NAME" = "cargo-check" ]; then
@@ -329,21 +333,6 @@ RUST_BACKTRACE=1 cargo test $FEATURES
329333
# Removing any mappings left over from integration tests
330334
rm -rf mappings/
331335

332-
# Add the Docker image's mappings in this Parsec service for the key mappings
333-
# test.
334-
# The key mappings test in e2e_tests/tests/per_provider/key_mappings.rs will try
335-
# to use the key generated via the generate-keys.sh script in the test image.
336-
cp -r /tmp/mappings/ .
337-
# Add the fake mappings for the key mappings test as well. The test will check that
338-
# those keys have successfully been deleted.
339-
# TODO: add fake mappings for the Trusted Service and CryptoAuthLib providers.
340-
cp -r $(pwd)/e2e_tests/fake_mappings/* mappings
341-
# As Mbed Crypto saves its keys on the current directory we need to move them
342-
# as well.
343-
if [ "$PROVIDER_NAME" = "mbed-crypto" ]; then
344-
cp /tmp/*.psa_its .
345-
fi
346-
347336
echo "Start Parsec for end-to-end tests"
348337
RUST_LOG=info RUST_BACKTRACE=1 cargo run --release $FEATURES -- --config $CONFIG_PATH &
349338
# Sleep time needed to make sure Parsec is ready before launching the tests.
@@ -353,6 +342,9 @@ if [ "$PROVIDER_NAME" = "all" ]; then
353342
echo "Execute all-providers normal tests"
354343
RUST_BACKTRACE=1 cargo test $TEST_FEATURES --manifest-path ./e2e_tests/Cargo.toml all_providers::normal
355344

345+
echo "Execute all-providers cross tests"
346+
RUST_BACKTRACE=1 cargo test $TEST_FEATURES --manifest-path ./e2e_tests/Cargo.toml all_providers::cross
347+
356348
echo "Execute all-providers multi-tenancy tests"
357349
# Needed because parsec-client-1 and 2 write to those locations owned by root
358350
chmod 777 /tmp/parsec/e2e_tests
@@ -363,6 +355,7 @@ if [ "$PROVIDER_NAME" = "all" ]; then
363355
su -c "PATH=\"/home/parsec-client-1/.cargo/bin:${PATH}\";RUST_BACKTRACE=1 cargo test $TEST_FEATURES --manifest-path ./e2e_tests/Cargo.toml --target-dir /home/parsec-client-1 all_providers::multitenancy::client1_before" parsec-client-1
364356
su -c "PATH=\"/home/parsec-client-2/.cargo/bin:${PATH}\";RUST_BACKTRACE=1 cargo test $TEST_FEATURES --manifest-path ./e2e_tests/Cargo.toml --target-dir /home/parsec-client-2 all_providers::multitenancy::client2" parsec-client-2
365357
su -c "PATH=\"/home/parsec-client-1/.cargo/bin:${PATH}\";RUST_BACKTRACE=1 cargo test $TEST_FEATURES --manifest-path ./e2e_tests/Cargo.toml --target-dir /home/parsec-client-1 all_providers::multitenancy::client1_after" parsec-client-1
358+
366359
# Change the authentication method
367360
sed -i 's/^\(auth_type\s*=\s*\).*$/\1\"UnixPeerCredentials\"/' $CONFIG_PATH
368361
reload_service
@@ -383,6 +376,8 @@ if [ "$PROVIDER_NAME" = "all" ]; then
383376
echo "Execute all-providers config tests"
384377
RUST_BACKTRACE=1 cargo test $TEST_FEATURES --manifest-path ./e2e_tests/Cargo.toml all_providers::config -- --test-threads=1
385378
else
379+
setup_mappings
380+
386381
# Per provider tests
387382
run_normal_tests
388383
run_old_e2e_tests

config.toml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,24 @@ auth_type = "UnixPeerCredentials"
8484
# Defined as an array of tables: https://github.com/toml-lang/toml#user-content-array-of-tables
8585
[[key_manager]]
8686
# (Required) Name of the key info manager. Used to tie providers to the manager supporting them.
87-
name = "on-disk-manager"
87+
name = "sqlite-manager"
8888

8989
# (Required) Type of key info manager to be used.
90-
manager_type = "OnDisk"
90+
# Possible values: "SQLite", "OnDisk"
91+
# NOTE: The SQLite KIM is now the recommended type, with the OnDisk KIM to be deprecated at some
92+
# point in the future.
93+
manager_type = "SQLite"
9194

92-
# Path to the location where the mapping will be persisted (in this case, the filesystem path)
95+
# Path to the location where the database will be persisted
96+
#store_path = "/var/lib/parsec/kim-mappings/sqlite/sqlite-key-info-manager.sqlite3"
97+
98+
# Example of OnDisk Key Info Manager configuration
99+
#[[key_manager]]
100+
# (Required) Name of the key info manager.
101+
#name = "on-disk-manager"
102+
# (Required) Type of key info manager to be used.
103+
#manager_type = "OnDisk"
104+
# Path to the location where the mappings will be persisted (in this case, the filesystem path)
93105
#store_path = "/var/lib/parsec/mappings"
94106

95107
# (Required) Provider configurations.
@@ -120,7 +132,7 @@ provider_type = "MbedCrypto"
120132
# Crypto library by default within the working directory of the service, NOT in the same location
121133
# as the mappings mentioned previously. If you want the keys to be persisted across reboots, ensure
122134
# that the working directory is not temporary.
123-
key_info_manager = "on-disk-manager"
135+
key_info_manager = "sqlite-manager"
124136

125137
# Example of a PKCS 11 provider configuration
126138
#[[provider]]
@@ -132,9 +144,9 @@ key_info_manager = "on-disk-manager"
132144
# ⚠ WARNING: Changing provider name after use will lead to loss of existing keys.
133145
#
134146
# (Optional) The name of the provider
135-
# name = "pkcs11-provider"
147+
#name = "pkcs11-provider"
136148
#provider_type = "Pkcs11"
137-
#key_info_manager = "on-disk-manager"
149+
#key_info_manager = "sqlite-manager"
138150
# (Required for this provider) Path to the location of the dynamic library loaded by this provider.
139151
# For the PKCS 11 provider, this library implements the PKCS 11 API on the target platform.
140152
#library_path = "/usr/local/lib/softhsm/libsofthsm2.so"
@@ -162,9 +174,9 @@ key_info_manager = "on-disk-manager"
162174
# ⚠ WARNING: Changing provider name after use will lead to loss of existing keys.
163175
#
164176
# (Optional) The name of the provider
165-
# name = "tpm-provider"
177+
#name = "tpm-provider"
166178
#provider_type = "Tpm"
167-
#key_info_manager = "on-disk-manager"
179+
#key_info_manager = "sqlite-manager"
168180
# (Required) TPM TCTI device to use with this provider. The string can include configuration values - if no
169181
# configuration value is given, the defaults are used. Options are:
170182
# - "device": uses a TPM device available as a file node; path can be given as a configuration string,
@@ -205,9 +217,9 @@ key_info_manager = "on-disk-manager"
205217
# ⚠ WARNING: Changing provider name after use will lead to loss of existing keys.
206218
#
207219
# (Optional) The name of the provider
208-
# name = "cryptoauthlib-provider"
220+
#name = "cryptoauthlib-provider"
209221
#provider_type = "CryptoAuthLib"
210-
#key_info_manager = "on-disk-manager"
222+
#key_info_manager = "sqlite-manager"
211223
##########
212224
# (Required) Interface for ATCA device
213225
# Supported values: "i2c", "test-interface"
@@ -266,9 +278,9 @@ key_info_manager = "on-disk-manager"
266278
# ⚠ WARNING: Changing provider name after use will lead to loss of existing keys.
267279
#
268280
# (Optional) The name of the provider
269-
# name = "trusted-service-provider"
281+
#name = "trusted-service-provider"
270282
# (Required) Type of provider.
271283
#provider_type = "TrustedService"
272284

273285
# (Required) Name of key info manager that will support this provider.
274-
#key_info_manager = "on-disk-manager"
286+
#key_info_manager = "sqlite-manager"

e2e_tests/provider_cfg/all/config.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ admins = [ { name = "list_clients test" }, { name = "1000" }, { name = "client1"
1818
#workload_endpoint="unix:///tmp/agent.sock"
1919

2020
[[key_manager]]
21-
name = "on-disk-manager"
22-
manager_type = "OnDisk"
23-
store_path = "./mappings"
21+
name = "sqlite-manager"
22+
manager_type = "SQLite"
23+
database_path = "./kim-mappings/sqlite/sqlite-key-info-manager.sqlite3"
2424

2525
[[provider]]
2626
provider_type = "MbedCrypto"
27-
key_info_manager = "on-disk-manager"
27+
key_info_manager = "sqlite-manager"
2828

2929
[[provider]]
3030
provider_type = "Tpm"
31-
key_info_manager = "on-disk-manager"
31+
key_info_manager = "sqlite-manager"
3232
tcti = "mssim"
3333
owner_hierarchy_auth = "tpm_pass"
3434

3535
[[provider]]
3636
provider_type = "Pkcs11"
37-
key_info_manager = "on-disk-manager"
37+
key_info_manager = "sqlite-manager"
3838
library_path = "/usr/local/lib/softhsm/libsofthsm2.so"
3939
user_pin = "123456"
4040
# The slot_number mandatory field is going to replace the following line with a valid number
4141
# slot_number
4242

4343
[[provider]]
4444
provider_type = "CryptoAuthLib"
45-
key_info_manager = "on-disk-manager"
45+
key_info_manager = "sqlite-manager"
4646
device_type = "always-success"
4747
iface_type = "test-interface"
4848
# wake_delay = 1500

e2e_tests/provider_cfg/all/sqlite-kim-all-providers.toml renamed to e2e_tests/provider_cfg/all/on-disk-kim-all-providers.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ admins = [ { name = "list_clients test" }, { name = "1000" }, { name = "client1"
1818
#workload_endpoint="unix:///tmp/agent.sock"
1919

2020
[[key_manager]]
21-
name = "sqlite-manager"
22-
manager_type = "SQLite"
23-
database_path = "./kim-mappings/sqlite/sqlite-key-info-manager.sqlite3"
21+
name = "on-disk-manager"
22+
manager_type = "OnDisk"
23+
store_path = "./mappings"
2424

2525
[[provider]]
2626
provider_type = "MbedCrypto"
27-
key_info_manager = "sqlite-manager"
27+
key_info_manager = "on-disk-manager"
2828

2929
[[provider]]
3030
provider_type = "Tpm"
31-
key_info_manager = "sqlite-manager"
31+
key_info_manager = "on-disk-manager"
3232
tcti = "mssim"
3333
owner_hierarchy_auth = "tpm_pass"
3434

3535
[[provider]]
3636
provider_type = "Pkcs11"
37-
key_info_manager = "sqlite-manager"
37+
key_info_manager = "on-disk-manager"
3838
library_path = "/usr/local/lib/softhsm/libsofthsm2.so"
3939
user_pin = "123456"
4040
# The slot_number mandatory field is going to replace the following line with a valid number
4141
# slot_number
4242

4343
[[provider]]
4444
provider_type = "CryptoAuthLib"
45-
key_info_manager = "sqlite-manager"
45+
key_info_manager = "on-disk-manager"
4646
device_type = "always-success"
4747
iface_type = "test-interface"
4848
# wake_delay = 1500

e2e_tests/tests/all_providers/config/tomls/allow_export.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ socket_path = "/tmp/parsec.sock"
1212
auth_type = "Direct"
1313

1414
[[key_manager]]
15-
name = "on-disk-manager"
16-
manager_type = "OnDisk"
17-
store_path = "./mappings"
15+
name = "sqlite-manager"
16+
manager_type = "SQLite"
17+
database_path = "./kim-mappings/sqlite/sqlite-key-info-manager.sqlite3"
1818

1919
[[provider]]
2020
provider_type = "Pkcs11"
21-
key_info_manager = "on-disk-manager"
21+
key_info_manager = "sqlite-manager"
2222
library_path = "/usr/local/lib/softhsm/libsofthsm2.so"
2323
user_pin = "123456"
2424
# The slot_number mandatory field is going to replace the following line with a valid number

0 commit comments

Comments
 (0)