Debian Codegraph @

internal/sandbox/sandbox.go

raw symbols SCIP
1 package sandboxscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
5 "osscip-go gomod github.com/golang/go/src go1.24.0 os/"
6
7 "github.com/landlock-lsm/go-landlock/landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/"
8 "github.com/landlock-lsm/go-landlock/landlock/syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/"
9 "github.com/zouuup/landrun/internal/logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/"
10 )
11
12 type Configscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config# struct {
13 ReadOnlyPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#ReadOnlyPaths. []string
14 ReadWritePathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#ReadWritePaths. []string
15 ReadOnlyExecutablePathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#ReadOnlyExecutablePaths. []string
16 ReadWriteExecutablePathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#ReadWriteExecutablePaths. []string
17 UnixSocketPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnixSocketPaths. []string
18 BindTCPPortsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#BindTCPPorts. []int
19 ConnectTCPPortsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#ConnectTCPPorts. []int
20 BestEffortscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#BestEffort. bool
21 UnrestrictedFilesystemscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedFilesystem. bool
22 UnrestrictedNetworkscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedNetwork. bool
23 UnrestrictedScopedscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedScoped. bool
24 IgnoreMissingPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#IgnoreMissingPaths. bool
25 // Audit logging configuration (Landlock ABI V7+).
26 DisableLogOriginatingscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#DisableLogOriginating. bool
27 EnableLogSubprocessesscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#EnableLogSubprocesses. bool
28 DisableLogSubdomainsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#DisableLogSubdomains. bool
29 }
30
31 // fullFSAccess is the union of every filesystem access right supported by
32 // Landlock V9. It is used as the Config's handled access set so that every
33 // per-path rule we build stays within its bounds.
34 const fullFSAccessscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/fullFSAccess. = landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(
35 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSExecutescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSExecute. |
36 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSWriteFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSWriteFile. |
37 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadFile. |
38 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadDir. |
39 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSRemoveDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSRemoveDir. |
40 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSRemoveFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSRemoveFile. |
41 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeCharscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeChar. |
42 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeDir. |
43 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeRegscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeReg. |
44 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeSockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeSock. |
45 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeFifoscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeFifo. |
46 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeBlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeBlock. |
47 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeSymscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeSym. |
48 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReferscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSRefer. |
49 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSTruncatescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSTruncate. |
50 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSIoctlDevscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSIoctlDev. |
51 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSResolveUnixscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSResolveUnix.,
52 )
53
54 // fullNetAccess is the union of every network access right supported by
55 // Landlock V9 (available since V4).
56 const fullNetAccessscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/fullNetAccess. = landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessNetSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessNetSet#(
57 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessNetBindTCPscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessNetBindTCP. | syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessNetConnectTCPscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessNetConnectTCP.,
58 )
59
60 // fullScoped is the union of every IPC scope supported by Landlock V9
61 // (available since V6).
62 const fullScopedscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/fullScoped. = landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.ScopedSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/ScopedSet#(
63 syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.ScopeAbstractUnixSocketscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/ScopeAbstractUnixSocket. | syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.ScopeSignalscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/ScopeSignal.,
64 )
65
66 // getReadWriteExecutableRights returns a full set of permissions including execution
67 func getReadWriteExecutableRightsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/getReadWriteExecutableRights().(dir bool) landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet# {
68 accessRights := landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(0)
69 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSExecutescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSExecute.)
70 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadFile.)
71 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSWriteFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSWriteFile.)
72 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSTruncatescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSTruncate.)
73 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSIoctlDevscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSIoctlDev.)
74
75 if dir {
76 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadDir.)
77 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSRemoveDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSRemoveDir.)
78 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSRemoveFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSRemoveFile.)
79 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeCharscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeChar.)
80 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeDir.)
81 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeRegscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeReg.)
82 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeSockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeSock.)
83 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeFifoscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeFifo.)
84 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeBlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeBlock.)
85 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeSymscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeSym.)
86 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReferscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSRefer.)
87 }
88
89 return accessRights
90 }
91
92 func getReadOnlyExecutableRightsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/getReadOnlyExecutableRights().(dir bool) landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet# {
93 accessRights := landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(0)
94 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSExecutescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSExecute.)
95 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadFile.)
96 if dir {
97 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadDir.)
98 }
99 return accessRights
100 }
101
102 // getReadOnlyRights returns permissions for read-only access
103 func getReadOnlyRightsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/getReadOnlyRights().(dir bool) landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet# {
104 accessRights := landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(0)
105 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadFile.)
106 if dir {
107 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadDir.)
108 }
109 return accessRights
110 }
111
112 // getReadWriteRights returns permissions for read-write access
113 func getReadWriteRightsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/getReadWriteRights().(dir bool) landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet# {
114 accessRights := landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(0)
115 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadFile.)
116 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSWriteFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSWriteFile.)
117 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSTruncatescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSTruncate.)
118 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSIoctlDevscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSIoctlDev.)
119 if dir {
120 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadDir.)
121 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSRemoveDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSRemoveDir.)
122 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSRemoveFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSRemoveFile.)
123 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeCharscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeChar.)
124 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeDir.)
125 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeRegscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeReg.)
126 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeSockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeSock.)
127 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeFifoscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeFifo.)
128 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeBlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeBlock.)
129 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSMakeSymscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSMakeSym.)
130 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReferscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSRefer.)
131 }
132
133 return accessRights
134 }
135
136 // getUnixSocketRights returns permissions for connecting to a pathname UNIX
137 // domain socket (connect(2)/sendmsg(2)), available since Landlock ABI V9.
138 func getUnixSocketRightsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/getUnixSocketRights().(dir bool) landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet# {
139 accessRights := landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(0)
140 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadFilescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadFile.)
141 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSResolveUnixscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSResolveUnix.)
142 if dir {
143 accessRights |= landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#(syscallscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/.AccessFSReadDirscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock/syscall`/AccessFSReadDir.)
144 }
145 return accessRights
146 }
147
148 // isDirectory checks if the given path is a directory
149 func isDirectoryscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/isDirectory().(path string) bool {
150 fileInfo, err := osscip-go gomod github.com/golang/go/src go1.24.0 os/.Statscip-go gomod github.com/golang/go/src go1.24.0 os/Stat().(path)
151 if err != nil {
152 return false
153 }
154 return fileInfo.IsDirscip-go gomod github.com/golang/go/src go1.24.0 `io/fs`/FileInfo#IsDir().()
155 }
156
157 // pathRule builds a filesystem rule for the given access rights and path,
158 // optionally applying the IgnoreIfMissing modifier so that referencing a
159 // non-existing path does not lead to a runtime error.
160 func pathRulescip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/pathRule().(rights landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.AccessFSSetscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/AccessFSSet#, path string, ignoreMissing bool) landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.Rulescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/Rule# {
161 rule := landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.PathAccessscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/PathAccess().(rights, path)
162 if ignoreMissing {
163 return rule.IgnoreIfMissingscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/FSRule#IgnoreIfMissing().()
164 }
165 return rule
166 }
167
168 func Applyscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Apply().(cfg Configscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#) error {
169 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Infoscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Info().("Sandbox config: %+v", cfg)
170
171 if cfg.UnrestrictedFilesystemscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedFilesystem. {
172 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Infoscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Info().("Unrestricted filesystem access enabled.")
173 }
174 if cfg.UnrestrictedNetworkscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedNetwork. {
175 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Infoscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Info().("Unrestricted network access enabled.")
176 }
177 if cfg.UnrestrictedScopedscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedScoped. {
178 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Infoscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Info().("Unrestricted IPC scoping enabled.")
179 }
180
181 // Determine which access domains should be handled (i.e. restricted).
182 // A domain that is left out of the Config stays completely unrestricted.
183 var configArgs []interface{}
184 if !cfg.UnrestrictedFilesystemscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedFilesystem. {
185 configArgs = append(configArgs, fullFSAccessscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/fullFSAccess.)
186 }
187 if !cfg.UnrestrictedNetworkscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedNetwork. {
188 configArgs = append(configArgs, fullNetAccessscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/fullNetAccess.)
189 }
190 if !cfg.UnrestrictedScopedscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedScoped. {
191 configArgs = append(configArgs, fullScopedscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/fullScoped.)
192 }
193
194 // If every domain is unrestricted, there is nothing for Landlock to do.
195 if len(configArgs) == 0 {
196 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Infoscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Info().("Unrestricted filesystem, network and IPC scoping enabled; no rules applied.")
197 return nil
198 }
199
200 // Collect our rules. Filesystem rules are only meaningful when the
201 // filesystem domain is handled; network rules only when the network
202 // domain is handled. Adding a rule for an unhandled domain is rejected
203 // by Landlock with EINVAL.
204 var allRules []landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.Rulescip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/Rule#
205
206 if !cfg.UnrestrictedFilesystemscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedFilesystem. {
207 for _, path := range cfg.ReadOnlyExecutablePathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#ReadOnlyExecutablePaths. {
208 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Debugscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Debug().("Adding read-only executable path: %s", path)
209 allRules = append(allRules, pathRulescip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/pathRule().(getReadOnlyExecutableRightsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/getReadOnlyExecutableRights().(isDirectoryscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/isDirectory().(path)), path, cfg.IgnoreMissingPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#IgnoreMissingPaths.))
210 }
211
212 for _, path := range cfg.ReadWriteExecutablePathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#ReadWriteExecutablePaths. {
213 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Debugscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Debug().("Adding read-write executable path: %s", path)
214 allRules = append(allRules, pathRulescip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/pathRule().(getReadWriteExecutableRightsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/getReadWriteExecutableRights().(isDirectoryscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/isDirectory().(path)), path, cfg.IgnoreMissingPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#IgnoreMissingPaths.))
215 }
216
217 for _, path := range cfg.ReadOnlyPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#ReadOnlyPaths. {
218 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Debugscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Debug().("Adding read-only path: %s", path)
219 allRules = append(allRules, pathRulescip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/pathRule().(getReadOnlyRightsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/getReadOnlyRights().(isDirectoryscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/isDirectory().(path)), path, cfg.IgnoreMissingPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#IgnoreMissingPaths.))
220 }
221
222 for _, path := range cfg.ReadWritePathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#ReadWritePaths. {
223 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Debugscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Debug().("Adding read-write path: %s", path)
224 allRules = append(allRules, pathRulescip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/pathRule().(getReadWriteRightsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/getReadWriteRights().(isDirectoryscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/isDirectory().(path)), path, cfg.IgnoreMissingPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#IgnoreMissingPaths.))
225 }
226
227 for _, path := range cfg.UnixSocketPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnixSocketPaths. {
228 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Debugscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Debug().("Adding UNIX socket (connect) path: %s", path)
229 allRules = append(allRules, pathRulescip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/pathRule().(getUnixSocketRightsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/getUnixSocketRights().(isDirectoryscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/isDirectory().(path)), path, cfg.IgnoreMissingPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#IgnoreMissingPaths.))
230 }
231 } else if len(cfg.UnixSocketPathsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnixSocketPaths.) > 0 {
232 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Infoscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Info().("Ignoring --unix paths because filesystem access is unrestricted.")
233 }
234
235 if !cfg.UnrestrictedNetworkscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#UnrestrictedNetwork. {
236 for _, port := range cfg.BindTCPPortsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#BindTCPPorts. {
237 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Debugscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Debug().("Adding TCP bind port: %d", port)
238 allRules = append(allRules, landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.BindTCPscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/BindTCP().(uint16(port)))
239 }
240
241 for _, port := range cfg.ConnectTCPPortsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#ConnectTCPPorts. {
242 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Debugscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Debug().("Adding TCP connect port: %d", port)
243 allRules = append(allRules, landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.ConnectTCPscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/ConnectTCP().(uint16(port)))
244 }
245 }
246
247 // Build the Landlock configuration. Start from a custom config that
248 // handles exactly the domains we want to restrict, so that all rules are
249 // enforced in a single ruleset layer. This keeps the "refer" access
250 // right working (it is implicitly denied whenever the filesystem domain
251 // is not handled by a layer).
252 baseCfg, err := landlockscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/.NewConfigscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/NewConfig().(configArgs...)
253 if err != nil {
254 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("failed to build Landlock config: %w", err)
255 }
256 llCfg := *baseCfg
257
258 if cfg.BestEffortscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#BestEffort. {
259 llCfg = llCfg.BestEffortscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/Config#BestEffort().()
260 }
261
262 // Audit logging configuration (Landlock ABI V7+). Without --best-effort
263 // these assert a V7+ kernel and will error at restriction time otherwise.
264 if cfg.DisableLogOriginatingscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#DisableLogOriginating. {
265 llCfg = llCfg.DisableLoggingForOriginatingProcessscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/Config#DisableLoggingForOriginatingProcess().()
266 }
267 if cfg.EnableLogSubprocessesscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#EnableLogSubprocesses. {
268 llCfg = llCfg.EnableLoggingForSubprocessesscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/Config#EnableLoggingForSubprocesses().()
269 }
270 if cfg.DisableLogSubdomainsscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/sandbox`/Config#DisableLogSubdomains. {
271 llCfg = llCfg.DisableLoggingForSubdomainsscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/Config#DisableLoggingForSubdomains().()
272 }
273
274 if len(allRules) == 0 {
275 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Infoscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Info().("No rules provided; applying maximum restrictions for the handled domains.")
276 }
277
278 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Debugscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Debug().("Applying Landlock restrictions: %s", llCfg.Stringscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/Config#String().())
279 if err := llCfg.Restrictscip-go gomod github.com/landlock-lsm/go-landlock v0.9.0 `github.com/landlock-lsm/go-landlock/landlock`/Config#Restrict().(allRules...); err != nil {
280 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("failed to apply Landlock restrictions: %w", err)
281 }
282
283 logscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/.Infoscip-go gomod github.com/zouuup/landrun . `github.com/zouuup/landrun/internal/log`/Info().("Landlock restrictions applied successfully")
284 return nil
285 }