From 93c6a60e84f2a0b3d72162419ee573e34e091822 Mon Sep 17 00:00:00 2001 From: Mark Laing Date: Thu, 8 Aug 2024 16:29:19 +0100 Subject: [PATCH] test/suites: Test project feature interaction with fine-grained auth. This commit copies the majority of the updated `tls_restrictions` test and asserts the behaviour of the fine-grained authorization driver. Signed-off-by: Mark Laing --- test/suites/auth.sh | 367 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 366 insertions(+), 1 deletion(-) diff --git a/test/suites/auth.sh b/test/suites/auth.sh index f058e9a04c8d..0153bc730f36 100644 --- a/test/suites/auth.sh +++ b/test/suites/auth.sh @@ -133,6 +133,9 @@ EOF # Perform access checks fine_grained_authorization + # Perform access check compatibility with project feature flags + auth_project_features + # Cleanup lxc auth group delete test-group lxc auth identity-provider-group delete test-idp-group @@ -191,7 +194,7 @@ fine_grained_authorization() { # Change permission to "user" for instance "user-foo" lxc auth group permission add test-group instance user-foo user project=default - # To exec into an instance, the test-group will also need `can_view_events` for the project. + # To exec into an instance, Members of test-group will also need `can_view_events` for the project. # This is because the client uses the events API to figure out when the operation is finished. # Ideally we would use operations for this instead or allow more fine-grained filtering on events. lxc auth group permission add test-group project default can_view_events @@ -444,3 +447,365 @@ user_is_instance_user() { # We can't edit the instance though ! lxc_remote config set "oidc:${instance_name}" user.fizz=buzz || false } + +auth_project_features() { + # test-group must have no permissions to start the test. + [ "$(lxc query /1.0/auth/groups/test-group | jq '.permissions | length')" -eq 0 ] + + # Create project blah + lxc project create blah + + # Validate view with no permissions + [ "$(lxc_remote project list oidc: --format csv | wc -l)" -eq 0 ] + + # Allow operator permissions on project blah + lxc auth group permission add test-group project blah operator + + # Confirm we can still view storage pools + [ "$(lxc_remote storage list oidc: --format csv | wc -l)" = 1 ] + + # Confirm we cannot view storage pool configuration + pool_name="$(lxc_remote storage list oidc: --format csv | cut -d, -f1)" + ! lxc_remote storage show "oidc:${pool_name}" | grep -F 'source:' || false + + # Validate restricted view + ! lxc_remote project list oidc: | grep -q default || false + lxc_remote project list oidc: | grep -q blah + + # Validate that the restricted caller cannot edit or delete the project. + ! lxc_remote project set oidc:blah user.foo=bar || false + ! lxc_remote project delete oidc:blah || false + + # Validate restricted caller cannot create projects. + ! lxc_remote project create oidc:blah1 || false + + # Validate restricted caller cannot see resources in projects they do not have access to (the call will not fail, but + # the lists should be empty + [ "$(lxc_remote list oidc: --project default --format csv)" = "" ] + [ "$(lxc_remote profile list oidc: --project default --format csv)" = "" ] + [ "$(lxc_remote network list oidc: --project default --format csv)" = "" ] + [ "$(lxc_remote operation list oidc: --project default --format csv)" = "" ] + [ "$(lxc_remote network zone list oidc: --project default --format csv)" = "" ] + [ "$(lxc_remote storage volume list "oidc:${pool_name}" --project default --format csv)" = "" ] + [ "$(lxc_remote storage bucket list "oidc:${pool_name}" --project default --format csv)" = "" ] + + ### Validate images. + test_image_fingerprint="$(lxc image info testimage --project default | awk '/^Fingerprint/ {print $2}')" + + # We can always list images, but there are no public images in the default project now, so the list should be empty. + [ "$(lxc_remote image list oidc: --project default --format csv)" = "" ] + ! lxc_remote image show oidc:testimage --project default || false + + # Set the image to public and ensure we can view it. + lxc image show testimage --project default | sed -e "s/public: false/public: true/" | lxc image edit testimage --project default + [ "$(lxc_remote image list oidc: --project default --format csv | wc -l)" = 1 ] + lxc_remote image show oidc:testimage --project default + + # Check we can export the public image: + lxc image export oidc:testimage "${TEST_DIR}/" --project default + [ "${test_image_fingerprint}" = "$(sha256sum "${TEST_DIR}/${test_image_fingerprint}.tar.xz" | cut -d' ' -f1)" ] + + # While the image is public, copy it to the blah project and create an alias for it. + lxc_remote image copy oidc:testimage oidc: --project default --target-project blah + lxc_remote image alias create oidc:testimage "${test_image_fingerprint}" --project blah + + # Restore privacy on the test image in the default project. + lxc image show testimage --project default | sed -e "s/public: true/public: false/" | lxc image edit testimage --project default + + # Set up a profile in the blah project. Additionally ensures project operator can edit profiles. + lxc profile show default | lxc_remote profile edit oidc:default --project blah + + # Create an instance (using the test image copied from the default project while it was public). + lxc_remote init testimage oidc:blah-instance --project blah + + # Create a custom volume. + lxc_remote storage volume create "oidc:${pool_name}" blah-volume --project blah + + # There should now be two volume URLs, one instance, one image, and one profile URL in the used-by list. + [ "$(lxc_remote project list oidc: --format csv | cut -d, -f9)" = "5" ] + + # Delete resources in project blah so that we can modify project features. + lxc_remote delete oidc:blah-instance --project blah + lxc_remote storage volume delete "oidc:${pool_name}" blah-volume --project blah + lxc_remote image delete "oidc:${test_image_fingerprint}" --project blah + + # Ensure we can create and view resources that are not enabled for the project (e.g. their effective project is + # the default project). + + ### IMAGES (initial value is true for new projects) + + # Unset the images feature (the default is false). + lxc project unset blah features.images + + # The test image in the default project *not* should be visible by default via project blah. + ! lxc_remote image info "oidc:${test_image_fingerprint}" --project blah || false + ! lxc_remote image show "oidc:${test_image_fingerprint}" --project blah || false + test_image_fingerprint_short="$(echo "${test_image_fingerprint}" | cut -c1-12)" + ! lxc_remote image list oidc: --project blah | grep -F "${test_image_fingerprint_short}" || false + + # Make the images in the default project viewable to members of test-group + lxc auth group permission add test-group project default can_view_images + + # The test image in the default project should now be visible via project blah. + lxc_remote image info "oidc:${test_image_fingerprint}" --project blah + lxc_remote image show "oidc:${test_image_fingerprint}" --project blah + lxc_remote image list oidc: --project blah | grep -F "${test_image_fingerprint_short}" + + # Members of test-group can view it via project default. (This is true even though they do not have can_view on project default). + lxc_remote image info "oidc:${test_image_fingerprint}" --project default + lxc_remote image show "oidc:${test_image_fingerprint}" --project default + lxc_remote image list oidc: --project default | grep -F "${test_image_fingerprint_short}" + + # Members of test-group cannot edit the image. + ! lxc_remote image set-property "oidc:${test_image_fingerprint}" requirements.secureboot true --project blah || false + ! lxc_remote image unset-property "oidc:${test_image_fingerprint}" requirements.secureboot --project blah || false + + # Members of test-group cannot delete the image. + ! lxc_remote image delete "oidc:${test_image_fingerprint}" --project blah || false + + # Delete it anyway to test that we can import a new one. + lxc image delete "${test_image_fingerprint}" --project default + + # Members of test-group can create images. + lxc_remote image import "${TEST_DIR}/${test_image_fingerprint}.tar.xz" oidc: --project blah + lxc_remote image alias create oidc:testimage "${test_image_fingerprint}" --project blah + + # We can view the image we've created via project blah (whose effective project is default) because we've granted the + # group permission to view all images in the default project. + lxc_remote image show "oidc:${test_image_fingerprint}" --project blah + lxc_remote image show "oidc:${test_image_fingerprint}" --project default + + # Image clean up + lxc image delete "${test_image_fingerprint}" --project default + lxc auth group permission remove test-group project default can_view_images + rm "${TEST_DIR}/${test_image_fingerprint}.tar.xz" + + ### NETWORKS (initial value is false in new projects). + + # Create a network in the default project. + networkName="net$(tr -dc A-Za-z0-9