hst/fsbind: optional autoroot behaviour
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m17s
Test / Hakurei (push) Successful in 3m10s
Test / Hpkg (push) Successful in 4m9s
Test / Sandbox (race detector) (push) Successful in 4m33s
Test / Hakurei (race detector) (push) Successful in 5m9s
Test / Flake checks (push) Successful in 1m23s
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m17s
Test / Hakurei (push) Successful in 3m10s
Test / Hpkg (push) Successful in 4m9s
Test / Sandbox (race detector) (push) Successful in 4m33s
Test / Hakurei (race detector) (push) Successful in 5m9s
Test / Flake checks (push) Successful in 1m23s
This allows autoroot to be configured via Filesystem. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
8db906ee64
commit
059164d4fa
@ -24,9 +24,21 @@ type FSBind struct {
|
|||||||
Device bool `json:"dev,omitempty"`
|
Device bool `json:"dev,omitempty"`
|
||||||
// skip this mount point if the host path does not exist
|
// skip this mount point if the host path does not exist
|
||||||
Optional bool `json:"optional,omitempty"`
|
Optional bool `json:"optional,omitempty"`
|
||||||
|
|
||||||
|
// enable autoroot behaviour;
|
||||||
|
// this requires Target to be [container.AbsFHSRoot].
|
||||||
|
AutoRoot bool `json:"autoroot,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *FSBind) Valid() bool { return b != nil && b.Source != nil }
|
func (b *FSBind) Valid() bool {
|
||||||
|
if b == nil || b.Source == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if b.AutoRoot && (b.Target == nil || b.Target.String() != container.FHSRoot) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (b *FSBind) Path() *container.Absolute {
|
func (b *FSBind) Path() *container.Absolute {
|
||||||
if !b.Valid() {
|
if !b.Valid() {
|
||||||
@ -64,28 +76,45 @@ func (b *FSBind) Apply(ops *container.Ops) {
|
|||||||
if b.Optional {
|
if b.Optional {
|
||||||
flags |= container.BindOptional
|
flags |= container.BindOptional
|
||||||
}
|
}
|
||||||
ops.Bind(b.Source, target, flags)
|
|
||||||
|
if !b.AutoRoot {
|
||||||
|
ops.Bind(b.Source, target, flags)
|
||||||
|
} else {
|
||||||
|
ops.Root(b.Source, flags)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *FSBind) String() string {
|
func (b *FSBind) String() string {
|
||||||
g := 4
|
|
||||||
if !b.Valid() {
|
if !b.Valid() {
|
||||||
return "<invalid>"
|
return "<invalid>"
|
||||||
}
|
}
|
||||||
|
|
||||||
g += len(b.Source.String())
|
var flagSym string
|
||||||
|
if b.Device {
|
||||||
|
flagSym = "d"
|
||||||
|
} else if b.Write {
|
||||||
|
flagSym = "w"
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.AutoRoot {
|
||||||
|
prefix := "autoroot"
|
||||||
|
if flagSym != "" {
|
||||||
|
prefix += ":" + flagSym
|
||||||
|
}
|
||||||
|
if b.Source.String() != container.FHSRoot {
|
||||||
|
return prefix + ":" + b.Source.String()
|
||||||
|
}
|
||||||
|
return prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
g := 4 + len(b.Source.String())
|
||||||
if b.Target != nil {
|
if b.Target != nil {
|
||||||
g += len(b.Target.String())
|
g += len(b.Target.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
expr := new(strings.Builder)
|
expr := new(strings.Builder)
|
||||||
expr.Grow(g)
|
expr.Grow(g)
|
||||||
|
expr.WriteString(flagSym)
|
||||||
if b.Device {
|
|
||||||
expr.WriteString("d")
|
|
||||||
} else if b.Write {
|
|
||||||
expr.WriteString("w")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !b.Optional {
|
if !b.Optional {
|
||||||
expr.WriteString("*")
|
expr.WriteString("*")
|
||||||
|
@ -62,5 +62,36 @@ func TestFSBind(t *testing.T) {
|
|||||||
Target: m("/"),
|
Target: m("/"),
|
||||||
}}, m("/"), ms("/"),
|
}}, m("/"), ms("/"),
|
||||||
"*/"},
|
"*/"},
|
||||||
|
|
||||||
|
{"autoroot nil target", &hst.FSBind{
|
||||||
|
Source: m("/"),
|
||||||
|
AutoRoot: true,
|
||||||
|
}, false, nil, nil, nil, "<invalid>"},
|
||||||
|
|
||||||
|
{"autoroot bad target", &hst.FSBind{
|
||||||
|
Source: m("/"),
|
||||||
|
Target: m("/etc/"),
|
||||||
|
AutoRoot: true,
|
||||||
|
}, false, nil, nil, nil, "<invalid>"},
|
||||||
|
|
||||||
|
{"autoroot pd", &hst.FSBind{
|
||||||
|
Target: m("/"),
|
||||||
|
Source: m("/"),
|
||||||
|
Write: true,
|
||||||
|
AutoRoot: true,
|
||||||
|
}, true, container.Ops{&container.AutoRootOp{
|
||||||
|
Host: m("/"),
|
||||||
|
Flags: container.BindWritable,
|
||||||
|
}}, m("/"), ms("/"), "autoroot:w"},
|
||||||
|
|
||||||
|
{"autoroot silly", &hst.FSBind{
|
||||||
|
Target: m("/"),
|
||||||
|
Source: m("/etc"),
|
||||||
|
Write: true,
|
||||||
|
AutoRoot: true,
|
||||||
|
}, true, container.Ops{&container.AutoRootOp{
|
||||||
|
Host: m("/etc"),
|
||||||
|
Flags: container.BindWritable,
|
||||||
|
}}, m("/"), ms("/etc"), "autoroot:w:/etc"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user