aletheia-firewall 0.3.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/.helios-baseline +1 -0
- package/LICENSE +21 -0
- package/README.md +129 -0
- package/index.js +383 -0
- package/package.json +36 -0
- package/src/aho-corasick.js +101 -0
- package/src/audit-log.js +102 -0
- package/src/behavior-tracker.js +455 -0
- package/src/detector.js +245 -0
- package/src/policy-watcher.js +233 -0
- package/src/policy.js +83 -0
- package/src/quarantine.js +123 -0
- package/sync-worker.js +87 -0
package/sync-worker.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// packages/fw-agent/sync-worker.js
|
|
2
|
+
// Telemetry worker thread: batches events and forwards them to the control plane.
|
|
3
|
+
// Supports graceful shutdown via TERMINATE message.
|
|
4
|
+
|
|
5
|
+
const { parentPort } = require('worker_threads');
|
|
6
|
+
const http = require('http');
|
|
7
|
+
|
|
8
|
+
let eventBuffer = [];
|
|
9
|
+
const FLUSH_INTERVAL_MS = 1000;
|
|
10
|
+
let flushTimer = null;
|
|
11
|
+
let terminating = false;
|
|
12
|
+
|
|
13
|
+
const agentId = `agent_${Math.random().toString(36).substring(2, 11)}`;
|
|
14
|
+
|
|
15
|
+
function flushEvents(callback) {
|
|
16
|
+
if (eventBuffer.length === 0) {
|
|
17
|
+
if (callback) callback();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const batch = [...eventBuffer];
|
|
22
|
+
eventBuffer = [];
|
|
23
|
+
if (flushTimer) {
|
|
24
|
+
clearTimeout(flushTimer);
|
|
25
|
+
flushTimer = null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const payload = JSON.stringify({ agentId, events: batch, schemaVersion: 1 });
|
|
29
|
+
|
|
30
|
+
const options = {
|
|
31
|
+
hostname: 'localhost',
|
|
32
|
+
port: process.env.FW_CONTROL_PORT || 3000,
|
|
33
|
+
path: '/v1/telemetry',
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
'Content-Length': Buffer.byteLength(payload),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// F-19: Send bearer token when FW_TELEMETRY_TOKEN is set (opt-in, backward-compatible).
|
|
42
|
+
if (process.env.FW_TELEMETRY_TOKEN) {
|
|
43
|
+
options.headers['Authorization'] = `Bearer ${process.env.FW_TELEMETRY_TOKEN}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const req = http.request(options, (res) => {
|
|
47
|
+
res.resume();
|
|
48
|
+
if (callback) callback();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
req.on('error', () => {
|
|
52
|
+
// Fail-open: swallow network errors silently; never friction the host app
|
|
53
|
+
if (callback) callback();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
req.setTimeout(3000, () => {
|
|
57
|
+
req.destroy();
|
|
58
|
+
if (callback) callback();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
req.write(payload);
|
|
62
|
+
req.end();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
parentPort.on('message', (message) => {
|
|
66
|
+
if (message.type === 'TELEMETRY_EVENT') {
|
|
67
|
+
if (terminating) return;
|
|
68
|
+
eventBuffer.push(message.payload);
|
|
69
|
+
if (!flushTimer) {
|
|
70
|
+
flushTimer = setTimeout(flushEvents, FLUSH_INTERVAL_MS);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (message.type === 'FORCE_FLUSH') {
|
|
75
|
+
if (flushTimer) clearTimeout(flushTimer);
|
|
76
|
+
flushEvents();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (message.type === 'TERMINATE') {
|
|
80
|
+
terminating = true;
|
|
81
|
+
if (flushTimer) clearTimeout(flushTimer);
|
|
82
|
+
flushEvents(() => {
|
|
83
|
+
parentPort.postMessage({ type: 'TERMINATED' });
|
|
84
|
+
process.exit(0);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|