hst/config: hold acl struct by value
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (race detector) (push) Successful in 4m6s
Test / Hpkg (push) Successful in 4m12s
Test / Hakurei (race detector) (push) Successful in 4m46s
Test / Sandbox (push) Successful in 1m22s
Test / Hakurei (push) Successful in 2m18s
Test / Flake checks (push) Successful in 1m37s

Doc comments are also reworded for clarity.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-10-14 07:02:14 +09:00
parent 4c647add0d
commit f95e0a7568
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
8 changed files with 26 additions and 21 deletions

View File

@ -129,11 +129,8 @@ func printShowInstance(
} }
if len(config.ExtraPerms) > 0 { if len(config.ExtraPerms) > 0 {
t.Printf("Extra ACL\n") t.Printf("Extra ACL\n")
for _, p := range config.ExtraPerms { for i := range config.ExtraPerms {
if p == nil { t.Printf(" %s\n", config.ExtraPerms[i].String())
continue
}
t.Printf(" %s\n", p.String())
} }
t.Printf("\n") t.Printf("\n")
} }

View File

@ -88,7 +88,7 @@ App
Flags: none Flags: none
`, false}, `, false},
{"config nil entries", nil, &hst.Config{Container: &hst.ContainerConfig{Filesystem: make([]hst.FilesystemConfigJSON, 1)}, ExtraPerms: make([]*hst.ExtraPermConfig, 1)}, false, false, `Error: container configuration missing path to home directory! {"config nil entries", nil, &hst.Config{Container: &hst.ContainerConfig{Filesystem: make([]hst.FilesystemConfigJSON, 1)}, ExtraPerms: make([]hst.ExtraPermConfig, 1)}, false, false, `Error: container configuration missing path to home directory!
App App
Identity: 0 Identity: 0
@ -99,6 +99,7 @@ Filesystem
<invalid> <invalid>
Extra ACL Extra ACL
<invalid>
`, false}, `, false},
{"config pd dbus see", nil, &hst.Config{SessionBus: &hst.BusConfig{See: []string{"org.example.test"}}}, false, false, `Error: configuration missing container state! {"config pd dbus see", nil, &hst.Config{SessionBus: &hst.BusConfig{See: []string{"org.example.test"}}}, false, false, `Error: configuration missing container state!

View File

@ -100,7 +100,7 @@ func (app *appInfo) toHst(pathSet *appPathSet, pathname *check.Absolute, argv []
Path: pathname, Path: pathname,
Args: argv, Args: argv,
}, },
ExtraPerms: []*hst.ExtraPermConfig{ ExtraPerms: []hst.ExtraPermConfig{
{Path: dataHome, Execute: true}, {Path: dataHome, Execute: true},
{Ensure: true, Path: pathSet.baseDir, Read: true, Write: true, Execute: true}, {Ensure: true, Path: pathSet.baseDir, Read: true, Write: true, Execute: true},
}, },

View File

@ -28,7 +28,7 @@ func withNixDaemon(
mustRunAppDropShell(ctx, msg, updateConfig(&hst.Config{ mustRunAppDropShell(ctx, msg, updateConfig(&hst.Config{
ID: app.ID, ID: app.ID,
ExtraPerms: []*hst.ExtraPermConfig{ ExtraPerms: []hst.ExtraPermConfig{
{Path: dataHome, Execute: true}, {Path: dataHome, Execute: true},
{Ensure: true, Path: pathSet.baseDir, Read: true, Write: true, Execute: true}, {Ensure: true, Path: pathSet.baseDir, Read: true, Write: true, Execute: true},
}, },
@ -83,7 +83,7 @@ func withCacheDir(
mustRunAppDropShell(ctx, msg, &hst.Config{ mustRunAppDropShell(ctx, msg, &hst.Config{
ID: app.ID, ID: app.ID,
ExtraPerms: []*hst.ExtraPermConfig{ ExtraPerms: []hst.ExtraPermConfig{
{Path: dataHome, Execute: true}, {Path: dataHome, Execute: true},
{Ensure: true, Path: pathSet.baseDir, Read: true, Write: true, Execute: true}, {Ensure: true, Path: pathSet.baseDir, Read: true, Write: true, Execute: true},
{Path: workDir, Execute: true}, {Path: workDir, Execute: true},

View File

@ -26,8 +26,8 @@ type Config struct {
// and the bare socket is made available to the container. // and the bare socket is made available to the container.
DirectWayland bool `json:"direct_wayland,omitempty"` DirectWayland bool `json:"direct_wayland,omitempty"`
// Extra acl update ops to perform before setuid. // Extra acl updates to perform before setuid.
ExtraPerms []*ExtraPermConfig `json:"extra_perms,omitempty"` ExtraPerms []ExtraPermConfig `json:"extra_perms,omitempty"`
// Numerical application id, passed to hsu, used to derive init user namespace credentials. // Numerical application id, passed to hsu, used to derive init user namespace credentials.
Identity int `json:"identity"` Identity int `json:"identity"`
@ -86,15 +86,21 @@ func (config *Config) Validate() error {
return nil return nil
} }
// ExtraPermConfig describes an acl update op. // ExtraPermConfig describes an acl update to perform before setuid.
type ExtraPermConfig struct { type ExtraPermConfig struct {
Ensure bool `json:"ensure,omitempty"` // Whether to create Path as a directory if it does not exist.
Path *check.Absolute `json:"path"` Ensure bool `json:"ensure,omitempty"`
Read bool `json:"r,omitempty"` // Pathname to act on.
Write bool `json:"w,omitempty"` Path *check.Absolute `json:"path"`
Execute bool `json:"x,omitempty"` // Whether to set ACL_READ for the target user.
Read bool `json:"r,omitempty"`
// Whether to set ACL_WRITE for the target user.
Write bool `json:"w,omitempty"`
// Whether to set ACL_EXECUTE for the target user.
Execute bool `json:"x,omitempty"`
} }
// String returns a checked string representation of [ExtraPermConfig].
func (e *ExtraPermConfig) String() string { func (e *ExtraPermConfig) String() string {
if e == nil || e.Path == nil { if e == nil || e.Path == nil {
return "<invalid>" return "<invalid>"

View File

@ -88,7 +88,7 @@ func Template() *Config {
}, },
DirectWayland: false, DirectWayland: false,
ExtraPerms: []*ExtraPermConfig{ ExtraPerms: []ExtraPermConfig{
{Path: fhs.AbsVarLib.Append("hakurei/u0"), Ensure: true, Execute: true}, {Path: fhs.AbsVarLib.Append("hakurei/u0"), Ensure: true, Execute: true},
{Path: fhs.AbsVarLib.Append("hakurei/u0/org.chromium.Chromium"), Read: true, Write: true, Execute: true}, {Path: fhs.AbsVarLib.Append("hakurei/u0/org.chromium.Chromium"), Read: true, Write: true, Execute: true},
}, },

View File

@ -156,7 +156,7 @@ type outcomeStateSys struct {
// Copied from [hst.Config]. Safe for read by spWaylandOp.toSystem only. // Copied from [hst.Config]. Safe for read by spWaylandOp.toSystem only.
directWayland bool directWayland bool
// Copied header from [hst.Config]. Safe for read by spFinalOp.toSystem only. // Copied header from [hst.Config]. Safe for read by spFinalOp.toSystem only.
extraPerms []*hst.ExtraPermConfig extraPerms []hst.ExtraPermConfig
// Copied address from [hst.Config]. Safe for read by spDBusOp.toSystem only. // Copied address from [hst.Config]. Safe for read by spDBusOp.toSystem only.
sessionBus, systemBus *hst.BusConfig sessionBus, systemBus *hst.BusConfig

View File

@ -21,8 +21,9 @@ type spFinalOp struct{}
func (s spFinalOp) toSystem(state *outcomeStateSys) error { func (s spFinalOp) toSystem(state *outcomeStateSys) error {
// append ExtraPerms last // append ExtraPerms last
for _, p := range state.extraPerms { for i := range state.extraPerms {
if p == nil || p.Path == nil { p := &state.extraPerms[i]
if p.Path == nil {
continue continue
} }