oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package provider
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7)
8
9func TestCheckGatePins(t *testing.T) {
10 source := filepath.Join(t.TempDir(), "gate")
11 if err := os.WriteFile(source, []byte("exit 1\n"), 0600); err != nil {
12 t.Fatal(err)
13 }
14 in := CheckPolicyInputs{Workspace: t.TempDir(), Bwrap: "/usr/bin/true", Argv: []string{"/usr/bin/true"}, GateFiles: []Mount{{Source: source, Target: "/workspace/Makefile", ReadOnly: true}}}
15 p, err := BuildCheckPolicy(in)
16 if err != nil {
17 t.Fatal(err)
18 }
19 l := Launch{AttemptKey: "checks", Workspace: in.Workspace, Policy: p}
20 if _, err := AttestLaunch(l, in.Argv); err != nil {
21 t.Fatal(err)
22 }
23 if !p.CheckGateMount(in.GateFiles[0]) {
24 t.Fatal("gate pin not certified")
25 }
26 if err := os.WriteFile(source, []byte("exit 0\n"), 0600); err != nil {
27 t.Fatal(err)
28 }
29 if _, err := AttestLaunch(l, in.Argv); err == nil {
30 t.Fatal("changed pinned gate accepted")
31 }
32 for _, target := range []string{"/workspace/../etc/evil", "/workspace/.git/config", "/opt/gate", "/workspace"} {
33 in.GateFiles[0].Target = target
34 if _, err := BuildCheckPolicy(in); err == nil {
35 t.Fatalf("unsafe gate target %s", target)
36 }
37 }
38 in.GateFiles[0].Target = "/workspace/Makefile"
39 in.GateFiles[0].ReadOnly = false
40 if _, err := BuildCheckPolicy(in); err == nil {
41 t.Fatal("writable gate accepted")
42 }
43}
44
45func TestCheckGateDirectoryPins(t *testing.T) {
46 dir := t.TempDir()
47 source := filepath.Join(dir, "scripts")
48 if err := os.Mkdir(source, 0700); err != nil {
49 t.Fatal(err)
50 }
51 if err := os.WriteFile(filepath.Join(source, "check.py"), []byte("import json"), 0600); err != nil {
52 t.Fatal(err)
53 }
54 if err := SealTree(source); err != nil {
55 t.Fatal(err)
56 }
57 t.Cleanup(func() { _ = os.Chmod(source, 0700) })
58 mount := Mount{Source: source, Target: "/workspace/scripts", ReadOnly: true}
59 in := CheckPolicyInputs{Workspace: t.TempDir(), Bwrap: "/usr/bin/true", Argv: []string{"/usr/bin/true"}, GateFiles: []Mount{mount}}
60 p, err := BuildCheckPolicy(in)
61 if err != nil {
62 t.Fatal(err)
63 }
64 l := Launch{AttemptKey: "checks", Workspace: in.Workspace, Policy: p}
65 if _, err := AttestLaunch(l, in.Argv); err != nil {
66 t.Fatal(err)
67 }
68 if !p.CheckGateTree(mount) {
69 t.Fatal("directory mount not recognized")
70 }
71 _ = os.Chmod(source, 0700)
72 _ = os.WriteFile(filepath.Join(source, "json.py"), []byte("shadow"), 0444)
73 _ = os.Chmod(source, 0555)
74 if _, err := AttestLaunch(l, in.Argv); err == nil {
75 t.Fatal("new helper escaped directory digest")
76 }
77}
78