@myrialabs/clopen 0.4.32 → 0.4.34
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/backend/auth/permissions.ts +3 -0
- package/backend/auth/rate-limiter.test.ts +115 -0
- package/backend/auth/rate-limiter.ts +25 -12
- package/backend/chat/stream-manager.ts +4 -1
- package/backend/database/migrations/069_create_ssh_client_tables.ts +116 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/db-client-connection-queries.ts +7 -2
- package/backend/database/queries/file-audit-log-queries.ts +1 -0
- package/backend/database/queries/index.ts +3 -0
- package/backend/database/queries/ssh-connection-queries.ts +244 -0
- package/backend/database/queries/ssh-known-host-queries.ts +67 -0
- package/backend/database/queries/ssh-port-forward-queries.ts +113 -0
- package/backend/db-client/connection-manager.ts +21 -1
- package/backend/engine/adapters/codex/message-converter.ts +18 -12
- package/backend/engine/adapters/codex/patch-rollout.test.ts +88 -0
- package/backend/engine/adapters/codex/patch-rollout.ts +120 -109
- package/backend/engine/adapters/codex/stream.ts +33 -4
- package/backend/engine/adapters/copilot/stream.ts +1 -1
- package/backend/engine/adapters/cursor/stream.ts +1 -1
- package/backend/engine/adapters/qwen/stream.ts +1 -1
- package/backend/engine/docs/adapter-contract.md +7 -0
- package/backend/files/file-watcher.ts +283 -51
- package/backend/files/git-events.test.ts +110 -0
- package/backend/git/git-dirs.test.ts +132 -0
- package/backend/git/git-dirs.ts +0 -0
- package/backend/git/nested-repos.test.ts +108 -5
- package/backend/git/nested-repos.ts +103 -18
- package/backend/http/audio.ts +5 -32
- package/backend/http/bearer-auth.ts +47 -0
- package/backend/http/files-download.test.ts +146 -0
- package/backend/http/files-download.ts +109 -0
- package/backend/http/files-upload.ts +3 -29
- package/backend/http/ssh-sftp.ts +133 -0
- package/backend/index.ts +25 -2
- package/backend/mcp/README.md +34 -6
- package/backend/mcp/index.ts +8 -8
- package/backend/mcp/internal/config.ts +69 -19
- package/backend/mcp/internal/project-context.test.ts +40 -0
- package/backend/mcp/internal/project-context.ts +80 -7
- package/backend/mcp/internal/remote-server.test.ts +17 -2
- package/backend/mcp/internal/remote-server.ts +36 -3
- package/backend/mcp/internal/servers/helper.ts +48 -18
- package/backend/middleware/security.test.ts +95 -0
- package/backend/middleware/security.ts +114 -0
- package/backend/ports/attribute.test.ts +231 -0
- package/backend/ports/attribute.ts +444 -0
- package/backend/ports/kill.ts +203 -0
- package/backend/ports/monitor.ts +365 -0
- package/backend/ports/processes.test.ts +98 -0
- package/backend/ports/processes.ts +374 -0
- package/backend/ports/registry.ts +165 -0
- package/backend/ports/runner.ts +195 -0
- package/backend/ports/scan-host.ts +260 -0
- package/backend/ports/scan.test.ts +341 -0
- package/backend/ports/scan.ts +687 -0
- package/backend/ports/ssh-lineage.ts +318 -0
- package/backend/preview/browser/browser-video-capture.ts +51 -4
- package/backend/ssh/client-pool.ts +196 -0
- package/backend/ssh/connect.ts +375 -0
- package/backend/ssh/disk-usage.test.ts +134 -0
- package/backend/ssh/disk-usage.ts +214 -0
- package/backend/ssh/forwards.ts +340 -0
- package/backend/ssh/health.ts +141 -0
- package/backend/ssh/known-hosts.ts +96 -0
- package/backend/ssh/pty-backend.ts +215 -0
- package/backend/ssh/ptykit.ts +66 -0
- package/backend/ssh/sftp.test.ts +242 -0
- package/backend/ssh/sftp.ts +967 -0
- package/backend/ssh/socks5.test.ts +167 -0
- package/backend/ssh/socks5.ts +164 -0
- package/backend/ssh/tunnel.ts +87 -0
- package/backend/ws/auth/device.ts +1 -1
- package/backend/ws/auth/login.ts +8 -4
- package/backend/ws/db-client/connections.ts +1 -0
- package/backend/ws/files/watch.ts +5 -1
- package/backend/ws/index.ts +6 -0
- package/backend/ws/ports/index.ts +19 -0
- package/backend/ws/ports/kill.ts +80 -0
- package/backend/ws/ports/list.ts +60 -0
- package/backend/ws/ssh/access.ts +31 -0
- package/backend/ws/ssh/connections.ts +224 -0
- package/backend/ws/ssh/forwards.ts +109 -0
- package/backend/ws/ssh/index.ts +18 -0
- package/backend/ws/ssh/sftp.ts +259 -0
- package/backend/ws/ssh/tunnel.ts +93 -0
- package/dist/assets/{index-hu17G6tX.js → index-gGTMFUa8.js} +1 -1
- package/dist/assets/{index-DSvGoxp2.js → index-vW2RpdHu.js} +1 -1
- package/dist/assets/main-CYCMEbXB.css +1 -0
- package/dist/assets/{main-BccclZsC.js → main-ZCojSzvW.js} +506 -477
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/types/database/schema.ts +49 -0
- package/shared/types/db-client/connection.ts +6 -0
- package/shared/types/ports/index.ts +5 -0
- package/shared/types/ports/port.ts +192 -0
- package/shared/types/ssh/connection.ts +80 -0
- package/shared/types/ssh/forward.ts +46 -0
- package/shared/types/ssh/index.ts +8 -0
- package/shared/types/ssh/known-host.ts +19 -0
- package/shared/types/ssh/sftp.ts +141 -0
- package/shared/utils/logger.ts +2 -0
- package/dist/assets/main-Ciuw0wF0.css +0 -1
|
@@ -43,6 +43,9 @@ export const ADMIN_ONLY_ROUTES = new Set([
|
|
|
43
43
|
'settings:update-batch',
|
|
44
44
|
'system:run-update',
|
|
45
45
|
'system:clear-data',
|
|
46
|
+
// Port manager — anyone signed in may see what is listening, but ending a
|
|
47
|
+
// process can take down another member's work, so stopping is admin-only.
|
|
48
|
+
'ports:kill',
|
|
46
49
|
// Stack — binary installation is an admin-only operation.
|
|
47
50
|
'stack:status',
|
|
48
51
|
'stack:status-all',
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behavior-based tests for AuthRateLimiter.
|
|
3
|
+
*
|
|
4
|
+
* Validates:
|
|
5
|
+
* - Failure-based lockout tiers (5/10/20 → 30s/2m/10m) still trigger.
|
|
6
|
+
* - Lockout state is per-route and per-identifier, so a lockout on one
|
|
7
|
+
* endpoint neither blocks nor is cleared by another.
|
|
8
|
+
* - `recordSuccess` clears only its own route's record.
|
|
9
|
+
*
|
|
10
|
+
* Each test uses a unique identifier so the singleton's in-memory state does
|
|
11
|
+
* not bleed across tests.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, expect, test } from 'bun:test';
|
|
15
|
+
import { authRateLimiter } from './rate-limiter';
|
|
16
|
+
|
|
17
|
+
let seq = 0;
|
|
18
|
+
function uniqueId(label: string): string {
|
|
19
|
+
// IPv4-shaped string the rate limiter treats as opaque.
|
|
20
|
+
return `203.0.113.${++seq}-${label}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Read the remaining lockout out of `check()`'s message. */
|
|
24
|
+
function remainingMs(result: string | null): number | null {
|
|
25
|
+
if (result === null) return null;
|
|
26
|
+
const match = result.match(/Try again in (\d+) seconds/);
|
|
27
|
+
return match ? Number(match[1]) * 1000 : 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Drive an identifier to `count` failures on one route. */
|
|
31
|
+
function fail(id: string, action: string, count: number): void {
|
|
32
|
+
for (let i = 0; i < count; i++) authRateLimiter.recordFailure(id, action);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('failure-based lockout tiers', () => {
|
|
36
|
+
test('four failures stay below the first threshold', () => {
|
|
37
|
+
const id = uniqueId('4fail');
|
|
38
|
+
fail(id, 'auth:login', 4);
|
|
39
|
+
expect(authRateLimiter.check(id, 'auth:login')).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('five failures lock for 30s', () => {
|
|
43
|
+
const id = uniqueId('5fail');
|
|
44
|
+
fail(id, 'auth:login', 5);
|
|
45
|
+
expect(remainingMs(authRateLimiter.check(id, 'auth:login'))).toBeGreaterThanOrEqual(25_000);
|
|
46
|
+
expect(remainingMs(authRateLimiter.check(id, 'auth:login'))).toBeLessThanOrEqual(30_500);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('ten failures escalate to a 2-minute lockout', () => {
|
|
50
|
+
const id = uniqueId('10fail');
|
|
51
|
+
fail(id, 'auth:login', 10);
|
|
52
|
+
expect(remainingMs(authRateLimiter.check(id, 'auth:login'))).toBeGreaterThanOrEqual(115_000);
|
|
53
|
+
expect(remainingMs(authRateLimiter.check(id, 'auth:login'))).toBeLessThanOrEqual(120_500);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('twenty failures escalate to a 10-minute lockout', () => {
|
|
57
|
+
const id = uniqueId('20fail');
|
|
58
|
+
fail(id, 'auth:login', 20);
|
|
59
|
+
expect(remainingMs(authRateLimiter.check(id, 'auth:login'))).toBeGreaterThanOrEqual(595_000);
|
|
60
|
+
expect(remainingMs(authRateLimiter.check(id, 'auth:login'))).toBeLessThanOrEqual(600_500);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('routes outside the rate-limited set are ignored', () => {
|
|
64
|
+
const id = uniqueId('unlimited');
|
|
65
|
+
fail(id, 'auth:logout', 5);
|
|
66
|
+
expect(authRateLimiter.check(id, 'auth:logout')).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('per-route isolation', () => {
|
|
71
|
+
test('a lockout on auth:login does not block auth:validate-invite', () => {
|
|
72
|
+
const id = uniqueId('route-iso');
|
|
73
|
+
fail(id, 'auth:login', 5);
|
|
74
|
+
|
|
75
|
+
expect(authRateLimiter.check(id, 'auth:login')).not.toBeNull();
|
|
76
|
+
expect(authRateLimiter.check(id, 'auth:validate-invite')).toBeNull();
|
|
77
|
+
expect(authRateLimiter.check(id, 'auth:claim-device-code')).toBeNull();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('success on one route does not clear another route\'s failures', () => {
|
|
81
|
+
const id = uniqueId('no-cross-clear');
|
|
82
|
+
fail(id, 'auth:login', 5);
|
|
83
|
+
authRateLimiter.recordSuccess(id, 'auth:validate-invite');
|
|
84
|
+
|
|
85
|
+
expect(authRateLimiter.check(id, 'auth:login')).not.toBeNull();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('success clears the lockout for its own route', () => {
|
|
89
|
+
const id = uniqueId('self-clear');
|
|
90
|
+
fail(id, 'auth:login', 5);
|
|
91
|
+
authRateLimiter.recordSuccess(id, 'auth:login');
|
|
92
|
+
|
|
93
|
+
expect(authRateLimiter.check(id, 'auth:login')).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('a valid invite clears the failures from earlier mistyped ones', () => {
|
|
97
|
+
const id = uniqueId('invite-retry');
|
|
98
|
+
fail(id, 'auth:validate-invite', 2);
|
|
99
|
+
authRateLimiter.recordSuccess(id, 'auth:validate-invite');
|
|
100
|
+
fail(id, 'auth:validate-invite', 4);
|
|
101
|
+
|
|
102
|
+
expect(authRateLimiter.check(id, 'auth:validate-invite')).toBeNull();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('per-identifier isolation', () => {
|
|
107
|
+
test('one identifier locking out does not affect another', () => {
|
|
108
|
+
const idA = uniqueId('ipA');
|
|
109
|
+
const idB = uniqueId('ipB');
|
|
110
|
+
fail(idA, 'auth:login', 5);
|
|
111
|
+
|
|
112
|
+
expect(authRateLimiter.check(idA, 'auth:login')).not.toBeNull();
|
|
113
|
+
expect(authRateLimiter.check(idB, 'auth:login')).toBeNull();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Auth Rate Limiter
|
|
3
3
|
*
|
|
4
4
|
* Protects auth endpoints against brute-force and credential stuffing attacks.
|
|
5
|
-
* Tracks failed attempts per IP with progressive lockout.
|
|
5
|
+
* Tracks failed attempts per (IP, route) with progressive lockout.
|
|
6
6
|
*
|
|
7
7
|
* Thresholds:
|
|
8
8
|
* 5 failures → 30 second lockout
|
|
@@ -10,11 +10,15 @@
|
|
|
10
10
|
* 20 failures → 10 minute lockout
|
|
11
11
|
*
|
|
12
12
|
* Attempts decay after the lockout window expires.
|
|
13
|
+
*
|
|
14
|
+
* Records are keyed by IP *and* route: a lockout earned on one endpoint must
|
|
15
|
+
* not block an unrelated one, and clearing one route's record on success must
|
|
16
|
+
* not wipe another route's accumulated failures.
|
|
13
17
|
*/
|
|
14
18
|
|
|
15
19
|
import { debug } from '$shared/utils/logger';
|
|
16
20
|
|
|
17
|
-
/** Routes that should be rate-limited */
|
|
21
|
+
/** Routes that should be rate-limited. */
|
|
18
22
|
const RATE_LIMITED_ROUTES = new Set([
|
|
19
23
|
'auth:login',
|
|
20
24
|
'auth:accept-invite',
|
|
@@ -43,6 +47,7 @@ const STALE_AFTER_MS = 15 * 60_000; // 15 minutes
|
|
|
43
47
|
const CLEANUP_INTERVAL_MS = 5 * 60_000; // 5 minutes
|
|
44
48
|
|
|
45
49
|
class AuthRateLimiter {
|
|
50
|
+
/** Keyed by `${identifier}::${action}` — see the note on the module doc. */
|
|
46
51
|
private attempts = new Map<string, AttemptRecord>();
|
|
47
52
|
private cleanupTimer: ReturnType<typeof setInterval> | null = null;
|
|
48
53
|
|
|
@@ -51,6 +56,10 @@ class AuthRateLimiter {
|
|
|
51
56
|
this.cleanupTimer = setInterval(() => this.cleanup(), CLEANUP_INTERVAL_MS);
|
|
52
57
|
}
|
|
53
58
|
|
|
59
|
+
private static recordKey(identifier: string, action: string): string {
|
|
60
|
+
return `${identifier}::${action}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
54
63
|
/**
|
|
55
64
|
* Check if an action is rate-limited for the given identifier.
|
|
56
65
|
* Returns null if allowed, or an error message if blocked.
|
|
@@ -60,9 +69,9 @@ class AuthRateLimiter {
|
|
|
60
69
|
return null; // Not a rate-limited route
|
|
61
70
|
}
|
|
62
71
|
|
|
63
|
-
const record = this.attempts.get(identifier);
|
|
72
|
+
const record = this.attempts.get(AuthRateLimiter.recordKey(identifier, action));
|
|
64
73
|
if (!record) {
|
|
65
|
-
return null; // No previous
|
|
74
|
+
return null; // No previous activity
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
const now = Date.now();
|
|
@@ -70,7 +79,7 @@ class AuthRateLimiter {
|
|
|
70
79
|
// Check if currently locked out
|
|
71
80
|
if (record.lockedUntil > now) {
|
|
72
81
|
const remainingSec = Math.ceil((record.lockedUntil - now) / 1000);
|
|
73
|
-
debug.warn('auth', `Rate limited: ${identifier} (${remainingSec}s remaining, ${record.failures} failures)`);
|
|
82
|
+
debug.warn('auth', `Rate limited: ${identifier} on ${action} (${remainingSec}s remaining, ${record.failures} failures)`);
|
|
74
83
|
return `Too many failed attempts. Try again in ${remainingSec} seconds.`;
|
|
75
84
|
}
|
|
76
85
|
|
|
@@ -78,13 +87,15 @@ class AuthRateLimiter {
|
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
/**
|
|
81
|
-
* Record a failed auth attempt for the given identifier.
|
|
90
|
+
* Record a failed auth attempt for the given identifier + action.
|
|
91
|
+
* Escalates the failure-tier lockout when a new threshold is crossed.
|
|
82
92
|
*/
|
|
83
93
|
recordFailure(identifier: string, action: string): void {
|
|
84
94
|
if (!RATE_LIMITED_ROUTES.has(action)) return;
|
|
85
95
|
|
|
86
96
|
const now = Date.now();
|
|
87
|
-
const
|
|
97
|
+
const key = AuthRateLimiter.recordKey(identifier, action);
|
|
98
|
+
const record = this.attempts.get(key) ?? { failures: 0, lastFailure: 0, lockedUntil: 0 };
|
|
88
99
|
|
|
89
100
|
record.failures += 1;
|
|
90
101
|
record.lastFailure = now;
|
|
@@ -99,17 +110,19 @@ class AuthRateLimiter {
|
|
|
99
110
|
|
|
100
111
|
if (lockoutMs > 0) {
|
|
101
112
|
record.lockedUntil = now + lockoutMs;
|
|
102
|
-
debug.warn('auth', `Lockout triggered: ${identifier} — ${record.failures} failures, locked for ${lockoutMs / 1000}s`);
|
|
113
|
+
debug.warn('auth', `Lockout triggered: ${identifier} on ${action} — ${record.failures} failures, locked for ${lockoutMs / 1000}s`);
|
|
103
114
|
}
|
|
104
115
|
|
|
105
|
-
this.attempts.set(
|
|
116
|
+
this.attempts.set(key, record);
|
|
106
117
|
}
|
|
107
118
|
|
|
108
119
|
/**
|
|
109
|
-
* Clear failure record on successful auth (e.g., successful
|
|
120
|
+
* Clear the failure record for this route on successful auth (e.g., successful
|
|
121
|
+
* login). Other routes keep whatever they had accumulated.
|
|
110
122
|
*/
|
|
111
|
-
recordSuccess(identifier: string): void {
|
|
112
|
-
|
|
123
|
+
recordSuccess(identifier: string, action: string): void {
|
|
124
|
+
if (!RATE_LIMITED_ROUTES.has(action)) return;
|
|
125
|
+
this.attempts.delete(AuthRateLimiter.recordKey(identifier, action));
|
|
113
126
|
}
|
|
114
127
|
|
|
115
128
|
/**
|
|
@@ -439,7 +439,10 @@ class StreamManager extends EventEmitter {
|
|
|
439
439
|
// Register session -> projectId mapping for MCP context
|
|
440
440
|
if (request.projectId) {
|
|
441
441
|
projectContextService.registerSession(request.chatSessionId, request.projectId);
|
|
442
|
-
|
|
442
|
+
// The engine goes with it: the remote HTTP MCP bridge cannot always
|
|
443
|
+
// name the calling stream, and knowing which engine asked is what
|
|
444
|
+
// keeps a fallback from reaching across into another engine's project.
|
|
445
|
+
projectContextService.registerStream(streamId, request.projectId, request.chatSessionId, request.engine.type);
|
|
443
446
|
}
|
|
444
447
|
// Hand the AbortSignal to MCP so tool handlers can fast-fail on
|
|
445
448
|
// cancellation. Without this, the engine subprocess dies on cancel
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
|
+
import { debug } from '$shared/utils/logger';
|
|
3
|
+
|
|
4
|
+
export const description = 'Create ssh_connections, ssh_known_hosts and ssh_port_forwards tables';
|
|
5
|
+
|
|
6
|
+
export const up = (db: DatabaseConnection): void => {
|
|
7
|
+
debug.log('migration', 'Creating ssh_connections table...');
|
|
8
|
+
|
|
9
|
+
// `jump_connection_id` self-references: a saved host can be reached through
|
|
10
|
+
// another saved host (ProxyJump). ON DELETE SET NULL rather than CASCADE —
|
|
11
|
+
// deleting a bastion must not silently delete everything behind it.
|
|
12
|
+
db.exec(`
|
|
13
|
+
CREATE TABLE IF NOT EXISTS ssh_connections (
|
|
14
|
+
id TEXT PRIMARY KEY,
|
|
15
|
+
name TEXT NOT NULL,
|
|
16
|
+
host TEXT NOT NULL,
|
|
17
|
+
port INTEGER NOT NULL DEFAULT 22,
|
|
18
|
+
username TEXT NOT NULL,
|
|
19
|
+
auth_method TEXT NOT NULL DEFAULT 'password'
|
|
20
|
+
CHECK (auth_method IN ('password','key','key-file','agent')),
|
|
21
|
+
password TEXT,
|
|
22
|
+
private_key TEXT,
|
|
23
|
+
private_key_path TEXT,
|
|
24
|
+
passphrase TEXT,
|
|
25
|
+
agent_socket TEXT,
|
|
26
|
+
jump_connection_id TEXT REFERENCES ssh_connections(id) ON DELETE SET NULL,
|
|
27
|
+
initial_path TEXT,
|
|
28
|
+
keepalive_seconds INTEGER NOT NULL DEFAULT 30,
|
|
29
|
+
strict_host_key INTEGER NOT NULL DEFAULT 1,
|
|
30
|
+
color TEXT,
|
|
31
|
+
owner_user_id TEXT,
|
|
32
|
+
created_at TEXT NOT NULL,
|
|
33
|
+
updated_at TEXT NOT NULL,
|
|
34
|
+
last_used_at TEXT
|
|
35
|
+
)
|
|
36
|
+
`);
|
|
37
|
+
|
|
38
|
+
db.exec(`
|
|
39
|
+
CREATE INDEX IF NOT EXISTS idx_ssh_conn_last_used
|
|
40
|
+
ON ssh_connections(last_used_at DESC)
|
|
41
|
+
`);
|
|
42
|
+
|
|
43
|
+
db.exec(`
|
|
44
|
+
CREATE INDEX IF NOT EXISTS idx_ssh_conn_owner
|
|
45
|
+
ON ssh_connections(owner_user_id)
|
|
46
|
+
`);
|
|
47
|
+
|
|
48
|
+
debug.log('migration', 'Creating ssh_known_hosts table...');
|
|
49
|
+
|
|
50
|
+
// One trusted key per (host, port) — the same rule OpenSSH's known_hosts
|
|
51
|
+
// enforces, so a rotated key is an update rather than a second row.
|
|
52
|
+
db.exec(`
|
|
53
|
+
CREATE TABLE IF NOT EXISTS ssh_known_hosts (
|
|
54
|
+
id TEXT PRIMARY KEY,
|
|
55
|
+
host TEXT NOT NULL,
|
|
56
|
+
port INTEGER NOT NULL DEFAULT 22,
|
|
57
|
+
key_type TEXT NOT NULL,
|
|
58
|
+
fingerprint TEXT NOT NULL,
|
|
59
|
+
added_at TEXT NOT NULL,
|
|
60
|
+
last_seen_at TEXT,
|
|
61
|
+
UNIQUE (host, port)
|
|
62
|
+
)
|
|
63
|
+
`);
|
|
64
|
+
|
|
65
|
+
debug.log('migration', 'Creating ssh_port_forwards table...');
|
|
66
|
+
|
|
67
|
+
db.exec(`
|
|
68
|
+
CREATE TABLE IF NOT EXISTS ssh_port_forwards (
|
|
69
|
+
id TEXT PRIMARY KEY,
|
|
70
|
+
connection_id TEXT NOT NULL,
|
|
71
|
+
name TEXT NOT NULL,
|
|
72
|
+
type TEXT NOT NULL CHECK (type IN ('local','remote','dynamic')),
|
|
73
|
+
listen_host TEXT NOT NULL DEFAULT '127.0.0.1',
|
|
74
|
+
listen_port INTEGER NOT NULL,
|
|
75
|
+
dest_host TEXT,
|
|
76
|
+
dest_port INTEGER,
|
|
77
|
+
auto_start INTEGER NOT NULL DEFAULT 0,
|
|
78
|
+
created_at TEXT NOT NULL,
|
|
79
|
+
updated_at TEXT NOT NULL,
|
|
80
|
+
FOREIGN KEY (connection_id) REFERENCES ssh_connections(id) ON DELETE CASCADE
|
|
81
|
+
)
|
|
82
|
+
`);
|
|
83
|
+
|
|
84
|
+
db.exec(`
|
|
85
|
+
CREATE INDEX IF NOT EXISTS idx_ssh_forward_connection
|
|
86
|
+
ON ssh_port_forwards(connection_id)
|
|
87
|
+
`);
|
|
88
|
+
|
|
89
|
+
// Let a database connection reuse a saved SSH host instead of repeating the
|
|
90
|
+
// host, credentials and key inline. The inline columns stay: existing
|
|
91
|
+
// connections keep working untouched, and this is simply the other mode.
|
|
92
|
+
const dbClientColumns = db.prepare(`PRAGMA table_info(db_client_connections)`).all() as Array<{ name: string }>;
|
|
93
|
+
if (dbClientColumns.length > 0 && !dbClientColumns.some((column) => column.name === 'ssh_connection_id')) {
|
|
94
|
+
debug.log('migration', 'Adding ssh_connection_id to db_client_connections...');
|
|
95
|
+
db.exec(`
|
|
96
|
+
ALTER TABLE db_client_connections
|
|
97
|
+
ADD COLUMN ssh_connection_id TEXT REFERENCES ssh_connections(id) ON DELETE SET NULL
|
|
98
|
+
`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
debug.log('migration', 'ssh-client tables created');
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const down = (db: DatabaseConnection): void => {
|
|
105
|
+
debug.log('migration', 'Dropping ssh-client tables...');
|
|
106
|
+
db.exec('DROP INDEX IF EXISTS idx_ssh_forward_connection');
|
|
107
|
+
db.exec('DROP TABLE IF EXISTS ssh_port_forwards');
|
|
108
|
+
db.exec('DROP TABLE IF EXISTS ssh_known_hosts');
|
|
109
|
+
db.exec('DROP INDEX IF EXISTS idx_ssh_conn_owner');
|
|
110
|
+
db.exec('DROP INDEX IF EXISTS idx_ssh_conn_last_used');
|
|
111
|
+
db.exec('DROP TABLE IF EXISTS ssh_connections');
|
|
112
|
+
// db_client_connections.ssh_connection_id is deliberately left in place —
|
|
113
|
+
// SQLite cannot drop a column without rebuilding the table, and an orphaned
|
|
114
|
+
// nullable column is harmless.
|
|
115
|
+
debug.log('migration', 'ssh-client tables dropped');
|
|
116
|
+
};
|
|
@@ -67,6 +67,7 @@ import * as migration065 from './065_add_session_reasoning_effort';
|
|
|
67
67
|
import * as migration066 from './066_create_memory_graph';
|
|
68
68
|
import * as migration067 from './067_add_memory_graph_layout';
|
|
69
69
|
import * as migration068 from './068_create_engine_config_revision';
|
|
70
|
+
import * as migration069 from './069_create_ssh_client_tables';
|
|
70
71
|
|
|
71
72
|
// Export all migrations in order
|
|
72
73
|
export const migrations = [
|
|
@@ -477,6 +478,12 @@ export const migrations = [
|
|
|
477
478
|
description: migration068.description,
|
|
478
479
|
up: migration068.up,
|
|
479
480
|
down: migration068.down
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
id: '069',
|
|
484
|
+
description: migration069.description,
|
|
485
|
+
up: migration069.up,
|
|
486
|
+
down: migration069.down
|
|
480
487
|
}
|
|
481
488
|
];
|
|
482
489
|
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
|
|
12
12
|
const DEFAULT_SSH: DbClientSshConfig = {
|
|
13
13
|
enabled: false,
|
|
14
|
+
connectionId: null,
|
|
14
15
|
host: '',
|
|
15
16
|
port: 22,
|
|
16
17
|
username: '',
|
|
@@ -35,6 +36,7 @@ function rowToConnection(row: DBDbClientConnectionRow): DbClientConnection {
|
|
|
35
36
|
|
|
36
37
|
const ssh: DbClientSshConfig = {
|
|
37
38
|
enabled: row.ssh_enabled === 1,
|
|
39
|
+
connectionId: row.ssh_connection_id,
|
|
38
40
|
host: row.ssh_host ?? '',
|
|
39
41
|
port: row.ssh_port ?? 22,
|
|
40
42
|
username: row.ssh_username ?? '',
|
|
@@ -151,7 +153,7 @@ function insertConnection(input: DbClientConnectionInput, ownerUserId: string |
|
|
|
151
153
|
host, port, username, password, database,
|
|
152
154
|
ssl_mode, ssl_ca,
|
|
153
155
|
ssh_enabled, ssh_host, ssh_port, ssh_username, ssh_auth_method,
|
|
154
|
-
ssh_password, ssh_private_key, ssh_passphrase,
|
|
156
|
+
ssh_password, ssh_private_key, ssh_passphrase, ssh_connection_id,
|
|
155
157
|
options_json, color,
|
|
156
158
|
owner_user_id,
|
|
157
159
|
created_at, updated_at, last_used_at
|
|
@@ -160,7 +162,7 @@ function insertConnection(input: DbClientConnectionInput, ownerUserId: string |
|
|
|
160
162
|
?, ?, ?, ?, ?,
|
|
161
163
|
?, ?,
|
|
162
164
|
?, ?, ?, ?, ?,
|
|
163
|
-
?, ?, ?,
|
|
165
|
+
?, ?, ?, ?,
|
|
164
166
|
?, ?,
|
|
165
167
|
?,
|
|
166
168
|
?, ?, ?
|
|
@@ -177,6 +179,7 @@ function insertConnection(input: DbClientConnectionInput, ownerUserId: string |
|
|
|
177
179
|
params.ssh.password || null,
|
|
178
180
|
params.ssh.privateKey || null,
|
|
179
181
|
params.ssh.passphrase || null,
|
|
182
|
+
params.ssh.connectionId || null,
|
|
180
183
|
JSON.stringify(params.options),
|
|
181
184
|
params.color,
|
|
182
185
|
params.ownerUserId,
|
|
@@ -275,6 +278,7 @@ export const dbClientConnectionQueries = {
|
|
|
275
278
|
if (patch.ssh !== undefined) {
|
|
276
279
|
const merged: DbClientSshConfig = {
|
|
277
280
|
enabled: existing.ssh_enabled === 1,
|
|
281
|
+
connectionId: existing.ssh_connection_id,
|
|
278
282
|
host: existing.ssh_host ?? '',
|
|
279
283
|
port: existing.ssh_port ?? 22,
|
|
280
284
|
username: existing.ssh_username ?? '',
|
|
@@ -296,6 +300,7 @@ export const dbClientConnectionQueries = {
|
|
|
296
300
|
push('ssh_password', sshPassword);
|
|
297
301
|
push('ssh_private_key', sshPrivateKey);
|
|
298
302
|
push('ssh_passphrase', sshPassphrase);
|
|
303
|
+
push('ssh_connection_id', merged.connectionId || null);
|
|
299
304
|
}
|
|
300
305
|
|
|
301
306
|
push('updated_at', new Date().toISOString());
|
|
@@ -10,6 +10,9 @@ export { engineQueries } from './engine-queries';
|
|
|
10
10
|
export { authQueries } from './auth-queries';
|
|
11
11
|
export { dbClientConnectionQueries } from './db-client-connection-queries';
|
|
12
12
|
export { dbClientQueryHistoryQueries } from './db-client-query-history-queries';
|
|
13
|
+
export { sshConnectionQueries } from './ssh-connection-queries';
|
|
14
|
+
export { sshKnownHostQueries } from './ssh-known-host-queries';
|
|
15
|
+
export { sshPortForwardQueries } from './ssh-port-forward-queries';
|
|
13
16
|
export { auditLogQueries } from './audit-log-queries';
|
|
14
17
|
export { fileAuditLogQueries } from './file-audit-log-queries';
|
|
15
18
|
export { mcpServerQueries } from './mcp-server-queries';
|