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

Enforce security.shifted and security.unmapped to be mutually exclusive. #12316

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
5 changes: 0 additions & 5 deletions lxd/storage/backend_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5119,11 +5119,6 @@ func (b *lxdBackend) UpdateCustomVolume(projectName string, volName string, newD
return fmt.Errorf("Custom volume 'block.filesystem' property cannot be changed")
}

// Check that security.unmapped and security.shifted aren't set together.
if shared.IsTrue(newConfig["security.unmapped"]) && shared.IsTrue(newConfig["security.shifted"]) {
return fmt.Errorf("security.unmapped and security.shifted are mutually exclusive")
}

// Check for config changing that is not allowed when running instances are using it.
if changedConfig["security.shifted"] != "" {
err = VolumeUsedByInstanceDevices(b.state, b.name, projectName, &curVol.StorageVolume, true, func(dbInst db.InstanceArgs, project api.Project, usedByDevices []string) error {
Expand Down
5 changes: 5 additions & 0 deletions lxd/storage/drivers/driver_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ func (d *common) validateVolume(vol Volume, driverRules map[string]func(value st
return fmt.Errorf("Volume %q property is not valid for volume type", "size")
}

// Check that security.unmapped and security.shifted are not set together.
if shared.IsTrue(vol.config["security.unmapped"]) && shared.IsTrue(vol.config["security.shifted"]) {
return fmt.Errorf("security.unmapped and security.shifted are mutually exclusive")
}

return nil
}

Expand Down
7 changes: 7 additions & 0 deletions test/suites/container_devices_disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ test_container_devices_disk_shift() {

# Test shifted custom volumes
POOL=$(lxc profile device get default root pool)

# Cannot set both security.shifted and security.unmapped.
! lxc storage volume create "${POOL}" foo-shift security.shifted=true security.unmapped=true || false

lxc storage volume create "${POOL}" foo-shift security.shifted=true

# Cannot set both security.shifted and security.unmapped.
! lxc storage volume set "${POOL}" foo-shift security.unmapped=true || false

lxc start foo
lxc launch testimage foo-priv -c security.privileged=true
lxc launch testimage foo-isol1 -c security.idmap.isolated=true
Expand Down
Loading