From c49ef5f1c599c9c6883b20527387a7e8057b8155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Peliz=C3=A4us?= Date: Thu, 22 Aug 2024 16:05:40 +0200 Subject: [PATCH] tests: Extend cluster member join tests if 'none' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julian Pelizäus --- test/suites/clustering.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/suites/clustering.sh b/test/suites/clustering.sh index aea40c3d5c21..414e6c15401b 100644 --- a/test/suites/clustering.sh +++ b/test/suites/clustering.sh @@ -1704,6 +1704,20 @@ test_clustering_join_api() { ns2="${prefix}2" LXD_NETNS="${ns2}" spawn_lxd "${LXD_TWO_DIR}" false + # Check a join token cannot be created for the reserved name 'none' + ! lxc cluster add none --quiet || false + + # Check a server with the name 'valid' cannot be joined when modifying the token. + # Therefore replace the valid name in the token with 'none'. + malicious_token="$(lxc cluster add valid --quiet | base64 -d | jq '.server_name |= "none"' | base64 --wrap=0)" + op=$(curl --unix-socket "${LXD_TWO_DIR}/unix.socket" -X PUT "lxd/1.0/cluster" -d "{\"server_name\":\"valid\",\"enabled\":true,\"member_config\":[{\"entity\": \"storage-pool\",\"name\":\"data\",\"key\":\"source\",\"value\":\"\"}],\"server_address\":\"10.1.1.102:8443\",\"cluster_address\":\"10.1.1.101:8443\",\"cluster_certificate\":\"${cert}\",\"cluster_token\":\"${malicious_token}\"}" | jq -r .operation) + [ "$(curl --unix-socket "${LXD_TWO_DIR}/unix.socket" "lxd${op}/wait" | jq '.error_code')" = "403" ] + + # Check that the server cannot be joined using a valid token by changing it's name to 'none'. + token="$(lxc cluster add valid2 --quiet)" + [ "$(curl --unix-socket "${LXD_TWO_DIR}/unix.socket" -X PUT "lxd/1.0/cluster" -d "{\"server_name\":\"none\",\"enabled\":true,\"member_config\":[{\"entity\": \"storage-pool\",\"name\":\"data\",\"key\":\"source\",\"value\":\"\"}],\"server_address\":\"10.1.1.102:8443\",\"cluster_address\":\"10.1.1.101:8443\",\"cluster_certificate\":\"${cert}\",\"cluster_token\":\"${token}\"}" | jq -r '.error_code')" = "400" ] + + # Check the server can be joined. token="$(lxc cluster add node2 --quiet)" op=$(curl --unix-socket "${LXD_TWO_DIR}/unix.socket" -X PUT "lxd/1.0/cluster" -d "{\"server_name\":\"node2\",\"enabled\":true,\"member_config\":[{\"entity\": \"storage-pool\",\"name\":\"data\",\"key\":\"source\",\"value\":\"\"}],\"server_address\":\"10.1.1.102:8443\",\"cluster_address\":\"10.1.1.101:8443\",\"cluster_certificate\":\"${cert}\",\"cluster_token\":\"${token}\"}" | jq -r .operation) curl --unix-socket "${LXD_TWO_DIR}/unix.socket" "lxd${op}/wait"