disk: move mount point checking to central location

Instead of all distribution implementing their own mount point
checking code, we de-duplicate it and move it to `disk`.
This commit is contained in:
Christian Kellner 2022-08-06 21:22:52 +02:00
parent 13e287733a
commit 2b03a839f0
6 changed files with 50 additions and 57 deletions

View file

@ -3,8 +3,6 @@ package distro
import (
"encoding/json"
"fmt"
"path"
"strings"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/container"
@ -260,22 +258,3 @@ func MakePackageSetChains(t ImageType, packageSets map[string]rpmmd.PackageSet,
return chainedSets
}
func IsMountpointAllowed(mountpoint string, allowlist []string) bool {
for _, allowed := range allowlist {
match, _ := path.Match(allowed, mountpoint)
if match {
return true
}
// ensure that only clean mountpoints
// are valid
if strings.Contains(mountpoint, "//") {
return false
}
match = strings.HasPrefix(mountpoint, allowed+"/")
if allowed != "/" && match {
return true
}
}
return false
}

View file

@ -700,15 +700,9 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
return fmt.Errorf("Custom mountpoints are not supported for ostree types")
}
invalidMountpoints := []string{}
for _, m := range mountpoints {
if !distro.IsMountpointAllowed(m.Mountpoint, mountpointAllowList) {
invalidMountpoints = append(invalidMountpoints, m.Mountpoint)
}
}
if len(invalidMountpoints) > 0 {
return fmt.Errorf("The following custom mountpoints are not supported %+q", invalidMountpoints)
err := disk.CheckMountpoints(mountpoints, mountpointAllowList)
if err != nil {
return err
}
if osc := customizations.GetOpenSCAP(); osc != nil {

View file

@ -437,15 +437,9 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
mountpoints := customizations.GetFilesystems()
invalidMountpoints := []string{}
for _, m := range mountpoints {
if !distro.IsMountpointAllowed(m.Mountpoint, mountpointAllowList) {
invalidMountpoints = append(invalidMountpoints, m.Mountpoint)
}
}
if len(invalidMountpoints) > 0 {
return fmt.Errorf("The following custom mountpoints are not supported %+q", invalidMountpoints)
err := disk.CheckMountpoints(mountpoints, mountpointAllowList)
if err != nil {
return err
}
if osc := customizations.GetOpenSCAP(); osc != nil {

View file

@ -667,15 +667,9 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
return fmt.Errorf("Custom mountpoints are not supported for ostree types")
}
invalidMountpoints := []string{}
for _, m := range mountpoints {
if !distro.IsMountpointAllowed(m.Mountpoint, mountpointAllowList) {
invalidMountpoints = append(invalidMountpoints, m.Mountpoint)
}
}
if len(invalidMountpoints) > 0 {
return fmt.Errorf("The following custom mountpoints are not supported %+q", invalidMountpoints)
err := disk.CheckMountpoints(mountpoints, mountpointAllowList)
if err != nil {
return err
}
if osc := customizations.GetOpenSCAP(); osc != nil {

View file

@ -603,15 +603,9 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
return fmt.Errorf("Custom mountpoints are not supported for ostree types")
}
invalidMountpoints := []string{}
for _, m := range mountpoints {
if !distro.IsMountpointAllowed(m.Mountpoint, mountpointAllowList) {
invalidMountpoints = append(invalidMountpoints, m.Mountpoint)
}
}
if len(invalidMountpoints) > 0 {
return fmt.Errorf("The following custom mountpoints are not supported %+q", invalidMountpoints)
err := disk.CheckMountpoints(mountpoints, mountpointAllowList)
if err != nil {
return err
}
if osc := customizations.GetOpenSCAP(); osc != nil {