oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package codex
2
3import (
4 "encoding/json"
5 "os/exec"
6 "testing"
7)
8
9func TestNestedProcDeny(t *testing.T) {
10 f := fixtureFor(t)
11 var settings struct {
12 Permissions map[string]struct{ Filesystem map[string]string }
13 }
14 if err := json.Unmarshal(f.inputs.Settings, &settings); err != nil {
15 t.Fatal(err)
16 }
17 fs := settings.Permissions["equipo"].Filesystem
18 if fs["/proc"] != "deny" {
19 t.Fatal("proc denial absent")
20 }
21 if fs["/tool"] != "deny" {
22 t.Fatal("tool denial absent")
23 }
24 inner := []string{"/usr/bin/bwrap", "--ro-bind", "/", "/", "--tmpfs", "/proc", "--tmpfs", "/tool", "--remount-ro", "/tool"}
25 if fs["/dev/fd"] == "deny" {
26 inner = append(inner, "--tmpfs", "/dev/fd")
27 }
28 if fs["/tool/equipo.sock"] == "deny" {
29 inner = append(inner, "--ro-bind", "/dev/null", "/tool/equipo.sock")
30 }
31 inner = append(inner, "/usr/bin/python3", "-c", `import os
32assert not os.path.exists('/proc/1/root')
33assert not os.path.exists('/dev/fd/0')
34assert not os.path.exists('/tool/equipo.sock')
35print('nested-denials-ok')`)
36 args := []string{"--unshare-pid", "--die-with-parent", "--ro-bind", "/usr", "/usr", "--symlink", "usr/bin", "/bin", "--symlink", "usr/lib", "/lib", "--symlink", "usr/lib64", "/lib64", "--proc", "/proc", "--dev", "/dev", "--tmpfs", "/tmp", "--dir", "/tool"}
37 out, err := exec.Command("/usr/bin/bwrap", append(args, inner...)...).CombinedOutput()
38 if err != nil {
39 t.Fatalf("nested deny setup failed: %v: %s", err, out)
40 }
41}
42