@raytrace-cli/cli 0.11.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +241 -473
- package/THIRD_PARTY_NOTICES.md +51 -0
- package/bin/raytrace.mjs +30 -0
- package/dist/dashboard/assets/index-CM-3AX0c.css +1 -0
- package/dist/dashboard/assets/index-DF_klLF4.js +38 -0
- package/dist/dashboard/favicon.svg +4 -6
- package/dist/dashboard/index.html +3 -3
- package/package.json +4 -2
- package/proxy/evidence-store.mjs +7 -2
- package/proxy/evidence-store.test.mjs +11 -0
- package/proxy/gvisor-forwarder.mjs +3 -1
- package/proxy/gvisor-forwarder.test.mjs +2 -0
- package/src/lima.mjs +5 -2
- package/src/report.mjs +178 -0
- package/worker/sandbox/SYSCALL_CATALOG.md +2 -2
- package/worker/sandbox/claude-hook.mjs +43 -4
- package/worker/sandbox/collector.py +99 -0
- package/worker/sandbox/engine.py +2 -0
- package/worker/sandbox/projects.py +14 -6
- package/worker/sandbox/setup.py +9 -0
- package/worker/sandbox/test_capture.py +102 -0
- package/dist/dashboard/assets/index-DepcI8Fi.js +0 -38
- package/dist/dashboard/assets/index-H97VLD5l.css +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""Raw-call context and failed execs. Run: python3 -B -m unittest discover -s worker/sandbox -p 'test_*.py'"""
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import sys
|
|
5
|
+
import unittest
|
|
6
|
+
|
|
7
|
+
sys.path.insert(0, str(Path(__file__).parent))
|
|
8
|
+
import collector # noqa: E402
|
|
9
|
+
import engine # noqa: E402
|
|
10
|
+
import setup # noqa: E402
|
|
11
|
+
|
|
12
|
+
HERE = Path(__file__).parent
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def attempt(pid, executable, argv):
|
|
16
|
+
return {'kind': 'exec_attempt', 'pid': pid, 'ppid': 1, 'executable': executable, 'argv': argv,
|
|
17
|
+
'timestamp_ns': '1794866886430727989', 'process_start_ns': '1794866886430553658', 'container_id': 'c' * 64,
|
|
18
|
+
'markers': {'RAYTRACE_CALL_ID': 'call_1'}}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TraceConfig(unittest.TestCase):
|
|
22
|
+
def test_a_number_only_call_has_its_enter_point_with_the_same_context(self):
|
|
23
|
+
config = setup.trace_config('aarch64', (HERE / 'syscall_catalog.sql').read_text(), '/run/x.sock')
|
|
24
|
+
points = {point['name']: point for point in config['trace_session']['points']}
|
|
25
|
+
for number in (34, 35, 38, 45, 46, 52, 53, 276): # mkdirat unlinkat renameat truncate ftruncate fchmod fchmodat renameat2
|
|
26
|
+
enter, leave = points[f'syscall/sysno/{number}/enter'], points[f'syscall/sysno/{number}/exit']
|
|
27
|
+
self.assertEqual(enter['context_fields'], leave['context_fields'])
|
|
28
|
+
self.assertIn('container_id', enter['context_fields'])
|
|
29
|
+
self.assertIn('group_id', enter['context_fields'])
|
|
30
|
+
# Typed points carry their own context, and the exec points are as they were.
|
|
31
|
+
self.assertNotIn('syscall/openat/enter', points)
|
|
32
|
+
self.assertNotIn('syscall/sysno/221/enter', points)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class RawCalls(unittest.TestCase):
|
|
36
|
+
def setUp(self):
|
|
37
|
+
self.engine = engine.Engine(':memory:', arch='aarch64', watch=False)
|
|
38
|
+
|
|
39
|
+
def test_the_enter_event_is_taken_and_not_queued(self):
|
|
40
|
+
self.assertTrue(self.engine.accept({'kind': 'syscall_enter', 'sysno': 35, 'container_id': 'c' * 64}))
|
|
41
|
+
self.assertTrue(self.engine.inbox.empty())
|
|
42
|
+
self.assertTrue(self.engine.accept({'kind': 'syscall_return', 'sysno': 35, 'container_id': 'c' * 64}))
|
|
43
|
+
self.assertEqual(self.engine.inbox.qsize(), 1)
|
|
44
|
+
|
|
45
|
+
def test_a_refused_delete_with_its_process_is_an_attempt_by_that_process(self):
|
|
46
|
+
box = engine.Sandbox('c' * 64)
|
|
47
|
+
box.workspace, box.guarded = '/nowhere', {'config/keys.js': 'watched'}
|
|
48
|
+
box.processes[41] = {'start_ns': '5', 'ppid': 1, 'name': 'rm', 'argv': ['rm', 'config/keys.js'], 'call_id': 'call_9'}
|
|
49
|
+
self.engine.numbered_call(box, {'kind': 'syscall_return', 'sysno': 35, 'errno': 13, 'pid': 41, 'ppid': 1,
|
|
50
|
+
'process_start_ns': '5', 'timestamp_ns': '100', 'cwd': '/workspace'})
|
|
51
|
+
(fact,) = self.engine.facts.values()
|
|
52
|
+
self.assertEqual((fact['path'], fact['effect'], fact['intent'], fact['pid'], fact['call_id']),
|
|
53
|
+
('config/keys.js', 'attempted', 'delete', 41, 'call_9'))
|
|
54
|
+
self.assertEqual(box.raw[0]['who']['pid'], 41)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class FailedExecs(unittest.TestCase):
|
|
58
|
+
def setUp(self):
|
|
59
|
+
self.attempts = collector.ExecAttempts()
|
|
60
|
+
|
|
61
|
+
def test_an_attempt_no_program_follows_failed_when_the_process_exits(self):
|
|
62
|
+
self.assertEqual(self.attempts.see(attempt(7, '/workspace/missing', ['/workspace/missing'])), [])
|
|
63
|
+
self.assertEqual(self.attempts.see({'kind': 'exec_syscall_return', 'pid': 7, 'errno': 0}), [])
|
|
64
|
+
(failed,) = self.attempts.see({'kind': 'process_exit', 'pid': 7, 'exit_code': 255})
|
|
65
|
+
self.assertEqual((failed['kind'], failed['errno'], failed['argv'], failed['tried']),
|
|
66
|
+
('exec_failed', None, ['/workspace/missing'], ['/workspace/missing']))
|
|
67
|
+
self.assertEqual(failed['markers'], {'RAYTRACE_CALL_ID': 'call_1'})
|
|
68
|
+
self.assertIn('inferred', failed)
|
|
69
|
+
self.assertEqual(self.attempts.see({'kind': 'process_exit', 'pid': 7}), []) # gVisor's second exit event
|
|
70
|
+
|
|
71
|
+
def test_a_path_search_that_finds_the_program_is_no_failure(self):
|
|
72
|
+
for folder in ('/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin'):
|
|
73
|
+
self.assertEqual(self.attempts.see(attempt(9, folder + '/python3', ['python3', '-c', 'pass'])), [])
|
|
74
|
+
self.assertEqual(self.attempts.see({'kind': 'exec_succeeded', 'pid': 9}), [])
|
|
75
|
+
self.assertEqual(self.attempts.see({'kind': 'process_exit', 'pid': 9}), [])
|
|
76
|
+
|
|
77
|
+
def test_a_path_search_that_finds_nothing_is_one_failure(self):
|
|
78
|
+
for folder in ('/usr/local/bin', '/usr/bin', '/bin'):
|
|
79
|
+
self.attempts.see(attempt(9, folder + '/nope', ['nope']))
|
|
80
|
+
(failed,) = self.attempts.see({'kind': 'process_exit', 'pid': 9})
|
|
81
|
+
self.assertEqual(failed['tried'], ['/usr/local/bin/nope', '/usr/bin/nope', '/bin/nope'])
|
|
82
|
+
|
|
83
|
+
def test_a_failure_then_another_program_in_the_same_process(self):
|
|
84
|
+
self.attempts.see(attempt(3, '/a', ['/a']))
|
|
85
|
+
(failed,) = self.attempts.see(attempt(3, '/bin/b', ['/bin/b']))
|
|
86
|
+
self.assertEqual(failed['argv'], ['/a'])
|
|
87
|
+
self.assertEqual(self.attempts.see({'kind': 'exec_succeeded', 'pid': 3}), [])
|
|
88
|
+
self.assertEqual(self.attempts.see({'kind': 'process_exit', 'pid': 3}), [])
|
|
89
|
+
|
|
90
|
+
def test_a_failure_gvisor_reported_is_not_said_twice(self):
|
|
91
|
+
self.attempts.see(attempt(4, '/a', ['/a']))
|
|
92
|
+
self.assertEqual(self.attempts.see({'kind': 'exec_failed', 'pid': 4, 'errno': 14}), [])
|
|
93
|
+
self.assertEqual(self.attempts.see({'kind': 'process_exit', 'pid': 4}), [])
|
|
94
|
+
|
|
95
|
+
def test_the_failure_is_json_and_carries_no_raw_packet(self):
|
|
96
|
+
self.attempts.see(attempt(5, '/a', ['/a']))
|
|
97
|
+
(failed,) = self.attempts.see({'kind': 'process_exit', 'pid': 5})
|
|
98
|
+
self.assertNotIn('raw_packet_base64', json.loads(json.dumps(failed)))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
if __name__ == '__main__':
|
|
102
|
+
unittest.main()
|