aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/container.go
diff options
context:
space:
mode:
authorClayton Gilmer <netadr_t@outlook.com>2025-08-18 12:00:52 +0900
committerOphestra <cat@gensokyo.uk>2025-08-18 16:28:14 +0900
commit5db07140726e6e1bf615ed075e9a8b653508c2a7 (patch)
tree15cdb5ed164ec5cdc32527f87ee969ad704cdd11 /container/container.go
parent69a4ab81053ef31d745ac0d92531cefb7d3a3e44 (diff)
container: optionally isolate host abstract UNIX domain sockets via landlock
Diffstat (limited to 'container/container.go')
-rw-r--r--container/container.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/container/container.go b/container/container.go
index 52691cea..fa5a34e5 100644
--- a/container/container.go
+++ b/container/container.go
@@ -92,6 +92,8 @@ type (
RetainSession bool
// Do not [syscall.CLONE_NEWNET].
HostNet bool
+ // Do not [LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET].
+ HostAbstract bool
// Retain CAP_SYS_ADMIN.
Privileged bool
}
@@ -185,6 +187,51 @@ func (p *Container) Start() error {
"prctl(PR_SET_NO_NEW_PRIVS):")
}
+ // landlock: depends on per-thread state but acts on a process group
+ {
+ rulesetAttr := &RulesetAttr{Scoped: LANDLOCK_SCOPE_SIGNAL}
+ if !p.HostAbstract {
+ rulesetAttr.Scoped |= LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET
+ }
+
+ if abi, err := LandlockGetABI(); err != nil {
+ if p.HostAbstract {
+ // landlock can be skipped here as it restricts access to resources
+ // already covered by namespaces (pid)
+ goto landlockOut
+ }
+ return wrapErrSuffix(err,
+ "landlock does not appear to be enabled:")
+ } else if abi < 6 {
+ if p.HostAbstract {
+ // see above comment
+ goto landlockOut
+ }
+ return msg.WrapErr(ENOSYS,
+ "kernel version too old for LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET")
+ } else {
+ msg.Verbosef("landlock abi version %d", abi)
+ }
+
+ if rulesetFd, err := rulesetAttr.Create(0); err != nil {
+ return wrapErrSuffix(err,
+ "cannot create landlock ruleset:")
+ } else {
+ msg.Verbosef("enforcing landlock ruleset %s", rulesetAttr)
+ if err = LandlockRestrictSelf(rulesetFd, 0); err != nil {
+ _ = Close(rulesetFd)
+ return wrapErrSuffix(err,
+ "cannot enforce landlock ruleset:")
+ }
+ if err = Close(rulesetFd); err != nil {
+ msg.Verbosef("cannot close landlock ruleset: %v", err)
+ // not fatal
+ }
+ }
+
+ landlockOut:
+ }
+
msg.Verbose("starting container init")
if err := p.cmd.Start(); err != nil {
return msg.WrapErr(err, err.Error())