Skip to content
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

lxd/project: Allow managed volumes under "allow" (from Incus) #14022

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lxd/project/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions test/suites/projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading