2024-09-22 00:29:36 +09:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"git.ophivana.moe/cat/fortify/acl"
|
2024-10-16 01:38:59 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal/system"
|
2024-09-22 00:29:36 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
xdgRuntimeDir = "XDG_RUNTIME_DIR"
|
|
|
|
xdgSessionClass = "XDG_SESSION_CLASS"
|
|
|
|
xdgSessionType = "XDG_SESSION_TYPE"
|
|
|
|
)
|
|
|
|
|
|
|
|
// shareRuntime queues actions for sharing/ensuring the runtime and share directories
|
|
|
|
func (seal *appSeal) shareRuntime() {
|
2024-10-11 04:18:15 +09:00
|
|
|
// mount tmpfs on inner runtime (e.g. `/run/user/%d`)
|
2024-10-15 02:15:55 +09:00
|
|
|
seal.sys.bwrap.Tmpfs("/run/user", 1*1024*1024)
|
|
|
|
seal.sys.bwrap.Tmpfs(seal.sys.runtime, 8*1024*1024)
|
|
|
|
|
|
|
|
// point to inner runtime path `/run/user/%d`
|
2024-10-16 01:38:59 +09:00
|
|
|
seal.sys.bwrap.SetEnv[xdgRuntimeDir] = seal.sys.runtime
|
|
|
|
seal.sys.bwrap.SetEnv[xdgSessionClass] = "user"
|
|
|
|
seal.sys.bwrap.SetEnv[xdgSessionType] = "tty"
|
2024-10-11 04:18:15 +09:00
|
|
|
|
2024-09-22 00:29:36 +09:00
|
|
|
// ensure RunDir (e.g. `/run/user/%d/fortify`)
|
2024-10-16 01:38:59 +09:00
|
|
|
seal.sys.Ensure(seal.RunDirPath, 0700)
|
|
|
|
seal.sys.UpdatePermType(system.User, seal.RunDirPath, acl.Execute)
|
2024-09-22 00:29:36 +09:00
|
|
|
|
|
|
|
// ensure runtime directory ACL (e.g. `/run/user/%d`)
|
2024-10-16 01:38:59 +09:00
|
|
|
seal.sys.UpdatePermType(system.User, seal.RuntimePath, acl.Execute)
|
2024-09-22 00:29:36 +09:00
|
|
|
|
2024-10-10 12:44:08 +09:00
|
|
|
// ensure process-specific share local to XDG_RUNTIME_DIR (e.g. `/run/user/%d/fortify/%s`)
|
|
|
|
seal.shareLocal = path.Join(seal.RunDirPath, seal.id.String())
|
2024-10-16 01:38:59 +09:00
|
|
|
seal.sys.Ephemeral(system.Process, seal.shareLocal, 0700)
|
|
|
|
seal.sys.UpdatePerm(seal.shareLocal, acl.Execute)
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|