distro: move isMountpointAllowed
Move the `isMountpointAllowed` function to the common distro package since this function is shared used in multiple distro packages.
This commit is contained in:
parent
4e2cea61bb
commit
682481d4d7
5 changed files with 25 additions and 84 deletions
|
|
@ -3,6 +3,8 @@ package distro
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
|
|
@ -257,3 +259,22 @@ 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
|
@ -735,25 +734,6 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
return manifest.Serialize(packageSets)
|
||||
}
|
||||
|
||||
func isMountpointAllowed(mountpoint string) bool {
|
||||
for _, allowed := range mountpointAllowList {
|
||||
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
|
||||
}
|
||||
|
||||
// checkOptions checks the validity and compatibility of options and customizations for the image type.
|
||||
func (t *imageType) checkOptions(customizations *blueprint.Customizations, options distro.ImageOptions) error {
|
||||
if t.bootISO && t.rpmOstree {
|
||||
|
|
@ -781,7 +761,7 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
|
|||
|
||||
invalidMountpoints := []string{}
|
||||
for _, m := range mountpoints {
|
||||
if !isMountpointAllowed(m.Mountpoint) {
|
||||
if !distro.IsMountpointAllowed(m.Mountpoint, mountpointAllowList) {
|
||||
invalidMountpoints = append(invalidMountpoints, m.Mountpoint)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
|
@ -427,25 +426,6 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
)
|
||||
}
|
||||
|
||||
func isMountpointAllowed(mountpoint string) bool {
|
||||
for _, allowed := range mountpointAllowList {
|
||||
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
|
||||
}
|
||||
|
||||
// checkOptions checks the validity and compatibility of options and customizations for the image type.
|
||||
func (t *imageType) checkOptions(customizations *blueprint.Customizations, options distro.ImageOptions) error {
|
||||
|
||||
|
|
@ -453,7 +433,7 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
|
|||
|
||||
invalidMountpoints := []string{}
|
||||
for _, m := range mountpoints {
|
||||
if !isMountpointAllowed(m.Mountpoint) {
|
||||
if !distro.IsMountpointAllowed(m.Mountpoint, mountpointAllowList) {
|
||||
invalidMountpoints = append(invalidMountpoints, m.Mountpoint)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
|
@ -546,25 +545,6 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
)
|
||||
}
|
||||
|
||||
func isMountpointAllowed(mountpoint string) bool {
|
||||
for _, allowed := range mountpointAllowList {
|
||||
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
|
||||
}
|
||||
|
||||
// checkOptions checks the validity and compatibility of options and customizations for the image type.
|
||||
func (t *imageType) checkOptions(customizations *blueprint.Customizations, options distro.ImageOptions) error {
|
||||
if t.bootISO && t.rpmOstree {
|
||||
|
|
@ -623,7 +603,7 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
|
|||
|
||||
invalidMountpoints := []string{}
|
||||
for _, m := range mountpoints {
|
||||
if !isMountpointAllowed(m.Mountpoint) {
|
||||
if !distro.IsMountpointAllowed(m.Mountpoint, mountpointAllowList) {
|
||||
invalidMountpoints = append(invalidMountpoints, m.Mountpoint)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
|
@ -492,25 +491,6 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations,
|
|||
)
|
||||
}
|
||||
|
||||
func isMountpointAllowed(mountpoint string) bool {
|
||||
for _, allowed := range mountpointAllowList {
|
||||
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
|
||||
}
|
||||
|
||||
// checkOptions checks the validity and compatibility of options and customizations for the image type.
|
||||
func (t *imageType) checkOptions(customizations *blueprint.Customizations, options distro.ImageOptions) error {
|
||||
if t.bootISO && t.rpmOstree {
|
||||
|
|
@ -569,7 +549,7 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
|
|||
|
||||
invalidMountpoints := []string{}
|
||||
for _, m := range mountpoints {
|
||||
if !isMountpointAllowed(m.Mountpoint) {
|
||||
if !distro.IsMountpointAllowed(m.Mountpoint, mountpointAllowList) {
|
||||
invalidMountpoints = append(invalidMountpoints, m.Mountpoint)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue