diff --git a/lxd/project/permissions.go b/lxd/project/permissions.go index 1859b3c9a164..323788063d7a 100644 --- a/lxd/project/permissions.go +++ b/lxd/project/permissions.go @@ -642,10 +642,11 @@ func checkRestrictions(project api.Project, instances []api.Instance, profiles [ } case "allow": - var allowed bool - allowed, _ = CheckRestrictedDevicesDiskPaths(project.Config, device["source"]) - if !allowed { - return fmt.Errorf("Disk source path %q not allowed", device["source"]) + if device["pool"] == "" { + allowed, _ := CheckRestrictedDevicesDiskPaths(project.Config, device["source"]) + if !allowed { + return fmt.Errorf("Disk source path %q not allowed", device["source"]) + } } } diff --git a/test/suites/projects.sh b/test/suites/projects.sh index b34fad3a4d1d..738cbe275f3d 100644 --- a/test/suites/projects.sh +++ b/test/suites/projects.sh @@ -972,6 +972,28 @@ test_projects_restrictions() { lxc project set p1 restricted.devices.disk=block ! lxc profile device add default data disk pool="${pool}" path=/mnt source="v-proj$$" || false + restrictedDir="/opt/projects_restricted" + mkdir "${restrictedDir}" + tmpDir=$(mktemp -d) + optDir=$(mktemp -d --tmpdir="${restrictedDir}") + + # Block unmanaged disk devices + lxc project set p1 restricted.devices.disk=managed + ! lxc profile device add default data disk path=/mnt source="${tmpDir}" || false + + # Allow unmanaged disk devices + lxc project set p1 restricted.devices.disk=allow + lxc profile device add default data disk path=/mnt source="${tmpDir}" + lxc profile device remove default data + + # Path restrictions + lxc project set p1 restricted.devices.disk.paths="${restrictedDir}" + ! lxc profile device add default data disk path=/mnt source="${tmpDir}" || false + lxc profile device add default data disk path=/mnt source="${optDir}" + lxc profile device remove default data + + rm -r "${tmpDir}" "${optDir}" "${restrictedDir}" + # Setting restricted.containers.nesting to 'allow' makes it possible to create # nested containers. lxc project set p1 restricted.containers.nesting=allow