-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nvme: testcases for TLS support #158
base: master
Are you sure you want to change the base?
Changes from all commits
e8e6097
87be415
0ae6f3e
255fc97
76dcea6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: GPL-3.0+ | ||
# Copyright (C) 2024 Hannes Reinecke, SUSE Labs | ||
# | ||
# Create TLS-encrypted connections | ||
|
||
. tests/nvme/rc | ||
|
||
DESCRIPTION="Create TLS-encrypted connections" | ||
QUICK=1 | ||
|
||
requires() { | ||
_nvme_requires | ||
_have_loop | ||
_have_kernel_option NVME_TCP_TLS | ||
_have_kernel_option NVME_TARGET_TCP_TLS | ||
_require_kernel_nvme_fabrics_feature tls | ||
_require_nvme_trtype tcp | ||
_require_nvme_cli_tls | ||
} | ||
|
||
set_conditions() { | ||
_set_nvme_trtype "$@" | ||
} | ||
|
||
test() { | ||
echo "Running ${TEST_NAME}" | ||
|
||
_setup_nvmet | ||
|
||
local hostkey | ||
local ctrl | ||
|
||
hostkey=$(nvme gen-tls-key -n "${def_hostnqn}" -c "${def_subsysnqn}" -m 1 -I 1 -i 2> /dev/null) | ||
if [ -z "$hostkey" ] ; then | ||
echo "nvme gen-tls-key failed" | ||
return 1 | ||
fi | ||
|
||
systemctl start tlshd | ||
|
||
_nvmet_target_setup --blkdev file --tls | ||
|
||
# Test unencrypted connection | ||
echo "Test unencrypted connection w/ tls not required" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. umm, looks pretty useless... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think so. This is testing the 'not required' setting in nvmet, which should accept both TLS and non-TLS connections even if TLS is enabled on the target. |
||
_nvme_connect_subsys | ||
|
||
ctrl=$(_find_nvme_dev "${def_subsysnqn}") | ||
if _nvme_ctrl_tls_key "$ctrl" > /dev/null; then | ||
echo "WARNING: connection is encrypted" | ||
fi | ||
|
||
_nvme_disconnect_subsys | ||
|
||
# Test encrypted connection | ||
echo "Test encrypted connection w/ tls not required" | ||
_nvme_connect_subsys --tls | ||
|
||
ctrl=$(_find_nvme_dev "${def_subsysnqn}") | ||
if ! _nvme_ctrl_tls_key "$ctrl" > /dev/null ; then | ||
echo "WARNING: connection is not encrypted" | ||
fi | ||
|
||
_nvme_disconnect_subsys | ||
|
||
# Reset target configuration | ||
_nvmet_target_cleanup | ||
|
||
_nvmet_target_setup --blkdev file --force-tls | ||
|
||
# Test unencrypted connection | ||
echo "Test unencrypted connection w/ tls required (should fail)" | ||
_nvme_connect_subsys | ||
|
||
_nvme_disconnect_subsys | ||
|
||
# Test encrypted connection | ||
echo "Test encrypted connection w/ tls required" | ||
_nvme_connect_subsys --tls | ||
|
||
ctrl=$(_find_nvme_dev "${def_subsysnqn}") | ||
if ! _nvme_ctrl_tls_key "$ctrl" > /dev/null; then | ||
echo "WARNING: connection is not encrypted" | ||
fi | ||
|
||
_nvme_disconnect_subsys | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any room to test passing explicit keys and private keyrings to this test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather not do that here. This is for testing the 'default' case, where PSKs are pre-populated in the keyring and the connection picks up the keys automatically. Explicit keys and keyrings are really just for testing. |
||
|
||
systemctl stop tlshd | ||
|
||
_nvmet_target_cleanup | ||
|
||
echo "Test complete" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Running nvme/059 | ||
Test unencrypted connection w/ tls not required | ||
disconnected 1 controller(s) | ||
Test encrypted connection w/ tls not required | ||
disconnected 1 controller(s) | ||
Test unencrypted connection w/ tls required (should fail) | ||
disconnected 0 controller(s) | ||
Test encrypted connection w/ tls required | ||
disconnected 1 controller(s) | ||
Test complete |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: GPL-3.0+ | ||
# Copyright (C) 2022 Hannes Reinecke, SUSE Labs | ||
# | ||
# Create secure concatenation for TCP connections | ||
|
||
. tests/nvme/rc | ||
|
||
DESCRIPTION="Create authenticated TCP connections with secure concatenation" | ||
QUICK=1 | ||
|
||
requires() { | ||
_nvme_requires | ||
_have_loop | ||
_have_kernel_option NVME_AUTH | ||
_have_kernel_option NVME_TCP_TLS | ||
_have_kernel_option NVME_TARGET_AUTH | ||
_have_kernel_option NVME_TARGET_TCP_TLS | ||
_require_kernel_nvme_fabrics_feature dhchap_ctrl_secret | ||
_require_kernel_nvme_fabrics_feature concat | ||
_require_nvme_trtype_is_tcp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should be "_require_nvme_trtype tcp". |
||
_require_nvme_cli_auth | ||
} | ||
|
||
set_conditions() { | ||
_set_nvme_trtype "$@" | ||
} | ||
|
||
test() { | ||
echo "Running ${TEST_NAME}" | ||
|
||
_setup_nvmet | ||
|
||
local hostkey | ||
|
||
systemctl restart tlshd | ||
|
||
hostkey="$(nvme gen-dhchap-key -m 1 -n ${def_hostnqn} 2> /dev/null)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ${def_hostnqn} should be surrounded with double quotations to avoid a shellcheck warning. |
||
if [ -z "$hostkey" ] ; then | ||
echo "nvme gen-dhchap-key failed" | ||
return 1 | ||
fi | ||
|
||
_nvmet_target_setup --blkdev file --hostkey "${hostkey}" --concat | ||
_set_nvmet_hash "${def_hostnqn}" "hmac(sha256)" | ||
_set_nvmet_dhgroup "${def_hostnqn}" "ffdhe2048" | ||
|
||
echo "Test secure concatenation with SHA256" | ||
_nvme_connect_subsys --dhchap-secret "${hostkey}" --concat | ||
|
||
ctrl=$(_find_nvme_dev) | ||
if [[ -z "$ctrl" ]]; then | ||
echo "WARNING: connection failed" | ||
exit 1 | ||
fi | ||
tlskey=$(_nvme_ctrl_tls_key "$ctrl" || true) | ||
if [[ -z "$tlskey" ]]; then | ||
echo "WARNING: connection is not encrypted" | ||
exit 1 | ||
fi | ||
|
||
# Reset controller to force re-negotiation | ||
echo "Reset controller" | ||
if ! nvme reset "/dev/${ctrl}" ; then | ||
echo "WARNING: failed to reset controller" | ||
fi | ||
|
||
new_tlskey=$(_nvme_ctrl_tls_key "$ctrl" || true) | ||
if [[ -z "$new_tlskey" ]]; then | ||
echo "WARNING: connection is not encrypted" | ||
elif [[ "$new_tlskey" = "$tlskey" ]]; then | ||
echo "WARNING: TLS key has not been renegotiated" | ||
fi | ||
|
||
_nvme_disconnect_subsys | ||
|
||
hostkey="$(nvme gen-dhchap-key -m 2 -n ${def_hostnqn} 2> /dev/null)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, ${def_hostnqn} should be surrounded with double quotations to avoid a shellcheck warning. |
||
if [ -z "$hostkey" ] ; then | ||
echo "nvme gen-dhchap-key failed" | ||
return 1 | ||
fi | ||
|
||
_set_nvmet_hostkey "{def_hostnqn}" "${hostkey}" | ||
_set_nvmet_hash "${def_hostnqn}" "hmac(sha384)" | ||
_set_nvmet_dhgroup "${def_hostnqn}" "ffdhe3072" | ||
|
||
echo "Test secure concatenation with SHA384" | ||
_nvme_connect_subsys --dhchap-secret "${hostkey}" --concat | ||
|
||
ctrl=$(_find_nvme_dev) | ||
if [[ -z "$ctrl" ]]; then | ||
echo "WARNING: connection failed" | ||
exit 1 | ||
fi | ||
tlskey=$(_nvme_ctrl_tls_key "$ctrl" || true) | ||
if [[ -z "$tlskey" ]]; then | ||
echo "WARNING: connection is not encrypted" | ||
exit 1 | ||
fi | ||
|
||
_nvme_disconnect_subsys | ||
|
||
_nvmet_target_cleanup | ||
|
||
echo "Test complete" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to check that it exists as a dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also check the version of ktls-utils?
Or just explain in a comment if you have any expectations from it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good point. Will check what we can do here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to "man systemctl" "EXIT STATUS" section, systemctl command returns exit status "4" for "no such unit". So it would work to check if "systemctl status tlshd" command's exist status is 4 or not.
I use Fedora, and needed to install "ktls-utils" package to run the test case. It would be the better to mention the word "ktls-utils" in the SKIP_REASONS message to help users to understand what is missing.