diff options
| author | Clayton Gilmer <netadr_t@outlook.com> | 2025-08-18 12:00:52 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-18 16:28:14 +0900 |
| commit | 5db07140726e6e1bf615ed075e9a8b653508c2a7 (patch) | |
| tree | 15cdb5ed164ec5cdc32527f87ee969ad704cdd11 /container/landlock_test.go | |
| parent | 69a4ab81053ef31d745ac0d92531cefb7d3a3e44 (diff) | |
container: optionally isolate host abstract UNIX domain sockets via landlock
Diffstat (limited to 'container/landlock_test.go')
| -rw-r--r-- | container/landlock_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/container/landlock_test.go b/container/landlock_test.go new file mode 100644 index 00000000..d204bc31 --- /dev/null +++ b/container/landlock_test.go @@ -0,0 +1,61 @@ +package container_test + +import ( + "testing" + "unsafe" + + "hakurei.app/container" +) + +func TestLandlockString(t *testing.T) { + testCases := []struct { + name string + rulesetAttr *container.RulesetAttr + want string + }{ + {"nil", nil, "NULL"}, + {"zero", new(container.RulesetAttr), "0"}, + {"some", &container.RulesetAttr{Scoped: container.LANDLOCK_SCOPE_SIGNAL}, "scoped: signal"}, + {"set", &container.RulesetAttr{ + HandledAccessFS: container.LANDLOCK_ACCESS_FS_MAKE_SYM | container.LANDLOCK_ACCESS_FS_IOCTL_DEV | container.LANDLOCK_ACCESS_FS_WRITE_FILE, + HandledAccessNet: container.LANDLOCK_ACCESS_NET_BIND_TCP, + Scoped: container.LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET | container.LANDLOCK_SCOPE_SIGNAL, + }, "fs: write_file make_sym fs_ioctl_dev, net: bind_tcp, scoped: abstract_unix_socket signal"}, + {"all", &container.RulesetAttr{ + HandledAccessFS: container.LANDLOCK_ACCESS_FS_EXECUTE | + container.LANDLOCK_ACCESS_FS_WRITE_FILE | + container.LANDLOCK_ACCESS_FS_READ_FILE | + container.LANDLOCK_ACCESS_FS_READ_DIR | + container.LANDLOCK_ACCESS_FS_REMOVE_DIR | + container.LANDLOCK_ACCESS_FS_REMOVE_FILE | + container.LANDLOCK_ACCESS_FS_MAKE_CHAR | + container.LANDLOCK_ACCESS_FS_MAKE_DIR | + container.LANDLOCK_ACCESS_FS_MAKE_REG | + container.LANDLOCK_ACCESS_FS_MAKE_SOCK | + container.LANDLOCK_ACCESS_FS_MAKE_FIFO | + container.LANDLOCK_ACCESS_FS_MAKE_BLOCK | + container.LANDLOCK_ACCESS_FS_MAKE_SYM | + container.LANDLOCK_ACCESS_FS_REFER | + container.LANDLOCK_ACCESS_FS_TRUNCATE | + container.LANDLOCK_ACCESS_FS_IOCTL_DEV, + HandledAccessNet: container.LANDLOCK_ACCESS_NET_BIND_TCP | + container.LANDLOCK_ACCESS_NET_CONNECT_TCP, + Scoped: container.LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET | + container.LANDLOCK_SCOPE_SIGNAL, + }, "fs: execute write_file read_file read_dir remove_dir remove_file make_char make_dir make_reg make_sock make_fifo make_block make_sym fs_refer fs_truncate fs_ioctl_dev, net: bind_tcp connect_tcp, scoped: abstract_unix_socket signal"}, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + if got := tc.rulesetAttr.String(); got != tc.want { + t.Errorf("String: %s, want %s", got, tc.want) + } + }) + } +} + +func TestLandlockAttrSize(t *testing.T) { + want := 24 + if got := unsafe.Sizeof(container.RulesetAttr{}); got != uintptr(want) { + t.Errorf("Sizeof: %d, want %d", got, want) + } +} |
