disk: move remaining mountpoint policy code to different packages
Move the `CheckMountpoints()` implementation to `blueprint` package, since it does not operate on any data structures from the `disk`. Move the default mountpoint allow list policy definition to the `pathpolicy` package. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
eb0531b89b
commit
26e6983320
7 changed files with 41 additions and 36 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
|
||||
)
|
||||
|
||||
type FilesystemCustomization struct {
|
||||
|
|
@ -69,3 +70,20 @@ func (fsc *FilesystemCustomization) UnmarshalJSON(data []byte) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckMountpointsPolicy checks if the mountpoints are allowed by the policy
|
||||
func CheckMountpointsPolicy(mountpoints []FilesystemCustomization, mountpointAllowList *pathpolicy.PathPolicies) error {
|
||||
invalidMountpoints := []string{}
|
||||
for _, m := range mountpoints {
|
||||
err := mountpointAllowList.Check(m.Mountpoint)
|
||||
if err != nil {
|
||||
invalidMountpoints = append(invalidMountpoints, m.Mountpoint)
|
||||
}
|
||||
}
|
||||
|
||||
if len(invalidMountpoints) > 0 {
|
||||
return fmt.Errorf("The following custom mountpoints are not supported %+q", invalidMountpoints)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,10 @@ package disk
|
|||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -53,19 +50,6 @@ const (
|
|||
XBootLDRPartitionGUID = "BC13C2FF-59E6-4262-A352-B275FD6F7172"
|
||||
)
|
||||
|
||||
var MountpointPolicies = pathpolicy.NewPathPolicies(map[string]pathpolicy.PathPolicy{
|
||||
"/": {Exact: true},
|
||||
"/boot": {Exact: true},
|
||||
"/var": {},
|
||||
"/opt": {},
|
||||
"/srv": {},
|
||||
"/usr": {},
|
||||
"/app": {},
|
||||
"/data": {},
|
||||
"/home": {},
|
||||
"/tmp": {},
|
||||
})
|
||||
|
||||
// Entity is the base interface for all disk-related entities.
|
||||
type Entity interface {
|
||||
// IsContainer indicates if the implementing type can
|
||||
|
|
@ -184,19 +168,3 @@ func NewVolIDFromRand(r *rand.Rand) string {
|
|||
}
|
||||
return hex.EncodeToString(volid)
|
||||
}
|
||||
|
||||
func CheckMountpoints(mountpoints []blueprint.FilesystemCustomization, mountpointAllowList *pathpolicy.PathPolicies) error {
|
||||
invalidMountpoints := []string{}
|
||||
for _, m := range mountpoints {
|
||||
err := mountpointAllowList.Check(m.Mountpoint)
|
||||
if err != nil {
|
||||
invalidMountpoints = append(invalidMountpoints, m.Mountpoint)
|
||||
}
|
||||
}
|
||||
|
||||
if len(invalidMountpoints) > 0 {
|
||||
return fmt.Errorf("The following custom mountpoints are not supported %+q", invalidMountpoints)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/image"
|
||||
"github.com/osbuild/osbuild-composer/internal/manifest"
|
||||
"github.com/osbuild/osbuild-composer/internal/oscap"
|
||||
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
|
||||
"github.com/osbuild/osbuild-composer/internal/platform"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/runner"
|
||||
|
|
@ -778,7 +779,7 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
|
|||
return fmt.Errorf("Custom mountpoints are not supported for ostree types")
|
||||
}
|
||||
|
||||
err := disk.CheckMountpoints(mountpoints, disk.MountpointPolicies)
|
||||
err := blueprint.CheckMountpointsPolicy(mountpoints, pathpolicy.MountpointPolicies)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/image"
|
||||
"github.com/osbuild/osbuild-composer/internal/manifest"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
|
||||
"github.com/osbuild/osbuild-composer/internal/platform"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/runner"
|
||||
|
|
@ -492,7 +493,7 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
|
|||
|
||||
mountpoints := customizations.GetFilesystems()
|
||||
|
||||
err := disk.CheckMountpoints(mountpoints, disk.MountpointPolicies)
|
||||
err := blueprint.CheckMountpointsPolicy(mountpoints, pathpolicy.MountpointPolicies)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/image"
|
||||
"github.com/osbuild/osbuild-composer/internal/manifest"
|
||||
"github.com/osbuild/osbuild-composer/internal/oscap"
|
||||
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
|
||||
"github.com/osbuild/osbuild-composer/internal/platform"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/workload"
|
||||
|
|
@ -411,7 +412,7 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
|
|||
return fmt.Errorf("Custom mountpoints are not supported for ostree types")
|
||||
}
|
||||
|
||||
err := disk.CheckMountpoints(mountpoints, disk.MountpointPolicies)
|
||||
err := blueprint.CheckMountpointsPolicy(mountpoints, pathpolicy.MountpointPolicies)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/image"
|
||||
"github.com/osbuild/osbuild-composer/internal/manifest"
|
||||
"github.com/osbuild/osbuild-composer/internal/oscap"
|
||||
"github.com/osbuild/osbuild-composer/internal/pathpolicy"
|
||||
"github.com/osbuild/osbuild-composer/internal/platform"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/workload"
|
||||
|
|
@ -391,7 +392,7 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio
|
|||
return fmt.Errorf("Custom mountpoints are not supported for ostree types")
|
||||
}
|
||||
|
||||
err := disk.CheckMountpoints(mountpoints, disk.MountpointPolicies)
|
||||
err := blueprint.CheckMountpointsPolicy(mountpoints, pathpolicy.MountpointPolicies)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
15
internal/pathpolicy/policies.go
Normal file
15
internal/pathpolicy/policies.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package pathpolicy
|
||||
|
||||
// MountpointPolicies is a set of default mountpoint policies used for filesystem customizations
|
||||
var MountpointPolicies = NewPathPolicies(map[string]PathPolicy{
|
||||
"/": {Exact: true},
|
||||
"/boot": {Exact: true},
|
||||
"/var": {},
|
||||
"/opt": {},
|
||||
"/srv": {},
|
||||
"/usr": {},
|
||||
"/app": {},
|
||||
"/data": {},
|
||||
"/home": {},
|
||||
"/tmp": {},
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue