aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/config.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-10-12 22:33:04 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-10-12 22:33:04 +0900
commit805ef99f9bf75189c512401ee5b92942be66342b (patch)
tree99a6e0aebdda3ba6cecb430e88ae0d96831e17b2 /internal/app/config.go
parent283bcba05b55acddbb3ffe664e84fda10ed779ad (diff)
app: filesystem struct that maps to all bwrap bind options
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/app/config.go')
-rw-r--r--internal/app/config.go60
1 files changed, 52 insertions, 8 deletions
diff --git a/internal/app/config.go b/internal/app/config.go
index ca3133c6..d633a240 100644
--- a/internal/app/config.go
+++ b/internal/app/config.go
@@ -55,10 +55,21 @@ type SandboxConfig struct {
// final environment variables
Env map[string]string `json:"env"`
- // paths made available within the sandbox
- Bind [][2]string `json:"bind"`
- // paths made available read-only within the sandbox
- ROBind [][2]string `json:"ro-bind"`
+ // sandbox host filesystem access
+ Filesystem []*FilesystemConfig `json:"filesystem"`
+}
+
+type FilesystemConfig struct {
+ // mount point in sandbox, same as src if empty
+ Dst string `json:"dst,omitempty"`
+ // host filesystem path to make available to sandbox
+ Src string `json:"src"`
+ // write access
+ Write bool `json:"write,omitempty"`
+ // device access
+ Device bool `json:"dev,omitempty"`
+ // exit if unable to share
+ Must bool `json:"require,omitempty"`
}
func (s *SandboxConfig) Bwrap() *bwrap.Config {
@@ -72,8 +83,6 @@ func (s *SandboxConfig) Bwrap() *bwrap.Config {
Hostname: s.Hostname,
Clearenv: true,
SetEnv: s.Env,
- Bind: s.Bind,
- ROBind: s.ROBind,
Procfs: []string{"/proc"},
DevTmpfs: []string{"/dev"},
Mqueue: []string{"/dev/mqueue"},
@@ -87,6 +96,37 @@ func (s *SandboxConfig) Bwrap() *bwrap.Config {
conf.GID = &s.GID
}
+ for _, c := range s.Filesystem {
+ if c == nil {
+ continue
+ }
+ p := [2]string{c.Src, 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)
+ }
+ }
+ }
+
return conf
}
@@ -119,8 +159,12 @@ func Template() *Config {
"GOOGLE_DEFAULT_CLIENT_ID": "77185425430.apps.googleusercontent.com",
"GOOGLE_DEFAULT_CLIENT_SECRET": "OTJgUOQcT7lO7GsGZq2G4IlT",
},
- Bind: [][2]string{{"/sdcard", "/sdcard"}, {"/var/tmp", "/var/tmp"}},
- ROBind: [][2]string{{"/nix", "/nix"}},
+ Filesystem: []*FilesystemConfig{
+ {Src: "/nix"},
+ {Src: "/storage/emulated/0", Write: true, Must: true},
+ {Src: "/data/user/0", Dst: "/data/data", Write: true, Must: true},
+ {Src: "/var/tmp", Write: true},
+ },
},
SystemBus: &dbus.Config{
See: nil,