container: optionally isolate host abstract UNIX domain sockets via landlock
Some checks failed
Test / Create distribution (push) Successful in 36s
Test / Create distribution (pull_request) Successful in 31s
Test / Sandbox (pull_request) Successful in 2m13s
Test / Sandbox (push) Successful in 2m20s
Test / Hpkg (push) Successful in 4m6s
Test / Hpkg (pull_request) Successful in 3m59s
Test / Sandbox (race detector) (pull_request) Successful in 4m15s
Test / Sandbox (race detector) (push) Successful in 4m27s
Test / Hakurei (race detector) (push) Failing after 22m30s
Test / Flake checks (pull_request) Has been cancelled
Test / Hakurei (pull_request) Has been cancelled
Test / Hakurei (race detector) (pull_request) Has been cancelled
Test / Hakurei (push) Failing after 39m52s
Test / Flake checks (push) Has been skipped
Some checks failed
Test / Create distribution (push) Successful in 36s
Test / Create distribution (pull_request) Successful in 31s
Test / Sandbox (pull_request) Successful in 2m13s
Test / Sandbox (push) Successful in 2m20s
Test / Hpkg (push) Successful in 4m6s
Test / Hpkg (pull_request) Successful in 3m59s
Test / Sandbox (race detector) (pull_request) Successful in 4m15s
Test / Sandbox (race detector) (push) Successful in 4m27s
Test / Hakurei (race detector) (push) Failing after 22m30s
Test / Flake checks (pull_request) Has been cancelled
Test / Hakurei (pull_request) Has been cancelled
Test / Hakurei (race detector) (pull_request) Has been cancelled
Test / Hakurei (push) Failing after 39m52s
Test / Flake checks (push) Has been skipped
This commit is contained in:
parent
551ec8c27d
commit
c1ff73b1b1
@ -28,6 +28,8 @@ type appInfo struct {
|
|||||||
// passed through to [hst.Config]
|
// passed through to [hst.Config]
|
||||||
Net bool `json:"net,omitempty"`
|
Net bool `json:"net,omitempty"`
|
||||||
// passed through to [hst.Config]
|
// passed through to [hst.Config]
|
||||||
|
ScopeAbstract bool `json:"scope_abstract,omitempty"`
|
||||||
|
// passed through to [hst.Config]
|
||||||
Device bool `json:"dev,omitempty"`
|
Device bool `json:"dev,omitempty"`
|
||||||
// passed through to [hst.Config]
|
// passed through to [hst.Config]
|
||||||
Tty bool `json:"tty,omitempty"`
|
Tty bool `json:"tty,omitempty"`
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -14,6 +15,7 @@ import (
|
|||||||
. "syscall"
|
. "syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"hakurei.app/container/landlock"
|
||||||
"hakurei.app/container/seccomp"
|
"hakurei.app/container/seccomp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -92,6 +94,8 @@ type (
|
|||||||
RetainSession bool
|
RetainSession bool
|
||||||
// Do not [syscall.CLONE_NEWNET].
|
// Do not [syscall.CLONE_NEWNET].
|
||||||
HostNet bool
|
HostNet bool
|
||||||
|
// Scope abstract UNIX domain sockets using LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET.
|
||||||
|
ScopeAbstract bool
|
||||||
// Retain CAP_SYS_ADMIN.
|
// Retain CAP_SYS_ADMIN.
|
||||||
Privileged bool
|
Privileged bool
|
||||||
}
|
}
|
||||||
@ -179,6 +183,12 @@ func (p *Container) Start() error {
|
|||||||
p.wait = make(chan struct{})
|
p.wait = make(chan struct{})
|
||||||
|
|
||||||
done <- func() error { // setup depending on per-thread state must happen here
|
done <- func() error { // setup depending on per-thread state must happen here
|
||||||
|
if p.ScopeAbstract {
|
||||||
|
if err := landlock.ScopeAbstract(); err != nil {
|
||||||
|
log.Fatalf("could not scope abstract unix sockets: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
msg.Verbose("starting container init")
|
msg.Verbose("starting container init")
|
||||||
if err := p.cmd.Start(); err != nil {
|
if err := p.cmd.Start(); err != nil {
|
||||||
return msg.WrapErr(err, err.Error())
|
return msg.WrapErr(err, err.Error())
|
||||||
|
55
container/landlock/landlock.go
Normal file
55
container/landlock/landlock.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package landlock
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <linux/landlock.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
LANDLOCK_CREATE_RULESET_VERSION = C.LANDLOCK_CREATE_RULESET_VERSION
|
||||||
|
LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET = C.LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET
|
||||||
|
|
||||||
|
SYS_LANDLOCK_CREATE_RULESET = C.SYS_landlock_create_ruleset
|
||||||
|
SYS_LANDLOCK_RESTRICT_SELF = C.SYS_landlock_restrict_self
|
||||||
|
)
|
||||||
|
|
||||||
|
type LandlockRulesetAttr = C.struct_landlock_ruleset_attr
|
||||||
|
|
||||||
|
// ScopeAbstract calls landlock_restrict_self and must be called from a goroutine wired to an m
|
||||||
|
// with the process starting from the same goroutine.
|
||||||
|
func ScopeAbstract() error {
|
||||||
|
abi, _, err := syscall.Syscall(SYS_LANDLOCK_CREATE_RULESET, 0, 0, LANDLOCK_CREATE_RULESET_VERSION)
|
||||||
|
|
||||||
|
if err != 0 {
|
||||||
|
return fmt.Errorf("could not fetch landlock ABI: errno %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if abi < 6 {
|
||||||
|
return fmt.Errorf("landlock ABI must be >= 6, got %d", abi)
|
||||||
|
}
|
||||||
|
|
||||||
|
attrs := LandlockRulesetAttr{
|
||||||
|
scoped: LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET,
|
||||||
|
}
|
||||||
|
|
||||||
|
fd, _, err := syscall.Syscall(SYS_LANDLOCK_CREATE_RULESET, uintptr(unsafe.Pointer(&attrs)), unsafe.Sizeof(attrs), 0)
|
||||||
|
|
||||||
|
if err != 0 {
|
||||||
|
return fmt.Errorf("could not create landlock ruleset: errno %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer syscall.Close(int(fd))
|
||||||
|
|
||||||
|
r, _, err := syscall.Syscall(SYS_LANDLOCK_RESTRICT_SELF, fd, 0, 0)
|
||||||
|
if r != 0 {
|
||||||
|
return fmt.Errorf("could not restrict self via landlock: errno %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -79,6 +79,8 @@ type (
|
|||||||
Userns bool `json:"userns,omitempty"`
|
Userns bool `json:"userns,omitempty"`
|
||||||
// share host net namespace
|
// share host net namespace
|
||||||
Net bool `json:"net,omitempty"`
|
Net bool `json:"net,omitempty"`
|
||||||
|
// disallow accessing abstract UNIX domain sockets created outside the container
|
||||||
|
ScopeAbstract bool `json:"scope_abstract,omitempty"`
|
||||||
// allow dangerous terminal I/O
|
// allow dangerous terminal I/O
|
||||||
Tty bool `json:"tty,omitempty"`
|
Tty bool `json:"tty,omitempty"`
|
||||||
// allow multiarch
|
// allow multiarch
|
||||||
|
@ -33,6 +33,7 @@ func newContainer(s *hst.ContainerConfig, os sys.State, prefix string, uid, gid
|
|||||||
SeccompPresets: s.SeccompPresets,
|
SeccompPresets: s.SeccompPresets,
|
||||||
RetainSession: s.Tty,
|
RetainSession: s.Tty,
|
||||||
HostNet: s.Net,
|
HostNet: s.Net,
|
||||||
|
ScopeAbstract: s.ScopeAbstract,
|
||||||
|
|
||||||
// the container is canceled when shim is requested to exit or receives an interrupt or termination signal;
|
// the container is canceled when shim is requested to exit or receives an interrupt or termination signal;
|
||||||
// this behaviour is implemented in the shim
|
// this behaviour is implemented in the shim
|
||||||
|
@ -137,6 +137,7 @@ in
|
|||||||
multiarch
|
multiarch
|
||||||
env
|
env
|
||||||
;
|
;
|
||||||
|
scope_abstract = app.scopeAbstract;
|
||||||
map_real_uid = app.mapRealUid;
|
map_real_uid = app.mapRealUid;
|
||||||
|
|
||||||
filesystem =
|
filesystem =
|
||||||
|
22
options.md
22
options.md
@ -572,6 +572,28 @@ boolean
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
` true `
|
||||||
|
|
||||||
|
|
||||||
|
## environment\.hakurei\.apps\.\<name>\.scopeAbstract
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Whether to restrict abstract UNIX domain socket access\.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Type:*
|
||||||
|
boolean
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*Default:*
|
||||||
|
` true `
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*Example:*
|
*Example:*
|
||||||
` true `
|
` true `
|
||||||
|
|
||||||
|
@ -182,6 +182,9 @@ in
|
|||||||
net = mkEnableOption "network access" // {
|
net = mkEnableOption "network access" // {
|
||||||
default = true;
|
default = true;
|
||||||
};
|
};
|
||||||
|
scopeAbstract = mkEnableOption "abstract unix domain socket access" // {
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
|
||||||
nix = mkEnableOption "nix daemon access";
|
nix = mkEnableOption "nix daemon access";
|
||||||
mapRealUid = mkEnableOption "mapping to priv-user uid";
|
mapRealUid = mkEnableOption "mapping to priv-user uid";
|
||||||
|
@ -64,6 +64,10 @@ func (p *Proxy) Start() error {
|
|||||||
argF, func(z *container.Container) {
|
argF, func(z *container.Container) {
|
||||||
z.SeccompFlags |= seccomp.AllowMultiarch
|
z.SeccompFlags |= seccomp.AllowMultiarch
|
||||||
z.SeccompPresets |= seccomp.PresetStrict
|
z.SeccompPresets |= seccomp.PresetStrict
|
||||||
|
|
||||||
|
// xdg-dbus-proxy requires host abstract UNIX domain socket access
|
||||||
|
z.ScopeAbstract = false
|
||||||
|
|
||||||
z.Hostname = "hakurei-dbus"
|
z.Hostname = "hakurei-dbus"
|
||||||
if p.output != nil {
|
if p.output != nil {
|
||||||
z.Stdout, z.Stderr = p.output, p.output
|
z.Stdout, z.Stderr = p.output, p.output
|
||||||
|
@ -243,7 +243,7 @@ in
|
|||||||
seccomp = true;
|
seccomp = true;
|
||||||
|
|
||||||
try_socket = "/tmp/.X11-unix/X0";
|
try_socket = "/tmp/.X11-unix/X0";
|
||||||
socket_abstract = true;
|
socket_abstract = false;
|
||||||
socket_pathname = true;
|
socket_pathname = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ in
|
|||||||
seccomp = true;
|
seccomp = true;
|
||||||
|
|
||||||
try_socket = "/tmp/.X11-unix/X0";
|
try_socket = "/tmp/.X11-unix/X0";
|
||||||
socket_abstract = true;
|
socket_abstract = false;
|
||||||
socket_pathname = false;
|
socket_pathname = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ in
|
|||||||
seccomp = true;
|
seccomp = true;
|
||||||
|
|
||||||
try_socket = "/tmp/.X11-unix/X0";
|
try_socket = "/tmp/.X11-unix/X0";
|
||||||
socket_abstract = true;
|
socket_abstract = false;
|
||||||
socket_pathname = false;
|
socket_pathname = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ in
|
|||||||
seccomp = true;
|
seccomp = true;
|
||||||
|
|
||||||
try_socket = "/tmp/.X11-unix/X0";
|
try_socket = "/tmp/.X11-unix/X0";
|
||||||
socket_abstract = true;
|
socket_abstract = false;
|
||||||
socket_pathname = false;
|
socket_pathname = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ in
|
|||||||
seccomp = true;
|
seccomp = true;
|
||||||
|
|
||||||
try_socket = "/tmp/.X11-unix/X0";
|
try_socket = "/tmp/.X11-unix/X0";
|
||||||
socket_abstract = true;
|
socket_abstract = false;
|
||||||
socket_pathname = true;
|
socket_pathname = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user