Compare commits
3 Commits
32c90ef4e7
...
f8502c3ece
Author | SHA1 | Date | |
---|---|---|---|
f8502c3ece | |||
996b42634d | |||
300571af47 |
@ -101,6 +101,7 @@ var testCasesNixos = []sealTestCase{
|
|||||||
"HOME=/var/lib/persist/module/fortify/0/1",
|
"HOME=/var/lib/persist/module/fortify/0/1",
|
||||||
"PULSE_COOKIE=" + fst.Tmp + "/pulse-cookie",
|
"PULSE_COOKIE=" + fst.Tmp + "/pulse-cookie",
|
||||||
"PULSE_SERVER=unix:/run/user/1971/pulse/native",
|
"PULSE_SERVER=unix:/run/user/1971/pulse/native",
|
||||||
|
"SHELL=/run/current-system/sw/bin/zsh",
|
||||||
"TERM=xterm-256color",
|
"TERM=xterm-256color",
|
||||||
"USER=u0_a1",
|
"USER=u0_a1",
|
||||||
"WAYLAND_DISPLAY=wayland-0",
|
"WAYLAND_DISPLAY=wayland-0",
|
||||||
|
@ -41,6 +41,7 @@ var testCasesPd = []sealTestCase{
|
|||||||
Args: []string{"/run/current-system/sw/bin/zsh"},
|
Args: []string{"/run/current-system/sw/bin/zsh"},
|
||||||
Env: []string{
|
Env: []string{
|
||||||
"HOME=/home/chronos",
|
"HOME=/home/chronos",
|
||||||
|
"SHELL=/run/current-system/sw/bin/zsh",
|
||||||
"TERM=xterm-256color",
|
"TERM=xterm-256color",
|
||||||
"USER=chronos",
|
"USER=chronos",
|
||||||
"XDG_RUNTIME_DIR=/run/user/65534",
|
"XDG_RUNTIME_DIR=/run/user/65534",
|
||||||
@ -259,6 +260,7 @@ var testCasesPd = []sealTestCase{
|
|||||||
"HOME=/home/chronos",
|
"HOME=/home/chronos",
|
||||||
"PULSE_COOKIE=" + fst.Tmp + "/pulse-cookie",
|
"PULSE_COOKIE=" + fst.Tmp + "/pulse-cookie",
|
||||||
"PULSE_SERVER=unix:/run/user/65534/pulse/native",
|
"PULSE_SERVER=unix:/run/user/65534/pulse/native",
|
||||||
|
"SHELL=/run/current-system/sw/bin/zsh",
|
||||||
"TERM=xterm-256color",
|
"TERM=xterm-256color",
|
||||||
"USER=chronos",
|
"USER=chronos",
|
||||||
"WAYLAND_DISPLAY=wayland-0",
|
"WAYLAND_DISPLAY=wayland-0",
|
||||||
|
@ -255,8 +255,9 @@ func (seal *outcome) finalise(ctx context.Context, sys sys.State, config *fst.Co
|
|||||||
mapuid = newInt(uid)
|
mapuid = newInt(uid)
|
||||||
mapgid = newInt(gid)
|
mapgid = newInt(gid)
|
||||||
if seal.env == nil {
|
if seal.env == nil {
|
||||||
seal.env = make(map[string]string)
|
seal.env = make(map[string]string, 1<<6)
|
||||||
}
|
}
|
||||||
|
seal.env[shell] = shellPath
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -6,7 +6,12 @@
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
testCases = import ./sandbox/case {
|
testCases = import ./sandbox/case {
|
||||||
inherit (pkgs) lib callPackage foot;
|
inherit (pkgs)
|
||||||
|
lib
|
||||||
|
callPackage
|
||||||
|
writeText
|
||||||
|
foot
|
||||||
|
;
|
||||||
inherit (config.environment.fortify.package) version;
|
inherit (config.environment.fortify.package) version;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
@ -23,6 +23,7 @@ func printf(format string, v ...any) { printfFunc(format, v...) }
|
|||||||
func fatalf(format string, v ...any) { fatalfFunc(format, v...) }
|
func fatalf(format string, v ...any) { fatalfFunc(format, v...) }
|
||||||
|
|
||||||
type TestCase struct {
|
type TestCase struct {
|
||||||
|
Env []string `json:"env"`
|
||||||
FS *FS `json:"fs"`
|
FS *FS `json:"fs"`
|
||||||
Mount []*MountinfoEntry `json:"mount"`
|
Mount []*MountinfoEntry `json:"mount"`
|
||||||
Seccomp bool `json:"seccomp"`
|
Seccomp bool `json:"seccomp"`
|
||||||
@ -34,13 +35,46 @@ type T struct {
|
|||||||
MountsPath string
|
MountsPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *T) MustCheckFile(wantFilePath string) {
|
func (t *T) MustCheckFile(wantFilePath, markerPath string) {
|
||||||
var want *TestCase
|
var want *TestCase
|
||||||
mustDecode(wantFilePath, &want)
|
mustDecode(wantFilePath, &want)
|
||||||
t.MustCheck(want)
|
t.MustCheck(want)
|
||||||
|
if _, err := os.Create(markerPath); err != nil {
|
||||||
|
fatalf("cannot create success marker: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *T) MustCheck(want *TestCase) {
|
func (t *T) MustCheck(want *TestCase) {
|
||||||
|
if want.Env != nil {
|
||||||
|
var (
|
||||||
|
fail bool
|
||||||
|
i int
|
||||||
|
got string
|
||||||
|
)
|
||||||
|
for i, got = range os.Environ() {
|
||||||
|
if i == len(want.Env) {
|
||||||
|
fatalf("got more than %d environment variables", len(want.Env))
|
||||||
|
}
|
||||||
|
if got != want.Env[i] {
|
||||||
|
fail = true
|
||||||
|
printf("[FAIL] %s", got)
|
||||||
|
} else {
|
||||||
|
printf("[ OK ] %s", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i++
|
||||||
|
if i != len(want.Env) {
|
||||||
|
fatalf("got %d environment variables, want %d", i, len(want.Env))
|
||||||
|
}
|
||||||
|
|
||||||
|
if fail {
|
||||||
|
fatalf("[FAIL] some environment variables did not match")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("[SKIP] skipping environ check")
|
||||||
|
}
|
||||||
|
|
||||||
if want.FS != nil && t.FS != nil {
|
if want.FS != nil && t.FS != nil {
|
||||||
if err := want.FS.Compare(".", t.FS); err != nil {
|
if err := want.FS.Compare(".", t.FS); err != nil {
|
||||||
fatalf("%v", err)
|
fatalf("%v", err)
|
||||||
|
@ -24,7 +24,7 @@ buildGoModule {
|
|||||||
import "os"
|
import "os"
|
||||||
import "git.gensokyo.uk/security/fortify/test/sandbox"
|
import "git.gensokyo.uk/security/fortify/test/sandbox"
|
||||||
|
|
||||||
func main() { (&sandbox.T{FS: os.DirFS("/")}).MustCheckFile(os.Args[1]) }
|
func main() { (&sandbox.T{FS: os.DirFS("/")}).MustCheckFile(os.Args[1], "/tmp/sandbox-ok") }
|
||||||
''} main.go
|
''} main.go
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
callPackage,
|
callPackage,
|
||||||
|
writeText,
|
||||||
foot,
|
foot,
|
||||||
|
|
||||||
version,
|
version,
|
||||||
@ -29,7 +30,7 @@ let
|
|||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
checkSandbox = callPackage ../. { inherit version; };
|
checkSandbox = callPackage ../assert.nix { inherit version; };
|
||||||
|
|
||||||
callTestCase =
|
callTestCase =
|
||||||
path:
|
path:
|
||||||
@ -48,7 +49,11 @@ let
|
|||||||
inherit (tc) tty mapRealUid;
|
inherit (tc) tty mapRealUid;
|
||||||
share = foot;
|
share = foot;
|
||||||
packages = [ ];
|
packages = [ ];
|
||||||
command = builtins.toString (checkSandbox tc.name tc.want);
|
path = "${checkSandbox}/bin/test";
|
||||||
|
args = [
|
||||||
|
"test"
|
||||||
|
(toString (writeText "fortify-${tc.name}-want.json" (builtins.toJSON tc.want)))
|
||||||
|
];
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,19 @@
|
|||||||
mapRealUid = true;
|
mapRealUid = true;
|
||||||
|
|
||||||
want = {
|
want = {
|
||||||
|
env = [
|
||||||
|
"DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus"
|
||||||
|
"HOME=/var/lib/fortify/u0/a3"
|
||||||
|
"PULSE_SERVER=unix:/run/user/1000/pulse/native"
|
||||||
|
"SHELL=/run/current-system/sw/bin/bash"
|
||||||
|
"TERM=linux"
|
||||||
|
"USER=u0_a3"
|
||||||
|
"WAYLAND_DISPLAY=wayland-0"
|
||||||
|
"XDG_RUNTIME_DIR=/run/user/1000"
|
||||||
|
"XDG_SESSION_CLASS=user"
|
||||||
|
"XDG_SESSION_TYPE=tty"
|
||||||
|
];
|
||||||
|
|
||||||
fs = fs "dead" {
|
fs = fs "dead" {
|
||||||
".fortify" = fs "800001ed" {
|
".fortify" = fs "800001ed" {
|
||||||
etc = fs "800001ed" null null;
|
etc = fs "800001ed" null null;
|
||||||
|
@ -9,6 +9,19 @@
|
|||||||
mapRealUid = false;
|
mapRealUid = false;
|
||||||
|
|
||||||
want = {
|
want = {
|
||||||
|
env = [
|
||||||
|
"DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/65534/bus"
|
||||||
|
"HOME=/var/lib/fortify/u0/a1"
|
||||||
|
"PULSE_SERVER=unix:/run/user/65534/pulse/native"
|
||||||
|
"SHELL=/run/current-system/sw/bin/bash"
|
||||||
|
"TERM=linux"
|
||||||
|
"USER=u0_a1"
|
||||||
|
"WAYLAND_DISPLAY=wayland-0"
|
||||||
|
"XDG_RUNTIME_DIR=/run/user/65534"
|
||||||
|
"XDG_SESSION_CLASS=user"
|
||||||
|
"XDG_SESSION_TYPE=tty"
|
||||||
|
];
|
||||||
|
|
||||||
fs = fs "dead" {
|
fs = fs "dead" {
|
||||||
".fortify" = fs "800001ed" {
|
".fortify" = fs "800001ed" {
|
||||||
etc = fs "800001ed" null null;
|
etc = fs "800001ed" null null;
|
||||||
|
@ -9,6 +9,19 @@
|
|||||||
mapRealUid = false;
|
mapRealUid = false;
|
||||||
|
|
||||||
want = {
|
want = {
|
||||||
|
env = [
|
||||||
|
"DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/65534/bus"
|
||||||
|
"HOME=/var/lib/fortify/u0/a2"
|
||||||
|
"PULSE_SERVER=unix:/run/user/65534/pulse/native"
|
||||||
|
"SHELL=/run/current-system/sw/bin/bash"
|
||||||
|
"TERM=linux"
|
||||||
|
"USER=u0_a2"
|
||||||
|
"WAYLAND_DISPLAY=wayland-0"
|
||||||
|
"XDG_RUNTIME_DIR=/run/user/65534"
|
||||||
|
"XDG_SESSION_CLASS=user"
|
||||||
|
"XDG_SESSION_TYPE=tty"
|
||||||
|
];
|
||||||
|
|
||||||
fs = fs "dead" {
|
fs = fs "dead" {
|
||||||
".fortify" = fs "800001ed" {
|
".fortify" = fs "800001ed" {
|
||||||
etc = fs "800001ed" null null;
|
etc = fs "800001ed" null null;
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
writeShellScript,
|
|
||||||
writeText,
|
|
||||||
callPackage,
|
|
||||||
|
|
||||||
version,
|
|
||||||
}:
|
|
||||||
name: want:
|
|
||||||
writeShellScript "fortify-${name}-check-sandbox-script" ''
|
|
||||||
set -e
|
|
||||||
${callPackage ./assert.nix { inherit version; }}/bin/test \
|
|
||||||
${writeText "fortify-${name}-want.json" (builtins.toJSON want)}
|
|
||||||
touch /tmp/sandbox-ok
|
|
||||||
''
|
|
Loading…
Reference in New Issue
Block a user