vyomi-tunnel 1.2.3 → 1.2.4
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/bin/credentials.mjs +1 -1
- package/bin/creds-sync.mjs +1 -1
- package/bin/mesh-cli.mjs +31 -9
- package/bin/vyomi-tunnel.mjs +25 -3
- package/package.json +1 -1
package/bin/credentials.mjs
CHANGED
|
@@ -48,7 +48,7 @@ const friendly = (portal) => ({
|
|
|
48
48
|
Throttled: "too many requests; wait a moment and retry.",
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
export async function fetchSession({ creds, fetchFn = globalThis.fetch, now = () => new Date(), version = "1.2.
|
|
51
|
+
export async function fetchSession({ creds, fetchFn = globalThis.fetch, now = () => new Date(), version = "1.2.4" }) {
|
|
52
52
|
const path = "/api/tunnel/session", body = JSON.stringify({ client: "vyomi-tunnel/" + version });
|
|
53
53
|
const date = now().toISOString().replace(/\.\d+Z$/, "Z");
|
|
54
54
|
let r;
|
package/bin/creds-sync.mjs
CHANGED
|
@@ -16,7 +16,7 @@ export const ALLOWED_ORIGINS = [/^https:\/\/(www\.)?vyomi\.cloud$/, /^https?:\/\
|
|
|
16
16
|
export const originAllowed = (origin) => !origin || ALLOWED_ORIGINS.some((re) => re.test(origin));
|
|
17
17
|
export const hostIsLoopback = (host) => /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/i.test(String(host || ""));
|
|
18
18
|
|
|
19
|
-
export function createCredsSync({ env = process.env, fetchFn = globalThis.fetch, version = "1.2.
|
|
19
|
+
export function createCredsSync({ env = process.env, fetchFn = globalThis.fetch, version = "1.2.4", log = () => {}, intervalMs = 300000, now = () => Date.now() } = {}) {
|
|
20
20
|
const home = env.VYOMI_HOME || join(homedir(), ".vyomi");
|
|
21
21
|
const file = env.VYOMI_CREDENTIALS_FILE || join(home, "credentials");
|
|
22
22
|
let st = { state: "unknown", key_id: "", portal: "", checked_at: 0, error: "" };
|
package/bin/mesh-cli.mjs
CHANGED
|
@@ -113,6 +113,26 @@ export function forward(target, { local, remote, relay, token, WS, allowPrivileg
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
export const INSTANCE_KEY = path.join(HOME, "mesh-instance-key");
|
|
117
|
+
const KEY_CMD = "docker exec vyomi-mesh-simulator-1 cat /root/.vyomi/instance-keys/id_ed25519";
|
|
118
|
+
|
|
119
|
+
/** Each Mesh makes its own VM login key. Fetch it from the Mesh on the first `connect` of a Codespace (and after a new Mesh), so
|
|
120
|
+
* `ssh <instance>.vyomi` needs no manual step. Best effort: a failure leaves ssh to report its usual error. Returns true when it wrote the key. */
|
|
121
|
+
export async function ensureInstanceKey(transport, codespace, { home = HOME, keyFile = path.join(home, "mesh-instance-key") } = {}) {
|
|
122
|
+
const mark = path.join(home, "instance_key_codespace");
|
|
123
|
+
let have = ""; try { have = fs.readFileSync(mark, "utf8").trim(); } catch { /* none yet */ }
|
|
124
|
+
if (codespace && have === codespace && fs.existsSync(keyFile)) return false;
|
|
125
|
+
try {
|
|
126
|
+
const pem = String(await transport.exec(KEY_CMD) || "").trim();
|
|
127
|
+
if (!/^-----BEGIN [A-Z ]*PRIVATE KEY-----/.test(pem) || !/-----END [A-Z ]*PRIVATE KEY-----$/.test(pem)) return false;
|
|
128
|
+
fs.mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
129
|
+
fs.writeFileSync(keyFile, pem + "\n", { mode: 0o600 });
|
|
130
|
+
fs.chmodSync(keyFile, 0o600);
|
|
131
|
+
if (codespace) fs.writeFileSync(mark, codespace + "\n", { mode: 0o600 });
|
|
132
|
+
return true;
|
|
133
|
+
} catch { return false; }
|
|
134
|
+
}
|
|
135
|
+
|
|
116
136
|
/** Every Mesh start creates a NEW Codespace, so the ssh host key behind `host.vyomi` changes each time and the key pinned in ~/.vyomi/known_hosts
|
|
117
137
|
* from the last one makes ssh refuse with "REMOTE HOST IDENTIFICATION HAS CHANGED". Host-key checking stays ON: when the Codespace differs from
|
|
118
138
|
* the last one seen, forget the old pins (this file is ours and only holds *.vyomi keys); a new Codespace is then trusted on first use and pinned
|
|
@@ -140,6 +160,10 @@ export async function configureSsh({ yes = false, cmd = "vyomi-tunnel", sshDir =
|
|
|
140
160
|
" IdentitiesOnly yes",
|
|
141
161
|
"",
|
|
142
162
|
`Host *${SUFFIX}`,
|
|
163
|
+
// Mesh VMs: the login user and the per-Mesh VM key (fetched by `connect`, see ensureInstanceKey), so plain `ssh <instance>.vyomi` works.
|
|
164
|
+
" User ubuntu",
|
|
165
|
+
` IdentityFile ${INSTANCE_KEY}`,
|
|
166
|
+
" IdentitiesOnly yes",
|
|
143
167
|
` ProxyCommand ${cmd} connect %h`,
|
|
144
168
|
" ServerAliveInterval 30",
|
|
145
169
|
" ServerAliveCountMax 4",
|
|
@@ -260,14 +284,11 @@ A type alone works too: vyomi-tunnel list vm`,
|
|
|
260
284
|
vyomi-tunnel list mesh
|
|
261
285
|
2. Once, add the *.vyomi names to your SSH config:
|
|
262
286
|
vyomi-tunnel config
|
|
263
|
-
3.
|
|
264
|
-
ssh
|
|
265
|
-
chmod 600 ~/.vyomi/mesh-instance-key
|
|
266
|
-
4. Log in as 'ubuntu' with that key (use the instance id from step 1):
|
|
267
|
-
ssh -i ~/.vyomi/mesh-instance-key -o IdentitiesOnly=yes ubuntu@i-0123456789ab.vyomi
|
|
287
|
+
3. Log in (use the instance id from step 1). The tunnel fetches this Mesh's VM key by itself the first time:
|
|
288
|
+
ssh i-0123456789ab.vyomi
|
|
268
289
|
|
|
269
|
-
|
|
270
|
-
|
|
290
|
+
Each Mesh makes its own VM key; the tunnel renews it when you start a new Mesh (saved as ~/.vyomi/mesh-instance-key).
|
|
291
|
+
If you set up SSH before this version, run 'vyomi-tunnel config' once to refresh the SSH settings. Problems: 'vyomi-tunnel help troubleshoot'.`,
|
|
271
292
|
troubleshoot: `Common problems
|
|
272
293
|
|
|
273
294
|
the portal refused the request (HTTP 405)
|
|
@@ -315,7 +336,7 @@ export async function main(argv) {
|
|
|
315
336
|
if (!cmd || ["help", "-h", "--help", "-help", "-?"].includes(cmd) || rest.some((a) => ["-h", "--help", "-help"].includes(a))) { const topic = cmd === "help" ? rest[0] : (["-h", "--help", "-help", "-?"].includes(cmd) ? undefined : cmd); const t = topic && DETAILS[topic];
|
|
316
337
|
if (topic && !t) { console.error(`vyomi-tunnel: no help for "${topic}".`); process.stdout.write(HELP); return 2; }
|
|
317
338
|
process.stdout.write((t || HELP) + (t ? "\n" : "")); return cmd ? 0 : 2; }
|
|
318
|
-
if (cmd === "--version" || cmd === "-v" || cmd === "version") { console.log(process.env.VYOMI_TUNNEL_VERSION || "vyomi-tunnel 1.2.
|
|
339
|
+
if (cmd === "--version" || cmd === "-v" || cmd === "version") { console.log(process.env.VYOMI_TUNNEL_VERSION || "vyomi-tunnel 1.2.4"); return 0; }
|
|
319
340
|
const WS = createRequire(import.meta.url)(process.env.WS_PKG || "ws");
|
|
320
341
|
// Mesh over the user's own ssh session (`--codespace <name>` or VYOMI_MESH_CODESPACE): no relay, no token (mesh-ssh.mjs).
|
|
321
342
|
const ci = rest.indexOf("--codespace");
|
|
@@ -329,6 +350,7 @@ export async function main(argv) {
|
|
|
329
350
|
const transport = o.transport;
|
|
330
351
|
resetKnownHostsOnNewCodespace(o.transport.codespace || (o.sess && o.sess.codespace));
|
|
331
352
|
transport.onStop(() => console.error("vyomi-tunnel: your Mesh session has ended."));
|
|
353
|
+
if (cmd === "connect" && vmName(rest[0]) && vmName(rest[0]).toLowerCase() !== "host") await ensureInstanceKey(transport, transport.codespace || (o.sess && o.sess.codespace));
|
|
332
354
|
try {
|
|
333
355
|
if (cmd === "connect") { const vm = vmName(rest[0]); if (!vm) { console.error("usage: vyomi-tunnel connect <vm>[.vyomi] [port]"); return 2; } return await ssh.connectSsh(vm, { port: Number(rest[1] || 22), transport }); }
|
|
334
356
|
const pos = rest.filter((x) => !x.startsWith("--")); const m = /^(\d{1,5}):(\d{1,5})$/.exec(pos[1] || "");
|
|
@@ -371,7 +393,7 @@ export async function main(argv) {
|
|
|
371
393
|
if (!/^[A-Za-z0-9_-]{20,64}$/.test(code)) { console.error("usage: vyomi-tunnel reset <code> (get a code in the Vyomi console: Setup Tunnel > Get install command; see `vyomi-tunnel help reset`)"); return 2; }
|
|
372
394
|
const { createCredsSync } = await import("./creds-sync.mjs");
|
|
373
395
|
try {
|
|
374
|
-
const cs = createCredsSync({ version: process.env.VYOMI_TUNNEL_VERSION_NUM || "1.2.
|
|
396
|
+
const cs = createCredsSync({ version: process.env.VYOMI_TUNNEL_VERSION_NUM || "1.2.4" });
|
|
375
397
|
const st = await cs.reset(code, os.hostname());
|
|
376
398
|
console.log(st.state === "ok" ? `Done. The tunnel now uses access key ${st.key_id}.` : `The new key was saved (${st.key_id}) but the portal answered: ${st.error || st.state}.`);
|
|
377
399
|
try { await fetch(`http://127.0.0.1:${process.env.RELAY_PORT || 8090}/reload`, { method: "POST", signal: AbortSignal.timeout(3000) }); console.log("The running tunnel reloaded it."); }
|
package/bin/vyomi-tunnel.mjs
CHANGED
|
@@ -45,19 +45,40 @@ import { createRequire } from "node:module";
|
|
|
45
45
|
// resolves wherever it's installed (e.g. NODE_PATH=/tmp/node_modules for tests).
|
|
46
46
|
const { WebSocketServer, WebSocket } = createRequire(import.meta.url)(process.env.WS_PKG || "ws");
|
|
47
47
|
|
|
48
|
+
function friendlyError(e) {
|
|
49
|
+
const code = e && e.code;
|
|
50
|
+
if (code === "EADDRINUSE") return `port ${process.env.RELAY_PORT || 8090} is already in use. A Vyomi tunnel is probably already running (check http://127.0.0.1:${process.env.RELAY_PORT || 8090}/health); stop it first, or set RELAY_PORT to another port.`;
|
|
51
|
+
if (code === "EACCES") return "permission denied for that port. Use a port above 1024 (RELAY_PORT).";
|
|
52
|
+
if (code === "ERR_SOCKET_BAD_PORT") return "RELAY_PORT must be a number from 1 to 65535.";
|
|
53
|
+
return (e && e.message) || String(e);
|
|
54
|
+
}
|
|
55
|
+
process.on("unhandledRejection", (e) => { console.error(`vyomi-tunnel: ${friendlyError(e)}`); if (process.env.VYOMI_DEBUG) console.error(e && e.stack); process.exit(1); });
|
|
56
|
+
|
|
48
57
|
// Mesh / SSH client subcommands (no relay is started for these): login | config | connect <vm> | status | forward <target> <local>:<remote> | keep
|
|
49
58
|
if (["login", "config", "connect", "status", "forward", "keep", "reset", "gh-login", "gateway-backend", "list", "ls", "help", "-h", "--help", "-help", "--version", "-v", "version"].includes(process.argv[2])) {
|
|
50
59
|
const { main } = await import("./mesh-cli.mjs");
|
|
51
|
-
|
|
60
|
+
try {
|
|
61
|
+
process.exit(await main(process.argv.slice(2)));
|
|
62
|
+
} catch (e) { // a user-facing tool never prints a stack trace (set VYOMI_DEBUG=1 to see it)
|
|
63
|
+
console.error(`vyomi-tunnel: ${friendlyError(e)}`);
|
|
64
|
+
if (process.env.VYOMI_DEBUG) console.error(e && e.stack);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
52
67
|
}
|
|
53
68
|
|
|
54
|
-
|
|
69
|
+
// Anything else on the command line is a mistake: running the relay with a stray flag would silently ignore it (or crash if one is already running).
|
|
70
|
+
if (process.argv[2]) {
|
|
71
|
+
const what = process.argv[2].startsWith("-") ? "option" : "command";
|
|
72
|
+
console.error(`vyomi-tunnel: unknown ${what} "${process.argv[2]}". Run \`vyomi-tunnel help\`.`);
|
|
73
|
+
process.exit(2);
|
|
74
|
+
}
|
|
55
75
|
|
|
56
76
|
// The tunnel keeps running even when its key is missing, revoked or wrong (a service manager would crash-loop it otherwise): the state is
|
|
57
77
|
// shown on /health, re-checked on a timer and when ~/.vyomi/credentials changes, and the Vyomi page can re-pair it (POST /reset).
|
|
58
|
-
const VERSION = "1.2.
|
|
78
|
+
const VERSION = "1.2.4";
|
|
59
79
|
const credsSync = createCredsSync({ version: VERSION, log: (m) => console.log("[creds] " + m) });
|
|
60
80
|
const PORT = Number(process.env.RELAY_PORT || 8090);
|
|
81
|
+
if (!Number.isInteger(PORT) || PORT < 1 || PORT > 65535) { console.error(`vyomi-tunnel: ${friendlyError({ code: "ERR_SOCKET_BAD_PORT" })}`); process.exit(2); }
|
|
61
82
|
// Mesh plane: the Nano console reaches the user's Mesh Codespace THROUGH this relay (the link runs on the laptop, over their own
|
|
62
83
|
// `gh codespace ssh`; opened on first use). No hosted relay, no MESH_RELAY_URL. Needs a Pro/Max key + a running Mesh Codespace.
|
|
63
84
|
const hub = createLazySshHub({ WebSocketServer, WebSocket, openMesh: async (o) => (await import("./mesh-cli.mjs")).openMesh(o), currentCodespace: async (o) => (await import("./mesh-cli.mjs")).currentMeshCodespace(o), log: (m) => console.log("[relay] " + m) });
|
|
@@ -343,6 +364,7 @@ const liveness = setInterval(() => {
|
|
|
343
364
|
}, PING_MS);
|
|
344
365
|
wss.on("close", () => { clearInterval(liveness); clearInterval(vmLiveness); });
|
|
345
366
|
|
|
367
|
+
server.on("error", (e) => { console.error(`vyomi-tunnel: ${friendlyError(e)}`); if (process.env.VYOMI_DEBUG) console.error(e && e.stack); process.exit(1); });
|
|
346
368
|
credsSync.start();
|
|
347
369
|
server.listen(PORT, HOST, () => {
|
|
348
370
|
const shown = HOST === "0.0.0.0" ? "<this-machine-ip>" : HOST;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vyomi-tunnel",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Vyomi-Nano local reverse-tunnel — reach the in-browser cloud simulator from any local SDK/CLI. The install-once, zero-cloud counterpart to the hosted Cloudflare relay; the Nano tab auto-detects it and prefers it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|