@celljs/ta-gateway 4.34.0 → 4.36.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/esm/node/docker-sandbox.js +3 -1
- package/esm/node/gateway-audit.d.ts +1 -0
- package/esm/node/gateway-audit.js +6 -6
- package/esm/node/gateway-server.js +7 -5
- package/esm/node/gateway-service.js +6 -4
- package/esm/node/local-sandbox.js +3 -1
- package/esm/node/sandbox-updates.js +5 -3
- package/esm/node/tenant-store.js +3 -5
- package/lib/node/docker-sandbox.js +3 -1
- package/lib/node/gateway-audit.d.ts +1 -0
- package/lib/node/gateway-audit.js +5 -5
- package/lib/node/gateway-server.js +7 -5
- package/lib/node/gateway-service.js +6 -4
- package/lib/node/local-sandbox.js +3 -1
- package/lib/node/sandbox-updates.js +5 -3
- package/lib/node/tenant-store.js +2 -4
- package/package.json +6 -5
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
+
import { Loggers } from '@celljs/core/lib/common/logger/console-logger';
|
|
2
3
|
import { DockerEngine, DockerEngineUtil } from './docker-engine.js';
|
|
3
4
|
import { SandboxProviders, } from './sandbox-provider.js';
|
|
5
|
+
const logger = Loggers.get('ta gateway');
|
|
4
6
|
export var DockerSandboxUtil;
|
|
5
7
|
(function (DockerSandboxUtil) {
|
|
6
8
|
/** The label of a container that tells the environment the gateway gave it. */
|
|
@@ -147,7 +149,7 @@ export class DockerSandbox {
|
|
|
147
149
|
if (refresh && DockerSandboxUtil.remote(image) && Date.now() - this.pulledAt > PULL_MS) {
|
|
148
150
|
this.pulledAt = Date.now();
|
|
149
151
|
this.latestRead = undefined;
|
|
150
|
-
await this.engine.pull(image).catch(error =>
|
|
152
|
+
await this.engine.pull(image).catch(error => logger.warn(`pulling ${image} failed: ${error.message}`));
|
|
151
153
|
}
|
|
152
154
|
const name = this.containerName(tenant);
|
|
153
155
|
const [latest, container, previous] = await Promise.all([
|
|
@@ -6,6 +6,7 @@ import type { TaGatewayAuditEntry } from '@celljs/ta-protocol';
|
|
|
6
6
|
export declare class GatewayAudit {
|
|
7
7
|
protected readonly file: string;
|
|
8
8
|
constructor(dir: string);
|
|
9
|
+
/** Turned over at AUDIT_MAX_BYTES, one older file kept (`audit.jsonl.1`): what list reads is the end of it anyway. */
|
|
9
10
|
add(entry: Omit<TaGatewayAuditEntry, 'at'>, now?: number): void;
|
|
10
11
|
/** The latest first. */
|
|
11
12
|
list(limit: number): TaGatewayAuditEntry[];
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import { FileRetention } from '@celljs/core/lib/node/fs';
|
|
3
4
|
/** What is kept of the audit when read: the end of the file, as many bytes at most. */
|
|
4
5
|
const TAIL_BYTES = 2 * 1024 * 1024;
|
|
6
|
+
/** How large it grows before it is turned over. */
|
|
7
|
+
const AUDIT_MAX_BYTES = 16 * 1024 * 1024;
|
|
5
8
|
/**
|
|
6
9
|
* What administrators did, one JSON line each (`audit.jsonl`, readable by the gateway's user only): what changed
|
|
7
10
|
* and what of others was looked at (logs, what an agent did), with who and when.
|
|
@@ -10,12 +13,9 @@ export class GatewayAudit {
|
|
|
10
13
|
constructor(dir) {
|
|
11
14
|
this.file = join(dir, 'audit.jsonl');
|
|
12
15
|
}
|
|
16
|
+
/** Turned over at AUDIT_MAX_BYTES, one older file kept (`audit.jsonl.1`): what list reads is the end of it anyway. */
|
|
13
17
|
add(entry, now = Date.now()) {
|
|
14
|
-
|
|
15
|
-
appendFileSync(this.file, `${JSON.stringify({ at: now, ...entry })}\n`, { mode: 0o600 });
|
|
16
|
-
if (fresh) {
|
|
17
|
-
chmodSync(this.file, 0o600);
|
|
18
|
-
}
|
|
18
|
+
FileRetention.append(this.file, `${JSON.stringify({ at: now, ...entry })}\n`, { maxBytes: AUDIT_MAX_BYTES, keep: 1, mode: 0o600 });
|
|
19
19
|
}
|
|
20
20
|
/** The latest first. */
|
|
21
21
|
list(limit) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { accessSync, constants, createReadStream, existsSync, mkdirSync, statSync } from 'node:fs';
|
|
2
2
|
import { createServer } from 'node:http';
|
|
3
3
|
import { extname, join, normalize, sep } from 'node:path';
|
|
4
|
+
import { Loggers } from '@celljs/core/lib/common/logger/console-logger';
|
|
4
5
|
import { WebSocketConnection } from '@celljs/rpc/lib/node/websocket/websocket-connection';
|
|
5
6
|
import { AccessStore, AccessUtil } from '@celljs/ta-host/lib/node/sign-in/access-store';
|
|
6
7
|
import { SignInFlow, SignInUtil } from '@celljs/ta-host/lib/node/sign-in/sign-in-flow';
|
|
@@ -28,6 +29,7 @@ import { SandboxProviders } from './sandbox-provider.js';
|
|
|
28
29
|
import { SIGN_IN_LINK_PATH, SignInLinks } from './sign-in-links.js';
|
|
29
30
|
import { TaSandbox } from './ta-sandbox.js';
|
|
30
31
|
import { TenantStore } from './tenant-store.js';
|
|
32
|
+
const logger = Loggers.get('ta gateway');
|
|
31
33
|
/** How often the minutes of running sandboxes are counted, and those out of them stopped. */
|
|
32
34
|
const TICK_MS = 30000;
|
|
33
35
|
/** The browser's token for `/api/files`, which pages load by URL, without the token of the WebSocket. */
|
|
@@ -252,7 +254,7 @@ export class GatewayServer {
|
|
|
252
254
|
this.quotas.addEgress(id, bytes, now);
|
|
253
255
|
}
|
|
254
256
|
for (const tenant of this.quotas.tick(this.environments.runningIds(), now)) {
|
|
255
|
-
|
|
257
|
+
logger.info(`${tenant.account} used its free minutes of the month: its sandbox stops`);
|
|
256
258
|
await this.environments.stop(tenant.id).catch(() => undefined);
|
|
257
259
|
this.reset(tenant.id);
|
|
258
260
|
}
|
|
@@ -263,11 +265,11 @@ export class GatewayServer {
|
|
|
263
265
|
server.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head));
|
|
264
266
|
// The way out of the sandboxes: CONNECT for https, absolute URLs for http (handle).
|
|
265
267
|
server.on('connect', (request, socket, head) => this.egress.connect(request, socket, head).catch(error => {
|
|
266
|
-
|
|
268
|
+
logger.warn(`CONNECT ${request.url} failed: ${error.message}`);
|
|
267
269
|
socket.destroy();
|
|
268
270
|
}));
|
|
269
271
|
this.server = server;
|
|
270
|
-
this.ticker = setInterval(() => void this.tick().catch(error =>
|
|
272
|
+
this.ticker = setInterval(() => void this.tick().catch(error => logger.warn(`counting minutes failed: ${error.message}`)), TICK_MS);
|
|
271
273
|
(_b = (_a = this.ticker).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
272
274
|
this.service.updates.start();
|
|
273
275
|
return new Promise((resolve, reject) => {
|
|
@@ -369,7 +371,7 @@ export class GatewayServer {
|
|
|
369
371
|
}
|
|
370
372
|
}
|
|
371
373
|
catch (error) {
|
|
372
|
-
|
|
374
|
+
logger.warn(`${request.method} ${path} failed: ${error.message}`);
|
|
373
375
|
if (!response.headersSent) {
|
|
374
376
|
SignInPageUtil.end(response, 502);
|
|
375
377
|
}
|
|
@@ -416,7 +418,7 @@ export class GatewayServer {
|
|
|
416
418
|
}
|
|
417
419
|
const account = { id: link.account, name: link.name };
|
|
418
420
|
const token = this.flow.store.signIn(account, request.headers['user-agent']);
|
|
419
|
-
|
|
421
|
+
logger.info(`${link.account} signed in with a link`);
|
|
420
422
|
this.signedIn(response, token, account, this.origin(request));
|
|
421
423
|
SignInPageUtil.redirect(response, SignInPageUtil.back({ token }));
|
|
422
424
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Loggers } from '@celljs/core/lib/common/logger/console-logger';
|
|
1
2
|
import { AccessUtil } from '@celljs/ta-host/lib/node/sign-in/access-store';
|
|
2
3
|
import { TaErrorCode, } from '@celljs/ta-protocol';
|
|
3
4
|
import { Redactor } from '@celljs/ta-protocol/lib/common/redactor';
|
|
@@ -7,6 +8,7 @@ import { GatewayCallError, GatewayServiceUtil } from './gateway-service-util.js'
|
|
|
7
8
|
import { GatewayUsageUtil } from './gateway-usage.js';
|
|
8
9
|
import { ModelProxyUtil } from './model-proxy.js';
|
|
9
10
|
import { SandboxUpdates } from './sandbox-updates.js';
|
|
11
|
+
const logger = Loggers.get('ta gateway');
|
|
10
12
|
const DAY = 24 * 3600000;
|
|
11
13
|
/**
|
|
12
14
|
* The calls the gateway answers on the WebSocket of a browser: TaGatewayServer, and TaAccessServer, whose
|
|
@@ -97,7 +99,7 @@ export class GatewayService {
|
|
|
97
99
|
this.audit.add({ actor: caller.account, action, target, detail: GatewayServiceUtil.detail(action, params) });
|
|
98
100
|
}
|
|
99
101
|
catch (error) {
|
|
100
|
-
|
|
102
|
+
logger.warn(`the audit could not be written: ${error.message}`);
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
info(caller) {
|
|
@@ -345,7 +347,7 @@ export class GatewayService {
|
|
|
345
347
|
const tenant = (_a = this.tenants.get(caller.tenant.id)) !== null && _a !== void 0 ? _a : caller.tenant;
|
|
346
348
|
const device = typeof label === 'string' && label.trim() ? label.trim().slice(0, 60) : 'Another Ta';
|
|
347
349
|
const token = this.flow.store.signIn({ id: caller.account, name: tenant.name, avatar: tenant.avatar }, device);
|
|
348
|
-
|
|
350
|
+
logger.info(`${caller.account} made a token for ${device}`);
|
|
349
351
|
return { token, url: this.meta.publicUrl };
|
|
350
352
|
}
|
|
351
353
|
access(caller) {
|
|
@@ -376,10 +378,10 @@ export class GatewayService {
|
|
|
376
378
|
this.hooks.cutOff();
|
|
377
379
|
for (const tenant of this.tenants.list().filter(one => !this.flow.store.allows(one.account) && !this.policy.lets(one.account))) {
|
|
378
380
|
const unpaired = await this.environments.revoke(tenant).catch((error) => {
|
|
379
|
-
|
|
381
|
+
logger.warn(`revoking ${tenant.account} failed: ${error.message}`);
|
|
380
382
|
return 0;
|
|
381
383
|
});
|
|
382
|
-
|
|
384
|
+
logger.info(`${tenant.account} is no longer let in: its sandbox stopped, ${unpaired} paired devices removed`);
|
|
383
385
|
}
|
|
384
386
|
}
|
|
385
387
|
async signOut(caller, id) {
|
|
@@ -2,7 +2,9 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { mkdirSync } from 'node:fs';
|
|
3
3
|
import { createServer } from 'node:net';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
+
import { Loggers } from '@celljs/core/lib/common/logger/console-logger';
|
|
5
6
|
import { SandboxProviders } from './sandbox-provider.js';
|
|
7
|
+
const logger = Loggers.get('ta gateway');
|
|
6
8
|
/** How long a ta serve has to end on SIGTERM before it is killed. */
|
|
7
9
|
const STOP_TIMEOUT_MS = 10000;
|
|
8
10
|
/** The lines of output of each tenant's ta serve kept for the console. */
|
|
@@ -75,7 +77,7 @@ export class LocalSandbox {
|
|
|
75
77
|
}
|
|
76
78
|
};
|
|
77
79
|
child.once('error', error => {
|
|
78
|
-
|
|
80
|
+
logger.warn(`the local sandbox of ${tenant.id} did not start: ${error.message}`);
|
|
79
81
|
gone();
|
|
80
82
|
});
|
|
81
83
|
this.running.set(tenant.id, { child, url });
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Loggers } from '@celljs/core/lib/common/logger/console-logger';
|
|
1
2
|
import { EnvironmentsUtil } from './environments.js';
|
|
3
|
+
const logger = Loggers.get('ta gateway');
|
|
2
4
|
export var SandboxUpdatesUtil;
|
|
3
5
|
(function (SandboxUpdatesUtil) {
|
|
4
6
|
/** How often the gateway looks for a newer version and the sandboxes that may move to it. */
|
|
@@ -28,7 +30,7 @@ export class SandboxUpdates {
|
|
|
28
30
|
}
|
|
29
31
|
start() {
|
|
30
32
|
var _a, _b;
|
|
31
|
-
this.timer = setInterval(() => void this.tick().catch(error =>
|
|
33
|
+
this.timer = setInterval(() => void this.tick().catch(error => logger.warn(`updating sandboxes failed: ${error.message}`)), SandboxUpdatesUtil.EVERY_MS);
|
|
32
34
|
(_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
33
35
|
}
|
|
34
36
|
dispose() {
|
|
@@ -71,7 +73,7 @@ export class SandboxUpdates {
|
|
|
71
73
|
this.record(tenant, 'updateTenant', `${EnvironmentsUtil.label(from.version)} → ${EnvironmentsUtil.label(from.latest)}`);
|
|
72
74
|
}
|
|
73
75
|
if (wentBack) {
|
|
74
|
-
|
|
76
|
+
logger.warn(`${tenant.account} did not move to the latest version, the others wait: ${wentBack}`);
|
|
75
77
|
break;
|
|
76
78
|
}
|
|
77
79
|
}
|
|
@@ -97,7 +99,7 @@ export class SandboxUpdates {
|
|
|
97
99
|
this.parts.audit.add({ actor: SandboxUpdatesUtil.ACTOR, action, target: tenant.account, detail });
|
|
98
100
|
}
|
|
99
101
|
catch (error) {
|
|
100
|
-
|
|
102
|
+
logger.warn(`the audit could not be written: ${error.message}`);
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
}
|
package/esm/node/tenant-store.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { FileUtil } from '@celljs/core/lib/node/fs';
|
|
4
5
|
/** Files written whole or not at all, readable by this user only. */
|
|
5
6
|
export function writePrivate(file, data) {
|
|
6
|
-
|
|
7
|
-
writeFileSync(temporary, JSON.stringify(data, undefined, 2), { mode: 0o600 });
|
|
8
|
-
chmodSync(temporary, 0o600);
|
|
9
|
-
renameSync(temporary, file);
|
|
7
|
+
FileUtil.write(file, JSON.stringify(data, undefined, 2), { mode: 0o600, mkdir: false });
|
|
10
8
|
}
|
|
11
9
|
export var TenantUtil;
|
|
12
10
|
(function (TenantUtil) {
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DockerSandbox = exports.DockerSandboxUtil = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const console_logger_1 = require("@celljs/core/lib/common/logger/console-logger");
|
|
5
6
|
const docker_engine_1 = require("./docker-engine");
|
|
6
7
|
const sandbox_provider_1 = require("./sandbox-provider");
|
|
8
|
+
const logger = console_logger_1.Loggers.get('ta gateway');
|
|
7
9
|
var DockerSandboxUtil;
|
|
8
10
|
(function (DockerSandboxUtil) {
|
|
9
11
|
/** The label of a container that tells the environment the gateway gave it. */
|
|
@@ -150,7 +152,7 @@ class DockerSandbox {
|
|
|
150
152
|
if (refresh && DockerSandboxUtil.remote(image) && Date.now() - this.pulledAt > PULL_MS) {
|
|
151
153
|
this.pulledAt = Date.now();
|
|
152
154
|
this.latestRead = undefined;
|
|
153
|
-
await this.engine.pull(image).catch(error =>
|
|
155
|
+
await this.engine.pull(image).catch(error => logger.warn(`pulling ${image} failed: ${error.message}`));
|
|
154
156
|
}
|
|
155
157
|
const name = this.containerName(tenant);
|
|
156
158
|
const [latest, container, previous] = await Promise.all([
|
|
@@ -6,6 +6,7 @@ import type { TaGatewayAuditEntry } from '@celljs/ta-protocol';
|
|
|
6
6
|
export declare class GatewayAudit {
|
|
7
7
|
protected readonly file: string;
|
|
8
8
|
constructor(dir: string);
|
|
9
|
+
/** Turned over at AUDIT_MAX_BYTES, one older file kept (`audit.jsonl.1`): what list reads is the end of it anyway. */
|
|
9
10
|
add(entry: Omit<TaGatewayAuditEntry, 'at'>, now?: number): void;
|
|
10
11
|
/** The latest first. */
|
|
11
12
|
list(limit: number): TaGatewayAuditEntry[];
|
|
@@ -3,8 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GatewayAudit = void 0;
|
|
4
4
|
const node_fs_1 = require("node:fs");
|
|
5
5
|
const node_path_1 = require("node:path");
|
|
6
|
+
const fs_1 = require("@celljs/core/lib/node/fs");
|
|
6
7
|
/** What is kept of the audit when read: the end of the file, as many bytes at most. */
|
|
7
8
|
const TAIL_BYTES = 2 * 1024 * 1024;
|
|
9
|
+
/** How large it grows before it is turned over. */
|
|
10
|
+
const AUDIT_MAX_BYTES = 16 * 1024 * 1024;
|
|
8
11
|
/**
|
|
9
12
|
* What administrators did, one JSON line each (`audit.jsonl`, readable by the gateway's user only): what changed
|
|
10
13
|
* and what of others was looked at (logs, what an agent did), with who and when.
|
|
@@ -13,12 +16,9 @@ class GatewayAudit {
|
|
|
13
16
|
constructor(dir) {
|
|
14
17
|
this.file = (0, node_path_1.join)(dir, 'audit.jsonl');
|
|
15
18
|
}
|
|
19
|
+
/** Turned over at AUDIT_MAX_BYTES, one older file kept (`audit.jsonl.1`): what list reads is the end of it anyway. */
|
|
16
20
|
add(entry, now = Date.now()) {
|
|
17
|
-
|
|
18
|
-
(0, node_fs_1.appendFileSync)(this.file, `${JSON.stringify({ at: now, ...entry })}\n`, { mode: 0o600 });
|
|
19
|
-
if (fresh) {
|
|
20
|
-
(0, node_fs_1.chmodSync)(this.file, 0o600);
|
|
21
|
-
}
|
|
21
|
+
fs_1.FileRetention.append(this.file, `${JSON.stringify({ at: now, ...entry })}\n`, { maxBytes: AUDIT_MAX_BYTES, keep: 1, mode: 0o600 });
|
|
22
22
|
}
|
|
23
23
|
/** The latest first. */
|
|
24
24
|
list(limit) {
|
|
@@ -4,6 +4,7 @@ exports.GatewayServer = exports.GatewayServerUtil = exports.SANDBOX_TYPES = void
|
|
|
4
4
|
const node_fs_1 = require("node:fs");
|
|
5
5
|
const node_http_1 = require("node:http");
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
|
+
const console_logger_1 = require("@celljs/core/lib/common/logger/console-logger");
|
|
7
8
|
const websocket_connection_1 = require("@celljs/rpc/lib/node/websocket/websocket-connection");
|
|
8
9
|
const access_store_1 = require("@celljs/ta-host/lib/node/sign-in/access-store");
|
|
9
10
|
const sign_in_flow_1 = require("@celljs/ta-host/lib/node/sign-in/sign-in-flow");
|
|
@@ -31,6 +32,7 @@ const sandbox_provider_1 = require("./sandbox-provider");
|
|
|
31
32
|
const sign_in_links_1 = require("./sign-in-links");
|
|
32
33
|
const ta_sandbox_1 = require("./ta-sandbox");
|
|
33
34
|
const tenant_store_1 = require("./tenant-store");
|
|
35
|
+
const logger = console_logger_1.Loggers.get('ta gateway');
|
|
34
36
|
/** How often the minutes of running sandboxes are counted, and those out of them stopped. */
|
|
35
37
|
const TICK_MS = 30000;
|
|
36
38
|
/** The browser's token for `/api/files`, which pages load by URL, without the token of the WebSocket. */
|
|
@@ -255,7 +257,7 @@ class GatewayServer {
|
|
|
255
257
|
this.quotas.addEgress(id, bytes, now);
|
|
256
258
|
}
|
|
257
259
|
for (const tenant of this.quotas.tick(this.environments.runningIds(), now)) {
|
|
258
|
-
|
|
260
|
+
logger.info(`${tenant.account} used its free minutes of the month: its sandbox stops`);
|
|
259
261
|
await this.environments.stop(tenant.id).catch(() => undefined);
|
|
260
262
|
this.reset(tenant.id);
|
|
261
263
|
}
|
|
@@ -266,11 +268,11 @@ class GatewayServer {
|
|
|
266
268
|
server.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head));
|
|
267
269
|
// The way out of the sandboxes: CONNECT for https, absolute URLs for http (handle).
|
|
268
270
|
server.on('connect', (request, socket, head) => this.egress.connect(request, socket, head).catch(error => {
|
|
269
|
-
|
|
271
|
+
logger.warn(`CONNECT ${request.url} failed: ${error.message}`);
|
|
270
272
|
socket.destroy();
|
|
271
273
|
}));
|
|
272
274
|
this.server = server;
|
|
273
|
-
this.ticker = setInterval(() => void this.tick().catch(error =>
|
|
275
|
+
this.ticker = setInterval(() => void this.tick().catch(error => logger.warn(`counting minutes failed: ${error.message}`)), TICK_MS);
|
|
274
276
|
(_b = (_a = this.ticker).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
275
277
|
this.service.updates.start();
|
|
276
278
|
return new Promise((resolve, reject) => {
|
|
@@ -372,7 +374,7 @@ class GatewayServer {
|
|
|
372
374
|
}
|
|
373
375
|
}
|
|
374
376
|
catch (error) {
|
|
375
|
-
|
|
377
|
+
logger.warn(`${request.method} ${path} failed: ${error.message}`);
|
|
376
378
|
if (!response.headersSent) {
|
|
377
379
|
sign_in_pages_1.SignInPageUtil.end(response, 502);
|
|
378
380
|
}
|
|
@@ -419,7 +421,7 @@ class GatewayServer {
|
|
|
419
421
|
}
|
|
420
422
|
const account = { id: link.account, name: link.name };
|
|
421
423
|
const token = this.flow.store.signIn(account, request.headers['user-agent']);
|
|
422
|
-
|
|
424
|
+
logger.info(`${link.account} signed in with a link`);
|
|
423
425
|
this.signedIn(response, token, account, this.origin(request));
|
|
424
426
|
sign_in_pages_1.SignInPageUtil.redirect(response, sign_in_pages_1.SignInPageUtil.back({ token }));
|
|
425
427
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GatewayService = void 0;
|
|
4
|
+
const console_logger_1 = require("@celljs/core/lib/common/logger/console-logger");
|
|
4
5
|
const access_store_1 = require("@celljs/ta-host/lib/node/sign-in/access-store");
|
|
5
6
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
6
7
|
const redactor_1 = require("@celljs/ta-protocol/lib/common/redactor");
|
|
@@ -10,6 +11,7 @@ const gateway_service_util_1 = require("./gateway-service-util");
|
|
|
10
11
|
const gateway_usage_1 = require("./gateway-usage");
|
|
11
12
|
const model_proxy_1 = require("./model-proxy");
|
|
12
13
|
const sandbox_updates_1 = require("./sandbox-updates");
|
|
14
|
+
const logger = console_logger_1.Loggers.get('ta gateway');
|
|
13
15
|
const DAY = 24 * 3600000;
|
|
14
16
|
/**
|
|
15
17
|
* The calls the gateway answers on the WebSocket of a browser: TaGatewayServer, and TaAccessServer, whose
|
|
@@ -100,7 +102,7 @@ class GatewayService {
|
|
|
100
102
|
this.audit.add({ actor: caller.account, action, target, detail: gateway_service_util_1.GatewayServiceUtil.detail(action, params) });
|
|
101
103
|
}
|
|
102
104
|
catch (error) {
|
|
103
|
-
|
|
105
|
+
logger.warn(`the audit could not be written: ${error.message}`);
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
info(caller) {
|
|
@@ -348,7 +350,7 @@ class GatewayService {
|
|
|
348
350
|
const tenant = (_a = this.tenants.get(caller.tenant.id)) !== null && _a !== void 0 ? _a : caller.tenant;
|
|
349
351
|
const device = typeof label === 'string' && label.trim() ? label.trim().slice(0, 60) : 'Another Ta';
|
|
350
352
|
const token = this.flow.store.signIn({ id: caller.account, name: tenant.name, avatar: tenant.avatar }, device);
|
|
351
|
-
|
|
353
|
+
logger.info(`${caller.account} made a token for ${device}`);
|
|
352
354
|
return { token, url: this.meta.publicUrl };
|
|
353
355
|
}
|
|
354
356
|
access(caller) {
|
|
@@ -379,10 +381,10 @@ class GatewayService {
|
|
|
379
381
|
this.hooks.cutOff();
|
|
380
382
|
for (const tenant of this.tenants.list().filter(one => !this.flow.store.allows(one.account) && !this.policy.lets(one.account))) {
|
|
381
383
|
const unpaired = await this.environments.revoke(tenant).catch((error) => {
|
|
382
|
-
|
|
384
|
+
logger.warn(`revoking ${tenant.account} failed: ${error.message}`);
|
|
383
385
|
return 0;
|
|
384
386
|
});
|
|
385
|
-
|
|
387
|
+
logger.info(`${tenant.account} is no longer let in: its sandbox stopped, ${unpaired} paired devices removed`);
|
|
386
388
|
}
|
|
387
389
|
}
|
|
388
390
|
async signOut(caller, id) {
|
|
@@ -5,7 +5,9 @@ const node_child_process_1 = require("node:child_process");
|
|
|
5
5
|
const node_fs_1 = require("node:fs");
|
|
6
6
|
const node_net_1 = require("node:net");
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
|
+
const console_logger_1 = require("@celljs/core/lib/common/logger/console-logger");
|
|
8
9
|
const sandbox_provider_1 = require("./sandbox-provider");
|
|
10
|
+
const logger = console_logger_1.Loggers.get('ta gateway');
|
|
9
11
|
/** How long a ta serve has to end on SIGTERM before it is killed. */
|
|
10
12
|
const STOP_TIMEOUT_MS = 10000;
|
|
11
13
|
/** The lines of output of each tenant's ta serve kept for the console. */
|
|
@@ -79,7 +81,7 @@ class LocalSandbox {
|
|
|
79
81
|
}
|
|
80
82
|
};
|
|
81
83
|
child.once('error', error => {
|
|
82
|
-
|
|
84
|
+
logger.warn(`the local sandbox of ${tenant.id} did not start: ${error.message}`);
|
|
83
85
|
gone();
|
|
84
86
|
});
|
|
85
87
|
this.running.set(tenant.id, { child, url });
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SandboxUpdates = exports.SandboxUpdatesUtil = void 0;
|
|
4
|
+
const console_logger_1 = require("@celljs/core/lib/common/logger/console-logger");
|
|
4
5
|
const environments_1 = require("./environments");
|
|
6
|
+
const logger = console_logger_1.Loggers.get('ta gateway');
|
|
5
7
|
var SandboxUpdatesUtil;
|
|
6
8
|
(function (SandboxUpdatesUtil) {
|
|
7
9
|
/** How often the gateway looks for a newer version and the sandboxes that may move to it. */
|
|
@@ -31,7 +33,7 @@ class SandboxUpdates {
|
|
|
31
33
|
}
|
|
32
34
|
start() {
|
|
33
35
|
var _a, _b;
|
|
34
|
-
this.timer = setInterval(() => void this.tick().catch(error =>
|
|
36
|
+
this.timer = setInterval(() => void this.tick().catch(error => logger.warn(`updating sandboxes failed: ${error.message}`)), SandboxUpdatesUtil.EVERY_MS);
|
|
35
37
|
(_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
36
38
|
}
|
|
37
39
|
dispose() {
|
|
@@ -74,7 +76,7 @@ class SandboxUpdates {
|
|
|
74
76
|
this.record(tenant, 'updateTenant', `${environments_1.EnvironmentsUtil.label(from.version)} → ${environments_1.EnvironmentsUtil.label(from.latest)}`);
|
|
75
77
|
}
|
|
76
78
|
if (wentBack) {
|
|
77
|
-
|
|
79
|
+
logger.warn(`${tenant.account} did not move to the latest version, the others wait: ${wentBack}`);
|
|
78
80
|
break;
|
|
79
81
|
}
|
|
80
82
|
}
|
|
@@ -100,7 +102,7 @@ class SandboxUpdates {
|
|
|
100
102
|
this.parts.audit.add({ actor: SandboxUpdatesUtil.ACTOR, action, target: tenant.account, detail });
|
|
101
103
|
}
|
|
102
104
|
catch (error) {
|
|
103
|
-
|
|
105
|
+
logger.warn(`the audit could not be written: ${error.message}`);
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
}
|
package/lib/node/tenant-store.js
CHANGED
|
@@ -5,12 +5,10 @@ exports.writePrivate = writePrivate;
|
|
|
5
5
|
const node_crypto_1 = require("node:crypto");
|
|
6
6
|
const node_fs_1 = require("node:fs");
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
|
+
const fs_1 = require("@celljs/core/lib/node/fs");
|
|
8
9
|
/** Files written whole or not at all, readable by this user only. */
|
|
9
10
|
function writePrivate(file, data) {
|
|
10
|
-
|
|
11
|
-
(0, node_fs_1.writeFileSync)(temporary, JSON.stringify(data, undefined, 2), { mode: 0o600 });
|
|
12
|
-
(0, node_fs_1.chmodSync)(temporary, 0o600);
|
|
13
|
-
(0, node_fs_1.renameSync)(temporary, file);
|
|
11
|
+
fs_1.FileUtil.write(file, JSON.stringify(data, undefined, 2), { mode: 0o600, mkdir: false });
|
|
14
12
|
}
|
|
15
13
|
var TenantUtil;
|
|
16
14
|
(function (TenantUtil) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-gateway",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.36.0",
|
|
4
4
|
"description": "ta gateway: one Ta per account, each in a sandbox of its own, behind one sign-in",
|
|
5
5
|
"homepage": "https://github.com/cellbang/ta",
|
|
6
6
|
"bugs": {
|
|
@@ -29,10 +29,11 @@
|
|
|
29
29
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@celljs/
|
|
33
|
-
"@celljs/
|
|
34
|
-
"@celljs/ta-
|
|
35
|
-
"@celljs/ta-
|
|
32
|
+
"@celljs/core": "4.36.0",
|
|
33
|
+
"@celljs/rpc": "4.36.0",
|
|
34
|
+
"@celljs/ta-host": "4.36.0",
|
|
35
|
+
"@celljs/ta-protocol": "4.36.0",
|
|
36
|
+
"@celljs/ta-relay": "4.36.0"
|
|
36
37
|
},
|
|
37
38
|
"publishConfig": {
|
|
38
39
|
"access": "public"
|