diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-10-15 02:15:55 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-10-15 02:15:55 +0900 |
| commit | 2faf510146733c28a5dbc3245175700abcf4f966 (patch) | |
| tree | 707b5fec5d210c19123205969731837b780e318d /internal/app/config.go | |
| parent | a0db19b9ad7def33eacdfc23d462604dce3af3bb (diff) | |
helper/bwrap: ordered filesystem args
The argument builder was written based on the incorrect assumption that bwrap arguments are unordered. The argument builder is replaced in this commit to correct that mistake.
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/app/config.go')
| -rw-r--r-- | internal/app/config.go | 61 |
1 files changed, 22 insertions, 39 deletions
diff --git a/internal/app/config.go b/internal/app/config.go index 7950c59d..3f6d1c0f 100644 --- a/internal/app/config.go +++ b/internal/app/config.go @@ -1,11 +1,18 @@ package app import ( + "encoding/gob" + "os" + "git.ophivana.moe/cat/fortify/dbus" "git.ophivana.moe/cat/fortify/helper/bwrap" "git.ophivana.moe/cat/fortify/internal/state" ) +func init() { + gob.Register(new(bwrap.PermConfig[*bwrap.TmpfsConfig])) +} + // Config is used to seal an *App type Config struct { // D-Bus application ID @@ -55,7 +62,7 @@ type SandboxConfig struct { // sandbox host filesystem access Filesystem []*FilesystemConfig `json:"filesystem"` // tmpfs mount points to mount last - Tmpfs []bwrap.TmpfsConfig `json:"tmpfs"` + Tmpfs []string `json:"tmpfs"` } type FilesystemConfig struct { @@ -71,61 +78,39 @@ type FilesystemConfig struct { Must bool `json:"require,omitempty"` } +// Bwrap returns the address of the corresponding bwrap.Config to s. +// Note that remaining tmpfs entries must be queued by the caller prior to launch. func (s *SandboxConfig) Bwrap() *bwrap.Config { if s == nil { return nil } - nobody := 65534 - conf := &bwrap.Config{ + conf := (&bwrap.Config{ Net: s.Net, UserNS: s.UserNS, - UID: &nobody, - GID: &nobody, Hostname: s.Hostname, Clearenv: true, SetEnv: s.Env, - Procfs: []string{"/proc"}, - DevTmpfs: []string{"/dev"}, - Mqueue: []string{"/dev/mqueue"}, NewSession: !s.NoNewSession, DieWithParent: true, AsInit: true, - } + + // initialise map + Chmod: make(map[string]os.FileMode), + }). + SetUID(65534).SetGID(65534). + Procfs("/proc").DevTmpfs("/dev").Mqueue("/dev/mqueue") for _, c := range s.Filesystem { if c == nil { continue } - p := [2]string{c.Src, c.Dst} + src := c.Src + dest := c.Dst if c.Dst == "" { - p[1] = c.Src - } - - switch { - case c.Device: - if c.Must { - conf.DevBind = append(conf.DevBind, p) - } else { - conf.DevBindTry = append(conf.DevBindTry, p) - } - case c.Write: - if c.Must { - conf.Bind = append(conf.Bind, p) - } else { - conf.BindTry = append(conf.BindTry, p) - } - default: - if c.Must { - conf.ROBind = append(conf.ROBind, p) - } else { - conf.ROBindTry = append(conf.ROBindTry, p) - } + dest = c.Src } - } - - for _, tmpfs := range s.Tmpfs { - conf.Tmpfs = append(conf.Tmpfs, bwrap.PermConfig[bwrap.TmpfsConfig]{Path: tmpfs, Last: true}) + conf.Bind(src, dest, !c.Must, c.Write, c.Device) } return conf @@ -164,9 +149,7 @@ func Template() *Config { {Src: "/data/user/0", Dst: "/data/data", Write: true, Must: true}, {Src: "/var/tmp", Write: true}, }, - Tmpfs: []bwrap.TmpfsConfig{ - {Size: 8 * 1024, Dir: "/var/run/nscd"}, - }, + Tmpfs: []string{"/var/run/nscd"}, }, SystemBus: &dbus.Config{ See: nil, |
