2024-09-22 00:29:36 +09:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/user"
|
|
|
|
|
|
|
|
"git.ophivana.moe/cat/fortify/dbus"
|
2024-10-11 02:01:03 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/helper/bwrap"
|
2024-09-22 00:29:36 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal"
|
|
|
|
"git.ophivana.moe/cat/fortify/internal/state"
|
2024-10-16 01:38:59 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal/system"
|
2024-09-22 00:29:36 +09:00
|
|
|
"git.ophivana.moe/cat/fortify/internal/verbose"
|
|
|
|
)
|
|
|
|
|
|
|
|
// appSeal seals the application with child-related information
|
|
|
|
type appSeal struct {
|
|
|
|
// application unique identifier
|
|
|
|
id *appID
|
2024-10-11 02:01:03 +09:00
|
|
|
// wayland socket path if mediated wayland is enabled
|
|
|
|
wl string
|
2024-10-11 04:18:15 +09:00
|
|
|
// wait for wayland client to exit if mediated wayland is enabled,
|
|
|
|
// (wlDone == nil) determines whether mediated wayland setup is performed
|
2024-10-11 02:01:03 +09:00
|
|
|
wlDone chan struct{}
|
2024-09-22 00:29:36 +09:00
|
|
|
|
|
|
|
// freedesktop application ID
|
|
|
|
fid string
|
|
|
|
// argv to start process with in the final confined environment
|
|
|
|
command []string
|
|
|
|
// persistent process state store
|
|
|
|
store state.Store
|
|
|
|
|
|
|
|
// uint8 representation of launch method sealed from config
|
|
|
|
launchOption uint8
|
|
|
|
// process-specific share directory path
|
|
|
|
share string
|
2024-10-10 12:44:08 +09:00
|
|
|
// process-specific share directory path local to XDG_RUNTIME_DIR
|
|
|
|
shareLocal string
|
2024-09-22 00:29:36 +09:00
|
|
|
|
|
|
|
// path to launcher program
|
|
|
|
toolPath string
|
|
|
|
// pass-through enablement tracking from config
|
|
|
|
et state.Enablements
|
|
|
|
|
|
|
|
// prevents sharing from happening twice
|
|
|
|
shared bool
|
|
|
|
// seal system-level component
|
2024-10-16 01:38:59 +09:00
|
|
|
sys *appSealSys
|
2024-09-22 00:29:36 +09:00
|
|
|
|
|
|
|
// used in various sealing operations
|
|
|
|
internal.SystemConstants
|
|
|
|
|
|
|
|
// protected by upstream mutex
|
|
|
|
}
|
|
|
|
|
2024-10-16 01:38:59 +09:00
|
|
|
// appSealSys encapsulates app seal behaviour with OS interactions
|
|
|
|
type appSealSys struct {
|
2024-10-11 04:18:15 +09:00
|
|
|
bwrap *bwrap.Config
|
2024-10-16 01:38:59 +09:00
|
|
|
// paths to override by mounting tmpfs over them
|
|
|
|
override []string
|
2024-09-22 00:29:36 +09:00
|
|
|
|
2024-10-11 04:18:15 +09:00
|
|
|
// default formatted XDG_RUNTIME_DIR of User
|
|
|
|
runtime string
|
2024-09-22 00:29:36 +09:00
|
|
|
// sealed path to fortify executable, used by shim
|
|
|
|
executable string
|
|
|
|
// target user sealed from config
|
2024-10-16 01:38:59 +09:00
|
|
|
user *user.User
|
2024-09-22 00:29:36 +09:00
|
|
|
|
2024-10-16 01:38:59 +09:00
|
|
|
*system.I
|
2024-09-22 00:29:36 +09:00
|
|
|
|
|
|
|
// protected by upstream mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
// shareAll calls all share methods in sequence
|
|
|
|
func (seal *appSeal) shareAll(bus [2]*dbus.Config) error {
|
|
|
|
if seal.shared {
|
|
|
|
panic("seal shared twice")
|
|
|
|
}
|
|
|
|
seal.shared = true
|
|
|
|
|
2024-10-15 02:15:55 +09:00
|
|
|
targetTmpdir := seal.shareTmpdirChild()
|
|
|
|
verbose.Printf("child tmpdir %q configured\n", targetTmpdir)
|
2024-09-22 00:29:36 +09:00
|
|
|
seal.shareRuntime()
|
2024-10-13 02:43:00 +09:00
|
|
|
seal.shareSystem()
|
2024-09-22 00:29:36 +09:00
|
|
|
if err := seal.shareDisplay(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := seal.sharePulse(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure dbus session bus defaults
|
|
|
|
if bus[0] == nil {
|
|
|
|
bus[0] = dbus.NewConfig(seal.fid, true, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := seal.shareDBus(bus); err != nil {
|
|
|
|
return err
|
2024-10-16 01:38:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// queue overriding tmpfs at the end of seal.sys.bwrap.Filesystem
|
|
|
|
for _, dest := range seal.sys.override {
|
|
|
|
seal.sys.bwrap.Tmpfs(dest, 8*1024)
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|