diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-11-04 03:15:39 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-11-04 03:15:39 +0900 |
| commit | af15b1c048e97c092f7a5eeb30f20d13cd972486 (patch) | |
| tree | c2d9e82655844cbf7130651f3a918b8c8a256f13 /internal/app/config.go | |
| parent | 7962681f4a9ea0614fe788ca2cda2c697cfff162 (diff) | |
app: support mapping target uid as privileged uid in sandbox
Chromium's D-Bus client implementation refuses to work when its getuid call returns a different value than what the D-Bus server is running as. The reason behind this is not fully understood, but this workaround is implemented to support chromium and electron apps. This is not used by default since it has many side effects that break many other programs, like SSH on NixOS.
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/app/config.go')
| -rw-r--r-- | internal/app/config.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/internal/app/config.go b/internal/app/config.go index eccb5922..6a25d833 100644 --- a/internal/app/config.go +++ b/internal/app/config.go @@ -8,11 +8,6 @@ import ( "git.ophivana.moe/security/fortify/internal/system" ) -const ( - mappedID = 65534 - mappedIDString = "65534" -) - // Config is used to seal an *App type Config struct { // D-Bus application ID @@ -54,6 +49,8 @@ type SandboxConfig struct { Net bool `json:"net,omitempty"` // do not run in new session NoNewSession bool `json:"no_new_session,omitempty"` + // map target user uid to privileged user uid in the user namespace + UseRealUID bool `json:"use_real_uid"` // mediated access to wayland socket Wayland bool `json:"wayland,omitempty"` @@ -82,11 +79,15 @@ type FilesystemConfig struct { // 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 { +func (s *SandboxConfig) Bwrap(uid int) *bwrap.Config { if s == nil { return nil } + if !s.UseRealUID { + uid = 65534 + } + conf := (&bwrap.Config{ Net: s.Net, UserNS: s.UserNS, @@ -100,7 +101,7 @@ func (s *SandboxConfig) Bwrap() *bwrap.Config { // initialise map Chmod: make(map[string]os.FileMode), }). - SetUID(mappedID).SetGID(mappedID). + SetUID(uid).SetGID(uid). Procfs("/proc").DevTmpfs("/dev").Mqueue("/dev/mqueue"). Tmpfs("/dev/fortify", 4*1024) |
