@raytrace-cli/cli 0.12.0 → 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 +240 -498
- package/THIRD_PARTY_NOTICES.md +51 -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/worker/sandbox/SYSCALL_CATALOG.md +2 -2
- package/worker/sandbox/claude-hook.mjs +3 -4
- package/worker/sandbox/collector.py +99 -0
- package/worker/sandbox/engine.py +2 -0
- 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
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
<svg
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
<path d="
|
|
5
|
-
<path d="M12 12H4.72727C3.22104 12 2 10.779 2 9.27273V4.72727C2 3.22104 3.22104 2 4.72727 2H9.27273C10.779 2 12 3.22104 12 4.72727V12Z" fill="#2E9EFF"/>
|
|
6
|
-
</svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 42 44">
|
|
2
|
+
<style>.top{fill:#edf5dd}.left{fill:#d8e9b7}.right{fill:#b7cf92}.faces{stroke:#647b40}.marks{stroke:#49652a}@media(prefers-color-scheme:dark){.top{fill:#283222}.left{fill:#131b10}.right{fill:#080e07}.faces{stroke:#94b568}.marks{stroke:#e2ffa8}}</style>
|
|
3
|
+
<g class="faces" stroke-width=".7" stroke-linejoin="round"><path class="top" d="M21 2 39 12.5 21 23 3 12.5Z"/><path class="left" d="M3 12.5 21 23V42L3 31.5Z"/><path class="right" d="M21 23 39 12.5V31.5L21 42Z"/></g>
|
|
4
|
+
<g class="marks" fill="none" stroke-width="1.6" stroke-linecap="round"><g transform="matrix(.68 .395 -.68 .395 21 3)"><path d="m10.586 5.414-5.172 5.172m13.172 2.828-5.172 5.172M6 12h12"/><circle cx="12" cy="20" r="2"/><circle cx="12" cy="4" r="2"/><circle cx="20" cy="12" r="2"/><circle cx="4" cy="12" r="2"/></g><g transform="matrix(.68 .395 0 .71 4 13.5)"><path d="m10.586 5.414-5.172 5.172m13.172 2.828-5.172 5.172M6 12h12"/><circle cx="12" cy="20" r="2"/><circle cx="12" cy="4" r="2"/><circle cx="20" cy="12" r="2"/><circle cx="4" cy="12" r="2"/></g><g transform="matrix(.68 -.395 0 .71 22 23)"><path d="m10.586 5.414-5.172 5.172m13.172 2.828-5.172 5.172M6 12h12"/><circle cx="12" cy="20" r="2"/><circle cx="12" cy="4" r="2"/><circle cx="20" cy="12" r="2"/><circle cx="4" cy="12" r="2"/></g></g></svg>
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>RayTrace — Agent trace forensics</title>
|
|
7
7
|
<meta name="description" content="Evidence-backed traces and live counterfactual forks for coding agents." />
|
|
8
|
-
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
8
|
+
<link rel="icon" href="/favicon.svg?v=raytrace-box-1" type="image/svg+xml" />
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-DF_klLF4.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/assets/index-CM-3AX0c.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body class="antialiased">
|
|
13
13
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raytrace-cli/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "See what your coding agent did: traces, tool calls, cost and step-by-step evidence for Claude Code and Codex.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"src/",
|
|
13
13
|
"proxy/",
|
|
14
14
|
"worker/",
|
|
15
|
-
"dist/dashboard/"
|
|
15
|
+
"dist/dashboard/",
|
|
16
|
+
"THIRD_PARTY_NOTICES.md"
|
|
16
17
|
],
|
|
17
18
|
"engines": {
|
|
18
19
|
"node": ">=22.13.0"
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"class-variance-authority": "0.7.1",
|
|
38
39
|
"clsx": "2.1.1",
|
|
39
40
|
"lucide-react": "1.31.0",
|
|
41
|
+
"motion": "^14.14.0",
|
|
40
42
|
"react": "19.2.6",
|
|
41
43
|
"react-dom": "19.2.6",
|
|
42
44
|
"tailwind-merge": "3.6.0",
|
package/proxy/evidence-store.mjs
CHANGED
|
@@ -56,7 +56,11 @@ function previewOf(item) {
|
|
|
56
56
|
* Never upgrades missing evidence into an outcome. */
|
|
57
57
|
function processOutcome(row) {
|
|
58
58
|
if (!row?.process_id) return { status: null, error: null };
|
|
59
|
-
|
|
59
|
+
// A failure the collector inferred has no errno (gVisor reports none for a
|
|
60
|
+
// missing or non-executable program); one gVisor reported has.
|
|
61
|
+
if (!row.exec_ok && (row.failed_errno != null || row.exec_failed)) {
|
|
62
|
+
return { status: 'failed', error: `exec failed: ${row.failed_errno != null ? `errno ${row.failed_errno}` : 'no program started (errno not reported)'}` };
|
|
63
|
+
}
|
|
60
64
|
if (row.exited_at_ns != null) {
|
|
61
65
|
if (row.exit_signal) return { status: 'failed', error: `killed by signal ${row.exit_signal}` };
|
|
62
66
|
if (row.exit_code === 0) return { status: 'completed', error: null };
|
|
@@ -74,7 +78,8 @@ const PROCESS_FACTS = `
|
|
|
74
78
|
WHERE ev.process_id = p.id AND ev.event_kind IN ('exec_succeeded','exec_failed') ORDER BY ev.stream_sequence LIMIT 1) AS argv_json,
|
|
75
79
|
(SELECT json_extract(ev.payload_json, '$.errno') FROM runtime_events ev
|
|
76
80
|
WHERE ev.process_id = p.id AND ev.event_kind = 'exec_failed' ORDER BY ev.stream_sequence DESC LIMIT 1) AS failed_errno,
|
|
77
|
-
EXISTS (SELECT 1 FROM runtime_events ev WHERE ev.process_id = p.id AND ev.event_kind = 'exec_succeeded') AS exec_ok
|
|
81
|
+
EXISTS (SELECT 1 FROM runtime_events ev WHERE ev.process_id = p.id AND ev.event_kind = 'exec_succeeded') AS exec_ok,
|
|
82
|
+
EXISTS (SELECT 1 FROM runtime_events ev WHERE ev.process_id = p.id AND ev.event_kind = 'exec_failed') AS exec_failed`;
|
|
78
83
|
|
|
79
84
|
export function openEvidenceStore(file, { readOnly = false } = {}) {
|
|
80
85
|
let journal = 'wal';
|
|
@@ -242,6 +242,17 @@ test('a failed execve reads as exec failed on its process', () => withStore((sto
|
|
|
242
242
|
assert.deepEqual([child.status, child.error], ['failed', 'exec failed: errno 13']);
|
|
243
243
|
}));
|
|
244
244
|
|
|
245
|
+
test('a failed execve the collector inferred (no errno) still reads as exec failed', () => withStore((store) => {
|
|
246
|
+
const raw = { event_id: 1, kind: 'exec_failed', pid: 61, ppid: 1, argv: ['./missing'], errno: null, inferred: 'no program started after this exec attempt',
|
|
247
|
+
container_id: CONTAINER, process_start_ns: '10', timestamp_ns: '20' };
|
|
248
|
+
store.recordProcessStart({ containerId: CONTAINER, raw, startedMs: 1 });
|
|
249
|
+
captureDemo(store);
|
|
250
|
+
const [candidate] = store.candidatesInWindow(0, Number.MAX_SAFE_INTEGER, { sessionId: SESSION });
|
|
251
|
+
store.attribute({ toolCallId: candidate.call_id, eventId: `gvisor:${CONTAINER}:1`, method: 'inherited' });
|
|
252
|
+
const [child] = store.descendants(['e1']);
|
|
253
|
+
assert.deepEqual([child.status, child.error], ['failed', 'exec failed: no program started (errno not reported)']);
|
|
254
|
+
}));
|
|
255
|
+
|
|
245
256
|
test('auxiliary features round trip', () => withStore((store) => {
|
|
246
257
|
store.saveExperiment({ id: 'x1', created_at: new Date().toISOString(), status: 'completed', exchange_id: 'e1', model: 'm' });
|
|
247
258
|
assert.equal(store.loadExperiments()[0].id, 'x1');
|
|
@@ -135,7 +135,9 @@ export function toFailedExec(event, clock = UNMEASURED_CLOCK) {
|
|
|
135
135
|
timestamp: observed - clock.offsetMs,
|
|
136
136
|
start_time_ns: typeof event.process_start_ns === 'string' ? event.process_start_ns : null,
|
|
137
137
|
status: 'failed',
|
|
138
|
-
|
|
138
|
+
// The collector infers a failure gVisor reports no errno for (a missing or
|
|
139
|
+
// non-executable program): errno is null there, never 0.
|
|
140
|
+
error: `exec failed: ${event.errno != null && Number.isFinite(Number(event.errno)) ? `errno ${Number(event.errno)}` : 'no program started (errno not reported)'}`,
|
|
139
141
|
ended_at: at,
|
|
140
142
|
container_id: typeof event.container_id === 'string' ? event.container_id : null,
|
|
141
143
|
raw: event,
|
|
@@ -313,6 +313,8 @@ test('a failed execve under a matched command gets its own failed row instead of
|
|
|
313
313
|
assert.equal(descended[0].exec.ended_at, new Date(BASE + 5).toISOString());
|
|
314
314
|
assert.equal(tracker.live.has(101), false, 'nothing ran, so nothing is tracked');
|
|
315
315
|
assert.equal(toFailedExec({ ...failed, argv: [], executable: '' }), null);
|
|
316
|
+
// Inferred by the collector: gVisor gave no errno, and null must not read as errno 0.
|
|
317
|
+
assert.equal(toFailedExec({ ...failed, errno: null }).error, 'exec failed: no program started (errno not reported)');
|
|
316
318
|
});
|
|
317
319
|
|
|
318
320
|
test('an exit with no in-memory link (proxy restarted) is closed by pid + start time', async () => {
|
package/src/lima.mjs
CHANGED
|
@@ -107,7 +107,7 @@ export async function checks({ vmRunning = false, runInVm = null } = {}) {
|
|
|
107
107
|
const row = (ok, label, detail, fix) => rows.push({ ok, label, detail, fix });
|
|
108
108
|
const platform = process.platform;
|
|
109
109
|
|
|
110
|
-
if (platform === 'win32') row(null, 'platform', 'Windows: local sandboxes are experimental here (Lima on Windows is)');
|
|
110
|
+
if (platform === 'win32') row(null, 'platform', 'Windows: local sandboxes are experimental here (Lima on Windows is); the workable paths are WSL2 and cloud sandboxes: https://github.com/Godcreatebugs/raytrace-cli/blob/main/docs/windows.md');
|
|
111
111
|
else if (platform !== 'darwin' && platform !== 'linux') row(false, 'platform', `${platform} is not supported for local sandboxes`);
|
|
112
112
|
|
|
113
113
|
const lima = findLima();
|
|
@@ -115,7 +115,10 @@ export async function checks({ vmRunning = false, runInVm = null } = {}) {
|
|
|
115
115
|
else if (canDownload()) {
|
|
116
116
|
row(null, 'lima', `${lima?.old ? `${lima.old} is older than ${MINIMUM.join('.')}` : 'not installed'}; RayTrace downloads Lima ${LIMA_VERSION} on the first \`raytrace sandbox create --local\``);
|
|
117
117
|
} else {
|
|
118
|
-
row(false, 'lima', lima?.old ? `${lima.old} is older than ${MINIMUM.join('.')}` : 'not installed',
|
|
118
|
+
row(false, 'lima', lima?.old ? `${lima.old} is older than ${MINIMUM.join('.')}` : 'not installed',
|
|
119
|
+
platform === 'win32'
|
|
120
|
+
? 'Lima has no native Windows build and RayTrace does not download it there; use WSL2 or a cloud sandbox: https://github.com/Godcreatebugs/raytrace-cli/blob/main/docs/windows.md'
|
|
121
|
+
: 'install Lima: https://lima-vm.io/docs/installation/');
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
if (platform === 'darwin') {
|
|
@@ -87,7 +87,7 @@ infer them from the collector host.
|
|
|
87
87
|
| `capture` | Meaning | Rows |
|
|
88
88
|
| --- | --- | --- |
|
|
89
89
|
| `yes` | Its gVisor trace point is subscribed, with the optional fields in `capture_fields`. | `open`, `openat`, `creat`, `connect`, `listen`, `setuid`, `setgid`, `setresuid`, `setresgid` |
|
|
90
|
-
| `watcher` |
|
|
90
|
+
| `watcher` | Its raw points are subscribed: which process, when, and whether it was refused. Both of them, because gVisor fills the exit event's process and sandbox from the fields asked of the enter point; the enter event itself is discarded. gVisor does not decode its path, so the host's file watcher supplies the name. | `unlink`, `unlinkat`, `rmdir`, `rename`, `renameat`, `renameat2`, `truncate`, `ftruncate`, `mkdir`, `mkdirat`, `chmod`, `fchmod`, `fchmodat` |
|
|
91
91
|
| `sentry` | Seen through gVisor's own process points (clone, exec, exit), whatever syscall caused them. | `clone`, `clone3`, `fork`, `vfork`, `execve`, `execveat`, `exit`, `exit_group` |
|
|
92
92
|
| `no` | Not captured. | everything else |
|
|
93
93
|
|
|
@@ -150,7 +150,7 @@ outcome. A missing exit result is unknown, not success. Apply the row-specific
|
|
|
150
150
|
| `connect_effect` | Decode the address family, IP address and port. A zero result is a connection on a stream socket and only a default peer on a datagram socket. `EINPROGRESS` is an attempt whose outcome this call does not report. A destination in a range the sandbox firewall rejects is a refused attempt. The address is never a host name: a name shown beside it comes from DNS evidence and is a best match. No payload is captured. |
|
|
151
151
|
| `listen_effect` | Success means the process accepts connections on the bound address. Nothing outside the sandbox network is routed to it. |
|
|
152
152
|
| `identity_effect` | Record the requested IDs and the result. Success changes the identity the process acts as; the sandbox has no capabilities, so a successful change away from its one user is unexpected, and a failure is an attempt. |
|
|
153
|
-
| `process_lifecycle` | gVisor's clone, exec and exit points report every task, program start and exit, whichever syscall caused it. A successful exec proves a program started, not what it did; a zero result on the exec syscall point is not treated as success. Keep arguments as observed and, of the environment, only the two `RAYTRACE_` markers. |
|
|
153
|
+
| `process_lifecycle` | gVisor's clone, exec and exit points report every task, program start and exit, whichever syscall caused it. A successful exec proves a program started, not what it did; a zero result on the exec syscall point is not treated as success, since gVisor's execve returns 0 before it loads the program. A missing or non-executable program is therefore inferred: an attempt no program start follows, by the time the process tries other arguments or exits, is recorded as `exec_failed` with no errno (`collector.py` `ExecAttempts`). Keep arguments as observed and, of the environment, only the two `RAYTRACE_` markers. |
|
|
154
154
|
| `not_classified` | The call is listed and grouped, and nothing is collected for it. No fact records its use and none rules it out. |
|
|
155
155
|
|
|
156
156
|
For example, successful `unlinkat` can display **L3 · Delete · Succeeded**;
|
|
@@ -141,10 +141,9 @@ if (input.hook_event_name === 'PreToolUse') {
|
|
|
141
141
|
if (input.tool_name === 'Bash' && /^[A-Za-z0-9_-]{1,128}$/.test(id ?? '') && typeof command === 'string') {
|
|
142
142
|
// An input change needs a decision with it. Only a session that already
|
|
143
143
|
// skips permission prompts gets "allow"; any other still asks as usual,
|
|
144
|
-
// unless
|
|
145
|
-
|
|
146
|
-
const allowAll =
|
|
147
|
-
|| process.env.RAYTRACE_HEADLESS === '1' || process.env.HEADLESS === '1';
|
|
144
|
+
// unless RAYTRACE_ALLOW_ALL is set on purpose. Ambient variables (CI, GITHUB_ACTIONS, HEADLESS) are set by
|
|
145
|
+
// runners and wrappers without anyone choosing to skip the prompts, so they are not honoured.
|
|
146
|
+
const allowAll = process.env.RAYTRACE_ALLOW_ALL === '1' || process.env.RAYTRACE_ALLOW_ALL === 'true';
|
|
148
147
|
const isBypass = input.permission_mode === 'bypassPermissions' || input.permission_mode === 'dontAsk';
|
|
149
148
|
const decision = (isBypass || allowAll) ? 'allow' : 'ask';
|
|
150
149
|
process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: decision,
|
|
@@ -225,6 +225,69 @@ def with_raw(event, packet):
|
|
|
225
225
|
return event
|
|
226
226
|
|
|
227
227
|
|
|
228
|
+
class ExecAttempts:
|
|
229
|
+
"""Tells a failed exec from the events around it, one sandbox at a time.
|
|
230
|
+
|
|
231
|
+
gVisor never reports that an exec failed for want of a program. Its execve
|
|
232
|
+
returns 0 at once and loads the program afterwards (kernel/task_exec.go),
|
|
233
|
+
so the call's exit point says errno 0 whether the file was there or not,
|
|
234
|
+
and a missing or non-executable file only shows as what does not follow:
|
|
235
|
+
no `exec_succeeded` (sentry/execve) for that process. So an attempt is
|
|
236
|
+
held until the process says which it was:
|
|
237
|
+
|
|
238
|
+
exec_succeeded the attempt, and any before it with the same
|
|
239
|
+
arguments (a shell trying each folder of PATH), led
|
|
240
|
+
to a program: nothing failed
|
|
241
|
+
another attempt with other arguments: the held ones failed
|
|
242
|
+
process_exit the held ones failed
|
|
243
|
+
|
|
244
|
+
A failure found this way is an `exec_failed` event with no errno (gVisor
|
|
245
|
+
gave none) and `inferred` saying why. The folders of one PATH search are
|
|
246
|
+
one failure, listed in `tried`, not one each. An attempt still held when
|
|
247
|
+
the stream ends is dropped: nothing says how it went."""
|
|
248
|
+
LIMIT = 20_000
|
|
249
|
+
|
|
250
|
+
def __init__(self):
|
|
251
|
+
self.held = {} # pid -> [the attempts since its last program started]
|
|
252
|
+
|
|
253
|
+
def see(self, event):
|
|
254
|
+
"""The failed execs this event settles, as events to record."""
|
|
255
|
+
kind, pid = event.get('kind'), event.get('pid')
|
|
256
|
+
if kind == 'exec_attempt':
|
|
257
|
+
held = self.held.get(pid)
|
|
258
|
+
failed = self.failures(self.held.pop(pid)) if held and held[-1].get('argv') != event.get('argv') else []
|
|
259
|
+
if len(self.held) >= self.LIMIT: # exits that never arrived
|
|
260
|
+
self.held.clear()
|
|
261
|
+
self.held.setdefault(pid, []).append(event)
|
|
262
|
+
return failed
|
|
263
|
+
if kind == 'exec_failed':
|
|
264
|
+
# gVisor did report this one (a bad pointer, a path too long): it is recorded as it came.
|
|
265
|
+
held = self.held.get(pid)
|
|
266
|
+
if held:
|
|
267
|
+
held.pop()
|
|
268
|
+
if not held:
|
|
269
|
+
del self.held[pid]
|
|
270
|
+
return []
|
|
271
|
+
if kind == 'exec_succeeded':
|
|
272
|
+
self.held.pop(pid, None)
|
|
273
|
+
return []
|
|
274
|
+
if kind == 'process_exit':
|
|
275
|
+
return self.failures(self.held.pop(pid, []))
|
|
276
|
+
return []
|
|
277
|
+
|
|
278
|
+
@staticmethod
|
|
279
|
+
def failures(attempts):
|
|
280
|
+
found = []
|
|
281
|
+
for attempt in attempts:
|
|
282
|
+
if found and found[-1].get('argv') == attempt.get('argv'):
|
|
283
|
+
if len(found[-1]['tried']) < 32:
|
|
284
|
+
found[-1]['tried'].append(attempt.get('executable'))
|
|
285
|
+
continue
|
|
286
|
+
found.append({**attempt, 'kind': 'exec_failed', 'errno': None, 'tried': [attempt.get('executable')],
|
|
287
|
+
'inferred': 'no program started after this exec attempt; gVisor reports no errno for it'})
|
|
288
|
+
return found
|
|
289
|
+
|
|
290
|
+
|
|
228
291
|
def init_db(path):
|
|
229
292
|
db = sqlite3.connect(path, timeout=10)
|
|
230
293
|
db.execute('PRAGMA journal_mode=WAL')
|
|
@@ -291,8 +354,41 @@ class Writer(threading.Thread):
|
|
|
291
354
|
if wrote_heartbeat:
|
|
292
355
|
self.last_heartbeat = now
|
|
293
356
|
|
|
357
|
+
def close_orphaned_streams(self, db):
|
|
358
|
+
"""Ends the streams an earlier collector left open, at their last heartbeat.
|
|
359
|
+
|
|
360
|
+
A connection records its own collector_disconnected when gVisor closes
|
|
361
|
+
it, but that runs on a daemon thread: when the collector itself stops
|
|
362
|
+
(a restart, an update, a crash) nothing is written, and the stream looks
|
|
363
|
+
open forever. gVisor does not reconnect a running sandbox to the new
|
|
364
|
+
collector, so recording has stopped until that sandbox restarts. Record
|
|
365
|
+
the cut-out in the earlier collector's name, at the last moment it was
|
|
366
|
+
known to be alive. Only safe once this collector holds the socket, so no
|
|
367
|
+
other collector can still be writing. Returns the streams it closed."""
|
|
368
|
+
with db:
|
|
369
|
+
orphans = db.execute('SELECT id, collector_id, container_id, heartbeat_ms FROM capture_streams '
|
|
370
|
+
'WHERE ended_ms IS NULL AND collector_id <> ?', (self.instance_id,)).fetchall()
|
|
371
|
+
for connection, collector, container, heartbeat in orphans:
|
|
372
|
+
db.execute('UPDATE capture_streams SET ended_ms=? WHERE id=?', (heartbeat, connection))
|
|
373
|
+
if not container:
|
|
374
|
+
continue # no event ever named its sandbox: nothing to tell a consumer
|
|
375
|
+
gone = {'kind': 'collector_disconnected', 'container_id': container, 'coverage': 'not_certified',
|
|
376
|
+
'reason': 'collector stopped', 'source_instance_id': collector,
|
|
377
|
+
'source_connection_id': connection, 'received_ms': heartbeat}
|
|
378
|
+
db.execute('INSERT INTO runtime_events(connection,received_ms,container_id,kind,body) VALUES(?,?,?,?,?)',
|
|
379
|
+
(connection, heartbeat, container, 'collector_disconnected', json.dumps(gone)))
|
|
380
|
+
return [row[0] for row in orphans]
|
|
381
|
+
|
|
294
382
|
def run(self):
|
|
295
383
|
db = init_db(self.database)
|
|
384
|
+
while True:
|
|
385
|
+
try:
|
|
386
|
+
for connection in self.close_orphaned_streams(db):
|
|
387
|
+
print(f'RayTrace collector: stream {connection} was left open by a stopped collector; ended it at its last heartbeat', flush=True)
|
|
388
|
+
break
|
|
389
|
+
except sqlite3.Error as error:
|
|
390
|
+
print(f'RayTrace collector: earlier streams not closed ({error}); retrying', flush=True)
|
|
391
|
+
time.sleep(1)
|
|
296
392
|
while True:
|
|
297
393
|
try:
|
|
298
394
|
batch = [self.rows.get(timeout=5)]
|
|
@@ -353,6 +449,7 @@ def serve(endpoint, database):
|
|
|
353
449
|
record({'kind': 'collector_connected', 'source': 'collector'})
|
|
354
450
|
previous_dropped = 0
|
|
355
451
|
previous_received = int(time.time()*1000)
|
|
452
|
+
attempts = ExecAttempts()
|
|
356
453
|
while True:
|
|
357
454
|
packet, _, flags, _ = conn.recvmsg(MAX_PACKET)
|
|
358
455
|
if not packet:
|
|
@@ -369,6 +466,8 @@ def serve(endpoint, database):
|
|
|
369
466
|
taken(gap)
|
|
370
467
|
previous_dropped = event['dropped_count']
|
|
371
468
|
previous_received = int(time.time()*1000)
|
|
469
|
+
for failed in attempts.see(event):
|
|
470
|
+
record(failed)
|
|
372
471
|
if not taken(event):
|
|
373
472
|
record(with_raw(event, packet))
|
|
374
473
|
except Exception as error:
|
package/worker/sandbox/engine.py
CHANGED
|
@@ -356,6 +356,8 @@ class Engine(threading.Thread):
|
|
|
356
356
|
try:
|
|
357
357
|
kind = event.get('kind')
|
|
358
358
|
own = kind in OWN_KINDS or (kind in ('syscall_return', 'syscall_enter') and event.get('sysno') in self.numbered)
|
|
359
|
+
if own and kind == 'syscall_enter':
|
|
360
|
+
return True # subscribed only so that its exit names the process (setup.py): nothing to keep
|
|
359
361
|
if own or kind in PROCESS_KINDS:
|
|
360
362
|
try:
|
|
361
363
|
self.inbox.put_nowait(event)
|
package/worker/sandbox/setup.py
CHANGED
|
@@ -73,6 +73,15 @@ def trace_config(arch, catalog_sql, endpoint, calls=True):
|
|
|
73
73
|
fields = [field for field in json.loads(wanted) if field in json.loads(offered or '[]')] if capture == 'yes' else []
|
|
74
74
|
if fields:
|
|
75
75
|
entry['optional_fields'] = fields
|
|
76
|
+
if capture == 'watcher':
|
|
77
|
+
# gVisor fills a raw exit event's context (which sandbox, which
|
|
78
|
+
# process, when) from the fields asked of the same call's raw
|
|
79
|
+
# ENTER point (kernel/task_syscall.go: the exit path reads
|
|
80
|
+
# SyscallRawEnter's field set). With only the exit subscribed the
|
|
81
|
+
# event names nobody, and the engine cannot say who deleted or
|
|
82
|
+
# renamed a file. So the enter point is subscribed with the same
|
|
83
|
+
# fields; the collector reads its exit and discards the enter.
|
|
84
|
+
configured.append({'name': f'syscall/sysno/{number[name]}/enter', 'context_fields': entry['context_fields']})
|
|
76
85
|
configured.append(entry)
|
|
77
86
|
# gVisor never waits long for the collector: when its socket is full it
|
|
78
87
|
# tries again a few times, each wait twice the last (25 microseconds at
|
|
@@ -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()
|