@mandateops/cli-linux-x64 0.0.0-stage → 0.7.1
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/LICENSE +55 -0
- package/README.md +175 -2
- package/audit-lab/README.md +194 -0
- package/audit-lab/bin/mandateops +0 -0
- package/audit-lab/contracts/contact-plain-text.vectors.json +85 -0
- package/audit-lab/contracts/history-reading.md +185 -0
- package/audit-lab/contracts/history-reading.vectors.json +284 -0
- package/audit-lab/contracts/profiles.md +161 -0
- package/audit-lab/contracts/properties.md +512 -0
- package/audit-lab/contracts/sdk-config.md +155 -0
- package/audit-lab/contracts/system-under-test.md +385 -0
- package/audit-lab/contracts/test-provider.md +350 -0
- package/audit-lab/lab/compose.audit.yml +181 -0
- package/audit-lab/lab/config/fault-control.json +14 -0
- package/audit-lab/lab/examples/agents/Dockerfile +28 -0
- package/audit-lab/lab/examples/agents/codeloc.cjs +199 -0
- package/audit-lab/lab/examples/agents/load.cjs +9 -0
- package/audit-lab/lab/examples/agents/package-lock.json +2840 -0
- package/audit-lab/lab/examples/agents/package.json +9 -0
- package/audit-lab/lab/examples/agents/python/mandateops_codeloc.py +271 -0
- package/audit-lab/lab/examples/agents/python/sitecustomize.py +51 -0
- package/audit-lab/lab/examples/agents/requirements-python.txt +522 -0
- package/audit-lab/lab/examples/agents/telemetry-router.cjs +272 -0
- package/audit-lab/lab/examples/test-provider/.dockerignore +4 -0
- package/audit-lab/lab/examples/test-provider/Dockerfile +28 -0
- package/audit-lab/lab/examples/test-provider/bun.lock +405 -0
- package/audit-lab/lab/examples/test-provider/package.json +42 -0
- package/audit-lab/lab/examples/test-provider/src/amount.ts +32 -0
- package/audit-lab/lab/examples/test-provider/src/app.ts +538 -0
- package/audit-lab/lab/examples/test-provider/src/auth.ts +30 -0
- package/audit-lab/lab/examples/test-provider/src/barrier.ts +262 -0
- package/audit-lab/lab/examples/test-provider/src/codeloc.ts +27 -0
- package/audit-lab/lab/examples/test-provider/src/config.ts +311 -0
- package/audit-lab/lab/examples/test-provider/src/connect.ts +204 -0
- package/audit-lab/lab/examples/test-provider/src/declaration.ts +270 -0
- package/audit-lab/lab/examples/test-provider/src/declared.ts +198 -0
- package/audit-lab/lab/examples/test-provider/src/domain.ts +193 -0
- package/audit-lab/lab/examples/test-provider/src/egress.ts +396 -0
- package/audit-lab/lab/examples/test-provider/src/flow.ts +263 -0
- package/audit-lab/lab/examples/test-provider/src/gate.ts +301 -0
- package/audit-lab/lab/examples/test-provider/src/main.ts +31 -0
- package/audit-lab/lab/examples/test-provider/src/notify.ts +157 -0
- package/audit-lab/lab/examples/test-provider/src/owner.ts +60 -0
- package/audit-lab/lab/examples/test-provider/src/payment.ts +103 -0
- package/audit-lab/lab/examples/test-provider/src/profile.ts +417 -0
- package/audit-lab/lab/examples/test-provider/src/request.ts +201 -0
- package/audit-lab/lab/examples/test-provider/src/rows.ts +173 -0
- package/audit-lab/lab/examples/test-provider/src/schema.ts +114 -0
- package/audit-lab/lab/examples/test-provider/src/signature.ts +86 -0
- package/audit-lab/lab/examples/test-provider/src/staged.ts +318 -0
- package/audit-lab/lab/examples/test-provider/src/store.ts +432 -0
- package/audit-lab/lab/examples/test-provider/src/traffic.ts +50 -0
- package/audit-lab/lab/examples/test-provider/src/webauthn.d.ts +11 -0
- package/audit-lab/lab/examples/test-provider/src/wire.ts +153 -0
- package/audit-lab/lab/examples/test-provider/tsconfig.build.json +9 -0
- package/audit-lab/lab/examples/test-provider/tsconfig.json +24 -0
- package/audit-lab/lab/images/capture/Dockerfile +15 -0
- package/audit-lab/lab/images/capture/LICENSE +201 -0
- package/audit-lab/lab/images/fault-control/Dockerfile +13 -0
- package/audit-lab/lab/images/fault-control/LICENSE +21 -0
- package/audit-lab/lab/images/provider-store/Dockerfile +4 -0
- package/audit-lab/lab/images/provider-store/LICENSE +23 -0
- package/audit-lab/lab/images/telemetry/Dockerfile +14 -0
- package/audit-lab/lab/images/telemetry/LICENSE +201 -0
- package/audit-lab/lab/scripts/compose-down.sh +143 -0
- package/audit-lab/lab/scripts/compose-lib.sh +632 -0
- package/audit-lab/lab/scripts/compose-up.sh +240 -0
- package/package.json +16 -4
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Code locations for calls to the provider. Loaded before a Node or Bun
|
|
2
|
+
// backend's own code (NODE_OPTIONS=--require, BUN_OPTIONS=--preload) in a lab
|
|
3
|
+
// run or under `mandateops run`. For each request to the provider's address,
|
|
4
|
+
// and no other, it:
|
|
5
|
+
// - adds one header, x-mandateops-call, carrying a random id, so the
|
|
6
|
+
// provider's side of the call is matched by that id and never guessed;
|
|
7
|
+
// - writes one line with that id and the stack frames in the project's own
|
|
8
|
+
// code, as paths relative to the project root.
|
|
9
|
+
// It never reads, changes or logs a body, a header value or a URL path, makes
|
|
10
|
+
// no network call of its own, and never stops the backend: any failure leaves
|
|
11
|
+
// the request as it was. It has no dependencies.
|
|
12
|
+
"use strict";
|
|
13
|
+
|
|
14
|
+
const HEADER = "x-mandateops-call";
|
|
15
|
+
const LINE_PREFIX = "mandateops-codeloc ";
|
|
16
|
+
const MAX_FRAMES = 8;
|
|
17
|
+
const MAX_FUNCTION = 120;
|
|
18
|
+
const MAX_PATH = 300;
|
|
19
|
+
|
|
20
|
+
/** `host:port` pairs, lower-cased; ports default by scheme. */
|
|
21
|
+
function parseOrigins(value) {
|
|
22
|
+
const origins = new Set();
|
|
23
|
+
for (const entry of String(value ?? "").split(",")) {
|
|
24
|
+
const trimmed = entry.trim().toLowerCase();
|
|
25
|
+
if (!trimmed) continue;
|
|
26
|
+
try {
|
|
27
|
+
const url = new URL(trimmed.includes("://") ? trimmed : `http://${trimmed}`);
|
|
28
|
+
origins.add(`${url.hostname}:${url.port || defaultPort(url.protocol)}`);
|
|
29
|
+
} catch {
|
|
30
|
+
// An unreadable entry watches nothing.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return origins;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function defaultPort(protocol) {
|
|
37
|
+
return protocol === "https:" ? "443" : "80";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The `host:port` a URL names, or null. */
|
|
41
|
+
function originOf(target) {
|
|
42
|
+
try {
|
|
43
|
+
const url = target instanceof URL ? target : new URL(String(target));
|
|
44
|
+
return `${url.hostname.toLowerCase()}:${url.port || defaultPort(url.protocol)}`;
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The `host:port` of `http.request`'s arguments, or null. */
|
|
51
|
+
function originOfRequestArgs(args, protocol) {
|
|
52
|
+
const [first, second] = args;
|
|
53
|
+
if (typeof first === "string" || first instanceof URL) return originOf(first);
|
|
54
|
+
const options = first && typeof first === "object" ? first : second;
|
|
55
|
+
if (!options || typeof options !== "object") return null;
|
|
56
|
+
const host = String(options.hostname ?? options.host ?? "localhost")
|
|
57
|
+
.replace(/:\d+$/, "")
|
|
58
|
+
.toLowerCase();
|
|
59
|
+
const port = options.port ?? options.defaultPort ?? defaultPort(protocol);
|
|
60
|
+
return `${host}:${String(port)}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A frame's path relative to `root`, or null when it is not project code. */
|
|
64
|
+
function projectPath(file, root, self) {
|
|
65
|
+
let path = String(file);
|
|
66
|
+
if (path.startsWith("file://")) {
|
|
67
|
+
try {
|
|
68
|
+
path = decodeURIComponent(new URL(path).pathname);
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!path.startsWith("/") || path === self) return null;
|
|
74
|
+
if (path.includes("/node_modules/") || path.includes("/mandateops-tools/")) return null;
|
|
75
|
+
const base = root.endsWith("/") ? root : `${root}/`;
|
|
76
|
+
if (!path.startsWith(base)) return null;
|
|
77
|
+
const relative = path.slice(base.length);
|
|
78
|
+
if (!relative || relative.length > MAX_PATH) return null;
|
|
79
|
+
if (relative.split("/").some((part) => part === ".." || part === "")) return null;
|
|
80
|
+
return relative;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const FRAME = /^\s*at (?:(.+?) \()?(.+?):(\d+):\d+\)?$/;
|
|
84
|
+
|
|
85
|
+
/** The project's own frames of a V8 or JavaScriptCore stack, newest first. */
|
|
86
|
+
function projectFrames(stack, root, self) {
|
|
87
|
+
const frames = [];
|
|
88
|
+
for (const line of String(stack ?? "").split("\n")) {
|
|
89
|
+
const match = FRAME.exec(line);
|
|
90
|
+
if (!match) continue;
|
|
91
|
+
const [, name, file, lineNumber] = match;
|
|
92
|
+
if (file.startsWith("node:") || file.startsWith("internal/")) continue;
|
|
93
|
+
const path = projectPath(file, root, self);
|
|
94
|
+
if (!path) continue;
|
|
95
|
+
const at = Number(lineNumber);
|
|
96
|
+
if (!Number.isSafeInteger(at) || at < 1) continue;
|
|
97
|
+
const functionName = (name ?? "")
|
|
98
|
+
.replace(/^async /, "")
|
|
99
|
+
.replace(/[^\w.$<>\- ]/g, "")
|
|
100
|
+
.slice(0, MAX_FUNCTION);
|
|
101
|
+
frames.push(functionName ? { file: path, line: at, function: functionName } : { file: path, line: at });
|
|
102
|
+
if (frames.length >= MAX_FRAMES) break;
|
|
103
|
+
}
|
|
104
|
+
return frames;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function install(env, runtime) {
|
|
108
|
+
const origins = parseOrigins(env.MANDATEOPS_PROVIDER_ORIGINS);
|
|
109
|
+
if (origins.size === 0) return false;
|
|
110
|
+
const crypto = require("node:crypto");
|
|
111
|
+
const fs = require("node:fs");
|
|
112
|
+
const root = String(env.MANDATEOPS_PROJECT_ROOT || process.cwd()).replace(/\/+$/, "");
|
|
113
|
+
const self = __filename;
|
|
114
|
+
const file = env.MANDATEOPS_CODELOC_FILE;
|
|
115
|
+
const write = (record) => {
|
|
116
|
+
try {
|
|
117
|
+
const line = `${JSON.stringify(record)}\n`;
|
|
118
|
+
if (file) fs.appendFileSync(file, line, { mode: 0o600 });
|
|
119
|
+
else process.stderr.write(`${LINE_PREFIX}${line}`);
|
|
120
|
+
} catch {
|
|
121
|
+
// Never stop the backend for a location.
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const record = (method) => {
|
|
125
|
+
const id = crypto.randomUUID();
|
|
126
|
+
const holder = {};
|
|
127
|
+
Error.captureStackTrace(holder, record);
|
|
128
|
+
write({
|
|
129
|
+
call: id,
|
|
130
|
+
runtime,
|
|
131
|
+
method: String(method || "GET").toUpperCase().slice(0, 10),
|
|
132
|
+
frames: projectFrames(holder.stack, root, self),
|
|
133
|
+
});
|
|
134
|
+
return id;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const originalFetch = globalThis.fetch;
|
|
138
|
+
if (typeof originalFetch === "function") {
|
|
139
|
+
globalThis.fetch = function fetch(input, init) {
|
|
140
|
+
try {
|
|
141
|
+
const url = input instanceof Request ? input.url : input;
|
|
142
|
+
if (origins.has(originOf(url))) {
|
|
143
|
+
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
|
|
144
|
+
if (!headers.has(HEADER)) {
|
|
145
|
+
const method = init?.method ?? (input instanceof Request ? input.method : "GET");
|
|
146
|
+
headers.set(HEADER, record(method));
|
|
147
|
+
return originalFetch.call(this, input, { ...init, headers });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} catch {
|
|
151
|
+
// Fall through to the untouched call.
|
|
152
|
+
}
|
|
153
|
+
return originalFetch.call(this, input, init);
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
for (const [name, protocol] of [
|
|
158
|
+
["node:http", "http:"],
|
|
159
|
+
["node:https", "https:"],
|
|
160
|
+
]) {
|
|
161
|
+
const module = require(name);
|
|
162
|
+
const originalRequest = module.request;
|
|
163
|
+
const request = function request(...args) {
|
|
164
|
+
const outgoing = originalRequest.apply(this, args);
|
|
165
|
+
try {
|
|
166
|
+
if (origins.has(originOfRequestArgs(args, protocol)) && !outgoing.getHeader(HEADER)) {
|
|
167
|
+
outgoing.setHeader(HEADER, record(outgoing.method));
|
|
168
|
+
}
|
|
169
|
+
} catch {
|
|
170
|
+
// Headers already sent, or a request we cannot read: leave it.
|
|
171
|
+
}
|
|
172
|
+
return outgoing;
|
|
173
|
+
};
|
|
174
|
+
module.request = request;
|
|
175
|
+
// `get` calls the module's own `request`, not the export, so it is
|
|
176
|
+
// wrapped too, with get's one difference: the request is ended.
|
|
177
|
+
module.get = function get(...args) {
|
|
178
|
+
const outgoing = request.apply(this, args);
|
|
179
|
+
outgoing.end();
|
|
180
|
+
return outgoing;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
module.exports = { HEADER, LINE_PREFIX, parseOrigins, originOf, originOfRequestArgs, projectPath, projectFrames, install };
|
|
187
|
+
|
|
188
|
+
if (require.main !== module && !globalThis.__mandateopsCodeLocations) {
|
|
189
|
+
globalThis.__mandateopsCodeLocations = true;
|
|
190
|
+
try {
|
|
191
|
+
install(process.env, typeof Bun === "undefined" ? "node" : "bun");
|
|
192
|
+
} catch (error) {
|
|
193
|
+
try {
|
|
194
|
+
process.stderr.write(`mandateops: code locations not loaded: ${error && error.message}\n`);
|
|
195
|
+
} catch {
|
|
196
|
+
// Nothing more to do.
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Loaded by NODE_OPTIONS in every Node service of a lab run. Telemetry must
|
|
2
|
+
// never stop a backend, so a failure to load the agent is reported and ignored.
|
|
3
|
+
// Code locations first: they need no package and must not wait on the agent.
|
|
4
|
+
require("./codeloc.cjs");
|
|
5
|
+
try {
|
|
6
|
+
require("./node_modules/@opentelemetry/auto-instrumentations-node/dist/register.cjs");
|
|
7
|
+
} catch (error) {
|
|
8
|
+
console.warn(`mandateops: OpenTelemetry agent not loaded: ${error && error.message}`);
|
|
9
|
+
}
|