@lsamien/yaoyao 0.4.77 → 0.4.78
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/README.md +7 -5
- package/THIRD_PARTY_NOTICES.md +8 -0
- package/bin/hermes-yaoyao.mjs +15 -2
- package/build-info.json +20 -3
- package/desktop/main.mjs +6 -2
- package/dist/assets/{AboutDialog-k7oUOua0.js → AboutDialog-jvhTP8-J.js} +2 -2
- package/dist/assets/AboutDialog-jvhTP8-J.js.map +1 -0
- package/dist/assets/BotAutomationsView-ktoci79V.js +2 -0
- package/dist/assets/{BotAutomationsView-CUaMkVfT.js.map → BotAutomationsView-ktoci79V.js.map} +1 -1
- package/dist/assets/{BotPluginsDialog-BqfqrWdq.js → BotPluginsDialog-H85RI-7P.js} +2 -2
- package/dist/assets/{BotPluginsDialog-BqfqrWdq.js.map → BotPluginsDialog-H85RI-7P.js.map} +1 -1
- package/dist/assets/{BotSettingsDialog-BfW0Jxhg.js → BotSettingsDialog-Ci_DZL4m.js} +5 -5
- package/dist/assets/{BotSettingsDialog-BfW0Jxhg.js.map → BotSettingsDialog-Ci_DZL4m.js.map} +1 -1
- package/dist/assets/ChatView-6cdLMsuy.js +2 -0
- package/dist/assets/ChatView-6cdLMsuy.js.map +1 -0
- package/dist/assets/ChatView-C_7_7olu.css +1 -0
- package/dist/assets/{ComputerPanel-D_wWUzlj.js → ComputerPanel-Dbwgx5n8.js} +2 -2
- package/dist/assets/{ComputerPanel-D_wWUzlj.js.map → ComputerPanel-Dbwgx5n8.js.map} +1 -1
- package/dist/assets/{ComputerViewerView-C2nS7MWX.js → ComputerViewerView-csnhRedK.js} +2 -2
- package/dist/assets/{ComputerViewerView-C2nS7MWX.js.map → ComputerViewerView-csnhRedK.js.map} +1 -1
- package/dist/assets/ConversationsView-CEO2SVGT.js +6 -0
- package/dist/assets/ConversationsView-CEO2SVGT.js.map +1 -0
- package/dist/assets/{ConversationsView-C_VZl5g2.css → ConversationsView-CHLGKsJt.css} +1 -1
- package/dist/assets/FilesView-t5jA-H2-.js +2 -0
- package/dist/assets/{FilesView-xOEZGSrD.js.map → FilesView-t5jA-H2-.js.map} +1 -1
- package/dist/assets/FloatingResourceSearch-3GOuDkuO.css +1 -0
- package/dist/assets/FloatingResourceSearch-BAYymuJV.js +9 -0
- package/dist/assets/FloatingResourceSearch-BAYymuJV.js.map +1 -0
- package/dist/assets/HistoryView-BqMSV9iC.js +2 -0
- package/dist/assets/HistoryView-BqMSV9iC.js.map +1 -0
- package/dist/assets/HistoryView-DlVfSP_p.css +1 -0
- package/dist/assets/KanbanView-CWwrwH9S.js +2 -0
- package/dist/assets/{KanbanView-DXJCj1E6.js.map → KanbanView-CWwrwH9S.js.map} +1 -1
- package/dist/assets/{LocalVmSettingsPanel-8wF6wA3P.js → LocalVmSettingsPanel-BXvZwFQP.js} +2 -2
- package/dist/assets/{LocalVmSettingsPanel-8wF6wA3P.js.map → LocalVmSettingsPanel-BXvZwFQP.js.map} +1 -1
- package/dist/assets/{RunnerSettingsPanel-DDEMgUS9.js → RunnerSettingsPanel-KkpIkkob.js} +2 -2
- package/dist/assets/{RunnerSettingsPanel-DDEMgUS9.js.map → RunnerSettingsPanel-KkpIkkob.js.map} +1 -1
- package/dist/assets/{StandaloneDialog-BN6RJ3uh.js → StandaloneDialog-D4BQqjpB.js} +2 -2
- package/dist/assets/{StandaloneDialog-BN6RJ3uh.js.map → StandaloneDialog-D4BQqjpB.js.map} +1 -1
- package/dist/assets/{UpdateCheckDialog-CZ6NZSkP.js → UpdateCheckDialog-Ct0bT6xU.js} +2 -2
- package/dist/assets/{UpdateCheckDialog-CZ6NZSkP.js.map → UpdateCheckDialog-Ct0bT6xU.js.map} +1 -1
- package/dist/assets/{WorkspaceKnowledgePanel-BA7yVvWK.js → WorkspaceKnowledgePanel-WBcPB49x.js} +2 -2
- package/dist/assets/{WorkspaceKnowledgePanel-BA7yVvWK.js.map → WorkspaceKnowledgePanel-WBcPB49x.js.map} +1 -1
- package/dist/assets/{WorkspaceRoutinesPanel-DgCqaACO.js → WorkspaceRoutinesPanel-JubUwGsV.js} +2 -2
- package/dist/assets/{WorkspaceRoutinesPanel-DgCqaACO.js.map → WorkspaceRoutinesPanel-JubUwGsV.js.map} +1 -1
- package/dist/assets/WorkspaceShell-0m4gg6AW.css +1 -0
- package/dist/assets/WorkspaceShell-Do2VAwIz.js +44 -0
- package/dist/assets/WorkspaceShell-Do2VAwIz.js.map +1 -0
- package/dist/assets/{WorkspaceView-jMPyO8oT.js → WorkspaceView-DTanioWW.js} +2 -2
- package/dist/assets/{WorkspaceView-jMPyO8oT.js.map → WorkspaceView-DTanioWW.js.map} +1 -1
- package/dist/assets/{docx-preview-Ba7Ciq-i.js → docx-preview-B1SjJgD_.js} +2 -2
- package/dist/assets/{docx-preview-Ba7Ciq-i.js.map → docx-preview-B1SjJgD_.js.map} +1 -1
- package/dist/assets/index-CWamgtSb.js +17 -0
- package/dist/assets/index-CWamgtSb.js.map +1 -0
- package/dist/assets/{pdf-C3k8l1DI.js → pdf-DVDddcFC.js} +2 -2
- package/dist/assets/{pdf-C3k8l1DI.js.map → pdf-DVDddcFC.js.map} +1 -1
- package/dist/assets/sessionOwnership-0hdKcwOs.js +4 -0
- package/dist/assets/sessionOwnership-0hdKcwOs.js.map +1 -0
- package/dist/assets/{sessionOwnership-BTz0Fyp5.css → sessionOwnership-CfO8CfmZ.css} +1 -1
- package/dist/assets/{viewModels-OLQqqyt3.js → viewModels-DKBqaDRg.js} +12 -12
- package/dist/assets/{viewModels-OLQqqyt3.js.map → viewModels-DKBqaDRg.js.map} +1 -1
- package/dist/index.html +1 -1
- package/dist-server/runner/agent.js +2 -2
- package/dist-server/server/app.js +15 -1
- package/dist-server/server/chatTranscriptStore.js +16 -0
- package/dist-server/server/config.js +3 -0
- package/dist-server/server/credentialVault/broker.js +272 -0
- package/dist-server/server/credentialVault/coordinator.js +297 -0
- package/dist-server/server/credentialVault/executor.js +1 -0
- package/dist-server/server/credentialVault/fixtureWebsiteExecutor.js +51 -0
- package/dist-server/server/credentialVault/index.js +49 -0
- package/dist-server/server/credentialVault/isolation.js +37 -0
- package/dist-server/server/credentialVault/privateFiles.js +17 -0
- package/dist-server/server/credentialVault/protectedExecutor.js +21 -0
- package/dist-server/server/credentialVault/schema.js +45 -0
- package/dist-server/server/credentialVault/sshExecutor.js +135 -0
- package/dist-server/server/credentialVault/store.js +308 -0
- package/dist-server/server/credentialVault/transport.js +127 -0
- package/dist-server/server/credentialVault/websiteExecutor.js +102 -0
- package/dist-server/server/localAuth.js +5 -0
- package/dist-server/server/openVikingSessionSync.js +148 -37
- package/dist-server/server/pushCoordinator.js +7 -4
- package/dist-server/server/routes.js +18 -0
- package/dist-server/server/runnerHub.js +14 -1
- package/dist-server/server/subaccountAccess.js +12 -0
- package/dist-server/server/unreadCenter.js +61 -0
- package/dist-server/server/uploads.js +4 -1
- package/dist-server/server/workspaceAssets.js +2 -1
- package/dist-server/server/workspaceRoutes.js +1 -1
- package/dist-server/server/workspaceRuntime.js +18 -2
- package/dist-server/server/workspaceStore.js +104 -43
- package/dist-server/shared/credentialVault.js +2 -0
- package/dist-server/shared/unread.js +6 -0
- package/dist-server/shared/uploadNames.js +14 -0
- package/licenses/libsodium.js/LICENSE +16 -0
- package/licenses/ssh2/LICENSE +19 -0
- package/package.json +4 -2
- package/release.json +3 -3
- package/dist/assets/AboutDialog-k7oUOua0.js.map +0 -1
- package/dist/assets/BotAutomationsView-CUaMkVfT.js +0 -2
- package/dist/assets/ChatView-CTWvNlNq.js +0 -2
- package/dist/assets/ChatView-CTWvNlNq.js.map +0 -1
- package/dist/assets/ChatView-Dx8YlcPr.css +0 -1
- package/dist/assets/ConversationsView-D5KvMs7J.js +0 -6
- package/dist/assets/ConversationsView-D5KvMs7J.js.map +0 -1
- package/dist/assets/FilesView-xOEZGSrD.js +0 -2
- package/dist/assets/FloatingResourceSearch-BF2XOLd-.css +0 -1
- package/dist/assets/FloatingResourceSearch-D5XwWF0V.js +0 -9
- package/dist/assets/FloatingResourceSearch-D5XwWF0V.js.map +0 -1
- package/dist/assets/HistoryView-CnUN9Qik.js +0 -2
- package/dist/assets/HistoryView-CnUN9Qik.js.map +0 -1
- package/dist/assets/HistoryView-DvuCAjlo.css +0 -1
- package/dist/assets/KanbanView-DXJCj1E6.js +0 -2
- package/dist/assets/WorkspaceShell-7wn8iTne.css +0 -1
- package/dist/assets/WorkspaceShell-DQZKvx2p.js +0 -44
- package/dist/assets/WorkspaceShell-DQZKvx2p.js.map +0 -1
- package/dist/assets/index-dvKMU4Xy.js +0 -17
- package/dist/assets/index-dvKMU4Xy.js.map +0 -1
- package/dist/assets/sessionOwnership-HZsbONG-.js +0 -6
- package/dist/assets/sessionOwnership-HZsbONG-.js.map +0 -1
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import Router from '@koa/router';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { HttpError } from '../errors.js';
|
|
6
|
+
import { CredentialVaultClient } from './transport.js';
|
|
7
|
+
import { parse, leaseInput } from './schema.js';
|
|
8
|
+
const toolSchema = { type: 'object', properties: { credentialRef: { type: 'string' }, operation: { enum: ['website.login', 'ssh.exec', 'sftp.read', 'sftp.write'] } }, required: ['credentialRef', 'operation'], additionalProperties: false };
|
|
9
|
+
export const CREDENTIAL_TOOLS = [
|
|
10
|
+
{ id: 'credential_refs', name: 'credential_refs', description: '列出用户授予当前 Bot/任务的凭据引用与允许目标,不包含账号密码或私钥。', inputSchema: { type: 'object', properties: {}, additionalProperties: false } },
|
|
11
|
+
{ id: 'credential_request', name: 'credential_request', description: '请求并使用当前任务的短凭据授权,只执行用户配置的标准网站表单、固定 SSH 命令或指定 SFTP 操作。锁定/离线时等待用户解锁与授权,隔离未批准或复杂网站转人工接管。不得索取或读取密码,不得降级 fill/shell;未知结果不能自动重试。', inputSchema: toolSchema },
|
|
12
|
+
];
|
|
13
|
+
/** The Web control plane never receives a read-secret response. Deployment must
|
|
14
|
+
* keep this process/IPC identity separate from Hermes' arbitrary shell identity. */
|
|
15
|
+
export class CredentialVaultCoordinator {
|
|
16
|
+
client;
|
|
17
|
+
store;
|
|
18
|
+
auth;
|
|
19
|
+
hub;
|
|
20
|
+
sessions = new Map();
|
|
21
|
+
grants = new Map();
|
|
22
|
+
pending = new Map();
|
|
23
|
+
generations = new Map();
|
|
24
|
+
logoutGenerations = new Map();
|
|
25
|
+
connectionGeneration = 0;
|
|
26
|
+
closed = false;
|
|
27
|
+
turnControllers = new Set();
|
|
28
|
+
timer;
|
|
29
|
+
constructor(client, store, auth, hub) {
|
|
30
|
+
this.client = client;
|
|
31
|
+
this.store = store;
|
|
32
|
+
this.auth = auth;
|
|
33
|
+
this.hub = hub;
|
|
34
|
+
client.onDisconnect = () => { this.connectionGeneration++; this.grants.clear(); this.sessions.clear(); };
|
|
35
|
+
this.timer = setInterval(() => {
|
|
36
|
+
for (const s of [...this.sessions.values()])
|
|
37
|
+
if (!this.valid(s))
|
|
38
|
+
void this.endSession(s);
|
|
39
|
+
for (const [id, g] of this.grants) {
|
|
40
|
+
try {
|
|
41
|
+
this.task(g.session.owner, g.summary.agentId, g.summary.workId);
|
|
42
|
+
const current = this.binding(g.session.owner, g.summary.agentId);
|
|
43
|
+
if (JSON.stringify(current) !== JSON.stringify(g.binding) || g.summary.expiresAt <= Date.now())
|
|
44
|
+
throw new Error();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
this.grants.delete(id);
|
|
48
|
+
void this.client.call(g.session.owner, g.session.key, 'revoke', { id }).catch(() => { });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, 1000);
|
|
52
|
+
this.timer.unref();
|
|
53
|
+
}
|
|
54
|
+
valid(s) { return this.auth.currentFromCookieHeader(s.cookie)?.id === s.owner && this.auth.isUserActive(s.owner) && this.auth.pushAuthorizationVersion(s.owner) === s.version; }
|
|
55
|
+
scope(ctx) {
|
|
56
|
+
if (this.closed)
|
|
57
|
+
throw new HttpError(503, '密码库连接已关闭', 'vault_offline');
|
|
58
|
+
const user = this.auth.require(ctx), cookie = ctx.get('cookie');
|
|
59
|
+
if (this.auth.currentFromCookieHeader(cookie)?.id !== user.id)
|
|
60
|
+
throw new HttpError(401, '当前会话已失效', 'vault_session_revoked');
|
|
61
|
+
const key = this.auth.sessionBinding(cookie);
|
|
62
|
+
if (!key)
|
|
63
|
+
throw new HttpError(401, '当前会话已失效', 'vault_session_revoked');
|
|
64
|
+
const s = { owner: user.id, key, cookie, version: this.auth.pushAuthorizationVersion(user.id) };
|
|
65
|
+
// Secrets may not traverse explicitly enabled insecure LAN HTTP.
|
|
66
|
+
const local = ['127.0.0.1', '::1', '::ffff:127.0.0.1'].includes(ctx.req.socket.remoteAddress ?? '');
|
|
67
|
+
if (!ctx.secure && !local)
|
|
68
|
+
throw new HttpError(403, '密码库管理需要 HTTPS 或本机回环连接', 'vault_https_required');
|
|
69
|
+
ctx.set('Cache-Control', 'no-store');
|
|
70
|
+
return s;
|
|
71
|
+
}
|
|
72
|
+
async call(s, command, value) {
|
|
73
|
+
if (!this.valid(s))
|
|
74
|
+
throw new HttpError(401, '当前会话已失效', 'vault_session_revoked');
|
|
75
|
+
const generation = this.generations.get(s.owner) ?? 0, logout = this.logoutGenerations.get(s.owner + ':' + s.key) ?? 0, connection = this.connectionGeneration;
|
|
76
|
+
const result = await this.client.call(s.owner, s.key, command, value);
|
|
77
|
+
if (!this.valid(s) || generation !== (this.generations.get(s.owner) ?? 0) || logout !== (this.logoutGenerations.get(s.owner + ':' + s.key) ?? 0) || connection !== this.connectionGeneration) {
|
|
78
|
+
await this.endSession(s);
|
|
79
|
+
throw new HttpError(401, '当前会话已失效', 'vault_session_revoked');
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
async endSession(s) {
|
|
84
|
+
if (this.sessions.get(s.owner)?.key === s.key)
|
|
85
|
+
this.sessions.delete(s.owner);
|
|
86
|
+
for (const [id, g] of this.grants)
|
|
87
|
+
if (g.session.key === s.key)
|
|
88
|
+
this.grants.delete(id);
|
|
89
|
+
await this.client.call(s.owner, s.key, 'logout').catch(() => { });
|
|
90
|
+
}
|
|
91
|
+
async logout(owner, cookie) {
|
|
92
|
+
const binding = this.auth.sessionBinding(cookie);
|
|
93
|
+
if (!binding)
|
|
94
|
+
return;
|
|
95
|
+
const key = owner + ':' + binding;
|
|
96
|
+
this.logoutGenerations.set(key, (this.logoutGenerations.get(key) ?? 0) + 1);
|
|
97
|
+
const s = this.sessions.get(owner);
|
|
98
|
+
if (s?.key === binding)
|
|
99
|
+
await this.endSession(s);
|
|
100
|
+
else
|
|
101
|
+
await this.client.call(owner, binding, 'logout').catch(() => { });
|
|
102
|
+
}
|
|
103
|
+
task(owner, agentId, workId) {
|
|
104
|
+
const agent = this.store.require(owner, 'agent', agentId), work = this.store.require(owner, 'turn', workId);
|
|
105
|
+
const run = this.store.require(owner, 'run', work.runId);
|
|
106
|
+
if (!this.auth.isUserActive(owner) || agent.archived || work.agentId !== agent.id || !['running', 'waiting'].includes(work.status) || work.cancelRequested || run.stopRequested
|
|
107
|
+
|| !this.auth.canUseSource(owner, agent.nodeId, agent.profile))
|
|
108
|
+
throw new HttpError(410, 'Bot 任务授权已结束', 'vault_task_revoked');
|
|
109
|
+
return { agent, work };
|
|
110
|
+
}
|
|
111
|
+
binding(owner, agentId) { return this.hub.credentialBinding(owner, this.store.require(owner, 'agent', agentId)); }
|
|
112
|
+
tasks(owner) {
|
|
113
|
+
return this.store.list(owner, 'turn').flatMap(w => {
|
|
114
|
+
try {
|
|
115
|
+
const { agent } = this.task(owner, w.agentId, w.id);
|
|
116
|
+
return [{ workId: w.id, agentId: agent.id, name: agent.name }];
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
offline() { return { protocol: 1, online: false, initialized: false, unlocked: false, execution: 'disabled', reason: 'vault_offline', entries: [], leases: [] }; }
|
|
124
|
+
async view(s) {
|
|
125
|
+
let status;
|
|
126
|
+
try {
|
|
127
|
+
status = await this.call(s, 'status');
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
if (!(e instanceof HttpError) || e.code !== 'vault_offline')
|
|
131
|
+
throw e;
|
|
132
|
+
status = this.offline();
|
|
133
|
+
}
|
|
134
|
+
return { ...status, tasks: this.tasks(s.owner), requests: [...this.pending.values()].filter(p => p.owner === s.owner).map(({ owner: _owner, ...p }) => p) };
|
|
135
|
+
}
|
|
136
|
+
router() {
|
|
137
|
+
const r = new Router(), root = '/api/app/vault';
|
|
138
|
+
r.get(root, async (ctx) => { ctx.body = await this.view(this.scope(ctx)); });
|
|
139
|
+
for (const command of ['initialize', 'unlock', 'lock', 'rotate', 'backup', 'restore'])
|
|
140
|
+
r.post(root + '/' + command, async (ctx) => {
|
|
141
|
+
const s = this.scope(ctx);
|
|
142
|
+
if (['unlock', 'lock', 'rotate'].includes(command))
|
|
143
|
+
this.generations.set(s.owner, (this.generations.get(s.owner) ?? 0) + 1);
|
|
144
|
+
if (['unlock', 'lock', 'rotate'].includes(command)) {
|
|
145
|
+
this.grants.forEach((g, id) => { if (g.session.owner === s.owner)
|
|
146
|
+
this.grants.delete(id); });
|
|
147
|
+
}
|
|
148
|
+
const result = await this.call(s, command, ctx.request.body ?? {});
|
|
149
|
+
if (command === 'unlock')
|
|
150
|
+
this.sessions.set(s.owner, s);
|
|
151
|
+
if (command === 'lock' || command === 'rotate')
|
|
152
|
+
this.sessions.delete(s.owner);
|
|
153
|
+
ctx.body = result;
|
|
154
|
+
});
|
|
155
|
+
r.post(root + '/entries', async (ctx) => { ctx.body = await this.call(this.scope(ctx), 'add', ctx.request.body); });
|
|
156
|
+
r.put(root + '/entries/:id', async (ctx) => {
|
|
157
|
+
const s = this.scope(ctx);
|
|
158
|
+
this.grants.forEach((g, id) => { if (g.summary.credentialRef === ctx.params.id && g.session.owner === s.owner)
|
|
159
|
+
this.grants.delete(id); });
|
|
160
|
+
ctx.body = await this.call(s, 'update', { id: ctx.params.id, entry: ctx.request.body });
|
|
161
|
+
});
|
|
162
|
+
r.delete(root + '/entries/:id', async (ctx) => {
|
|
163
|
+
const s = this.scope(ctx);
|
|
164
|
+
this.grants.forEach((g, id) => { if (g.summary.credentialRef === ctx.params.id && g.session.owner === s.owner)
|
|
165
|
+
this.grants.delete(id); });
|
|
166
|
+
ctx.body = await this.call(s, 'remove', { id: ctx.params.id });
|
|
167
|
+
});
|
|
168
|
+
r.post(root + '/leases', async (ctx) => {
|
|
169
|
+
const s = this.scope(ctx), body = parse(z.object({ credentialRef: z.string().uuid(), agentId: z.string().uuid(), workId: z.string().uuid(),
|
|
170
|
+
operation: leaseInput.shape.operation, seconds: leaseInput.shape.seconds }).strict(), ctx.request.body);
|
|
171
|
+
this.task(s.owner, body.agentId, body.workId);
|
|
172
|
+
const binding = this.binding(s.owner, body.agentId), state = await this.call(s, 'status'), entry = state.entries.find(e => e.id === body.credentialRef);
|
|
173
|
+
if (!entry)
|
|
174
|
+
throw new HttpError(403, '请解锁并选择当前账号的凭据', 'vault_credential_forbidden');
|
|
175
|
+
const summary = await this.call(s, 'grant', { ...body, ...binding, target: entry.target });
|
|
176
|
+
try {
|
|
177
|
+
this.task(s.owner, body.agentId, body.workId);
|
|
178
|
+
if (JSON.stringify(this.binding(s.owner, body.agentId)) !== JSON.stringify(binding))
|
|
179
|
+
throw new Error();
|
|
180
|
+
this.grants.set(summary.id, { summary, target: entry.target, usage: entry.usage, session: s, binding });
|
|
181
|
+
ctx.body = summary;
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
await this.client.call(s.owner, s.key, 'revoke', { id: summary.id }).catch(() => { });
|
|
185
|
+
throw new HttpError(410, '任务或执行节点已变化,授权未保留', 'vault_task_revoked');
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
r.delete(root + '/leases/:id', async (ctx) => {
|
|
189
|
+
const s = this.scope(ctx);
|
|
190
|
+
this.grants.delete(ctx.params.id);
|
|
191
|
+
ctx.body = await this.call(s, 'revoke', { id: ctx.params.id });
|
|
192
|
+
});
|
|
193
|
+
return r;
|
|
194
|
+
}
|
|
195
|
+
openTurn(owner, agentId, workId, externalSignal, authorize, waiting) {
|
|
196
|
+
const controller = new AbortController(), signal = AbortSignal.any([externalSignal, controller.signal]), pendingIds = new Set();
|
|
197
|
+
let waitingCalls = 0;
|
|
198
|
+
this.turnControllers.add(controller);
|
|
199
|
+
const check = () => { signal.throwIfAborted(); if (this.closed)
|
|
200
|
+
throw new HttpError(503, '密码库连接已关闭', 'vault_offline'); authorize(); this.task(owner, agentId, workId); };
|
|
201
|
+
const abort = () => {
|
|
202
|
+
this.turnControllers.delete(controller);
|
|
203
|
+
for (const id of pendingIds)
|
|
204
|
+
this.pending.delete(id);
|
|
205
|
+
for (const [key, g] of this.grants)
|
|
206
|
+
if (g.summary.workId === workId && g.session.owner === owner)
|
|
207
|
+
this.grants.delete(key);
|
|
208
|
+
const s = this.sessions.get(owner);
|
|
209
|
+
if (s)
|
|
210
|
+
void this.client.call(owner, s.key, 'revoke-work', { workId }).catch(() => { });
|
|
211
|
+
};
|
|
212
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
213
|
+
const refs = async () => {
|
|
214
|
+
const binding = this.binding(owner, agentId), entries = [];
|
|
215
|
+
for (const g of this.grants.values()) {
|
|
216
|
+
if (g.session.owner !== owner || g.summary.agentId !== agentId || g.summary.workId !== workId || g.summary.expiresAt <= Date.now()
|
|
217
|
+
|| !this.valid(g.session) || JSON.stringify(g.binding) !== JSON.stringify(binding))
|
|
218
|
+
continue;
|
|
219
|
+
const state = await this.call(g.session, 'status');
|
|
220
|
+
check();
|
|
221
|
+
if (state.unlocked && state.leases.some(l => l.id === g.summary.id))
|
|
222
|
+
entries.push({ credentialRef: g.summary.credentialRef, operation: g.summary.operation, allowedTarget: g.target, ...(g.usage ? { allowedUse: g.usage } : {}) });
|
|
223
|
+
}
|
|
224
|
+
return entries;
|
|
225
|
+
};
|
|
226
|
+
return { close: () => { controller.abort(); signal.removeEventListener('abort', abort); },
|
|
227
|
+
call: async (name, value) => {
|
|
228
|
+
check();
|
|
229
|
+
if (name === 'credential_refs') {
|
|
230
|
+
parse(z.object({}).strict(), value);
|
|
231
|
+
return { references: await refs() };
|
|
232
|
+
}
|
|
233
|
+
if (name !== 'credential_request')
|
|
234
|
+
throw new HttpError(404, '凭据工具不存在', 'vault_command_unknown');
|
|
235
|
+
const b = parse(z.object({ credentialRef: z.string().uuid(), operation: leaseInput.shape.operation }).strict(), value);
|
|
236
|
+
const id = randomUUID();
|
|
237
|
+
pendingIds.add(id);
|
|
238
|
+
this.pending.set(id, { owner, agentId, workId, ...b });
|
|
239
|
+
if (++waitingCalls === 1)
|
|
240
|
+
waiting(true);
|
|
241
|
+
try {
|
|
242
|
+
let initialBinding;
|
|
243
|
+
// Bounded waiting is a state, never permission to execute or replay.
|
|
244
|
+
const end = Date.now() + 120000;
|
|
245
|
+
while (Date.now() < end) {
|
|
246
|
+
check();
|
|
247
|
+
try {
|
|
248
|
+
const binding = this.binding(owner, agentId);
|
|
249
|
+
if (initialBinding && JSON.stringify(binding) !== JSON.stringify(initialBinding))
|
|
250
|
+
throw new HttpError(410, '节点重连后需要新的任务授权', 'vault_connection_revoked');
|
|
251
|
+
initialBinding ??= binding;
|
|
252
|
+
const g = [...this.grants.values()].find(g => g.session.owner === owner && g.summary.workId === workId && g.summary.credentialRef === b.credentialRef && g.summary.operation === b.operation);
|
|
253
|
+
if (g) {
|
|
254
|
+
if (!this.valid(g.session) || g.summary.expiresAt <= Date.now() || JSON.stringify(g.binding) !== JSON.stringify(binding))
|
|
255
|
+
throw new HttpError(410, '凭据任务授权已结束', 'vault_lease_revoked');
|
|
256
|
+
const state = await this.call(g.session, 'status');
|
|
257
|
+
check();
|
|
258
|
+
if (state.unlocked && state.leases.some(l => l.id === g.summary.id)) {
|
|
259
|
+
if (JSON.stringify(this.binding(owner, agentId)) !== JSON.stringify(binding))
|
|
260
|
+
throw new HttpError(410, '节点重连后需要新授权', 'vault_connection_revoked');
|
|
261
|
+
if (state.execution === 'dummy-fixture' || state.execution === 'protected-adapters') {
|
|
262
|
+
try {
|
|
263
|
+
const result = await this.call(g.session, 'execute', { id: g.summary.id, input: { ...b, agentId, workId, ...binding, target: g.target, seconds: 60 } });
|
|
264
|
+
check();
|
|
265
|
+
if (JSON.stringify(this.binding(owner, agentId)) !== JSON.stringify(binding))
|
|
266
|
+
throw new HttpError(409, '执行端在回执确认前变化,结果未知;不能自动重试', 'vault_operation_uncertain');
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
this.grants.delete(g.summary.id);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return { status: 'manual_takeover_required', reason: 'vault_executor_not_enabled', message: '正式网站/SSH 受保护执行器尚未启用;请人工接管,不能使用通用 fill 或 shell 替代。' };
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
if (!(e instanceof HttpError) || !['vault_offline', 'vault_runner_offline', 'vault_locked'].includes(e.code))
|
|
279
|
+
throw e;
|
|
280
|
+
}
|
|
281
|
+
await delay(1000, undefined, { signal });
|
|
282
|
+
}
|
|
283
|
+
return { status: 'waiting_for_user', reason: 'vault_locked_or_offline', message: '仍需用户连接、解锁和本任务授权;未执行登录。' };
|
|
284
|
+
}
|
|
285
|
+
finally {
|
|
286
|
+
this.pending.delete(id);
|
|
287
|
+
pendingIds.delete(id);
|
|
288
|
+
if (--waitingCalls === 0)
|
|
289
|
+
waiting(false);
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
close() { this.closed = true; clearInterval(this.timer); for (const c of this.turnControllers)
|
|
295
|
+
c.abort(); this.turnControllers.clear(); this.grants.clear(); this.pending.clear(); for (const s of this.sessions.values())
|
|
296
|
+
void this.endSession(s); this.sessions.clear(); }
|
|
297
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** A working, deliberately local-only HTTPS login adapter for dummy integration
|
|
2
|
+
* fixtures. Not wired into the production CLI and not a generic browser login.
|
|
3
|
+
* It never uses global fetch/proxies, redirects, shell, CDP or model form input. */
|
|
4
|
+
import { request } from 'node:https';
|
|
5
|
+
export class FixtureWebsiteLoginExecutor {
|
|
6
|
+
ca;
|
|
7
|
+
origin;
|
|
8
|
+
constructor(origin, ca) {
|
|
9
|
+
this.ca = ca;
|
|
10
|
+
const u = new URL(origin);
|
|
11
|
+
if (u.protocol !== 'https:' || u.hostname !== '127.0.0.1' || u.username || u.password || u.pathname !== '/' || u.search || u.hash || !u.port)
|
|
12
|
+
throw new Error('dummy executor requires exact loopback HTTPS origin');
|
|
13
|
+
this.origin = u.origin;
|
|
14
|
+
}
|
|
15
|
+
send(path, signal, body, cookie) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
signal.throwIfAborted();
|
|
18
|
+
const req = request(new URL(path, this.origin), { method: body ? 'POST' : 'GET', ca: this.ca, rejectUnauthorized: true, signal,
|
|
19
|
+
agent: false, headers: { ...(body ? { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(body) } : {}), ...(cookie ? { Cookie: cookie } : {}) } }, res => {
|
|
20
|
+
let size = 0;
|
|
21
|
+
const chunks = [];
|
|
22
|
+
res.on('data', chunk => { size += chunk.length; if (size > 8192)
|
|
23
|
+
req.destroy(new Error('dummy response limit'));
|
|
24
|
+
else
|
|
25
|
+
chunks.push(Buffer.from(chunk)); });
|
|
26
|
+
res.on('error', reject);
|
|
27
|
+
res.on('aborted', () => reject(new Error('dummy response interrupted')));
|
|
28
|
+
res.on('end', () => resolve({ status: res.statusCode ?? 0, cookies: res.headers['set-cookie'] ?? [], body: Buffer.concat(chunks).toString() }));
|
|
29
|
+
});
|
|
30
|
+
req.setTimeout(3000, () => req.destroy(new Error('dummy login timeout')));
|
|
31
|
+
req.on('error', reject);
|
|
32
|
+
req.end(body);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async execute(entry, input, signal) {
|
|
36
|
+
if (input.operation !== 'website.login' || entry.target.kind !== 'website' || input.target.kind !== 'website' || entry.target.origin !== this.origin || input.target.origin !== this.origin)
|
|
37
|
+
throw new Error('dummy login target forbidden');
|
|
38
|
+
const form = new URLSearchParams({ username: entry.username, password: entry.secret }).toString();
|
|
39
|
+
const login = await this.send('/login', signal, form);
|
|
40
|
+
if (login.status !== 200)
|
|
41
|
+
throw new Error('dummy login rejected'); // Never follow redirects.
|
|
42
|
+
const cookie = login.cookies.map(v => v.split(';')[0]).find(v => /^fixture_auth=[a-f0-9]{64}$/.test(v));
|
|
43
|
+
if (!cookie)
|
|
44
|
+
throw new Error('dummy authentication receipt missing');
|
|
45
|
+
signal.throwIfAborted();
|
|
46
|
+
const proof = await this.send('/protected', signal, undefined, cookie);
|
|
47
|
+
if (proof.status !== 200 || proof.body !== 'dummy-authenticated')
|
|
48
|
+
throw new Error('dummy authenticated session unverified');
|
|
49
|
+
signal.throwIfAborted(); // No cookies, body, username or password returned to the Bot.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Operator-started foreground service. Never started by Web/Runner or the model.
|
|
2
|
+
* No setup of OS users, permissions, service manager or network rules is performed. */
|
|
3
|
+
import { chmodSync } from 'node:fs';
|
|
4
|
+
import { isAbsolute } from 'node:path';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { parse } from './schema.js';
|
|
7
|
+
import { CredentialVaultStore } from './store.js';
|
|
8
|
+
import { CredentialVaultBroker } from './broker.js';
|
|
9
|
+
import { serveCredentialVault } from './transport.js';
|
|
10
|
+
import { acquireServiceInstance } from '../serviceInstance.js';
|
|
11
|
+
import { readPrivateUtf8 } from './privateFiles.js';
|
|
12
|
+
import { OperatorIsolationGate } from './isolation.js';
|
|
13
|
+
import { ProtectedCredentialExecutor } from './protectedExecutor.js';
|
|
14
|
+
try {
|
|
15
|
+
const index = process.argv.indexOf('--config'), path = index < 0 ? undefined : process.argv[index + 1];
|
|
16
|
+
if (!path)
|
|
17
|
+
throw new Error('用法:node credentialVault/index.js --config /私有路径/vault.json');
|
|
18
|
+
const config = parse(z.object({ home: z.string().refine(isAbsolute), socket: z.string().refine(isAbsolute), tokenFile: z.string().refine(isAbsolute),
|
|
19
|
+
hermesUid: z.number().int().positive(), execution: z.object({ approvalFile: z.string().refine(isAbsolute), hermesPid: z.number().int().positive(), home: z.string().refine(isAbsolute) }).strict().optional() }).strict(), JSON.parse(readPrivateUtf8(path, 8192)));
|
|
20
|
+
if (!process.getuid || process.getuid() === 0 || process.getuid() === config.hermesUid)
|
|
21
|
+
throw new Error('密码库需要独立非 root OS 身份,不能与 Hermes 同用户运行');
|
|
22
|
+
const controlToken = readPrivateUtf8(config.tokenFile, 4096).trim();
|
|
23
|
+
const store = await CredentialVaultStore.create(config.home);
|
|
24
|
+
process.umask(0o077);
|
|
25
|
+
const instance = acquireServiceInstance(store.root, 'credential-vault-v1');
|
|
26
|
+
const executor = config.execution ? new ProtectedCredentialExecutor(config.execution.home, new OperatorIsolationGate(config.execution.approvalFile, config.hermesUid, config.execution.hermesPid)) : undefined;
|
|
27
|
+
const broker = new CredentialVaultBroker(store, Date.now, executor);
|
|
28
|
+
const server = serveCredentialVault(broker, controlToken);
|
|
29
|
+
process.once('exit', () => { broker.close(); instance.release(); });
|
|
30
|
+
server.listen(config.socket, () => {
|
|
31
|
+
try {
|
|
32
|
+
chmodSync(config.socket, 0o600);
|
|
33
|
+
process.stdout.write('密码库私有服务已启动,默认锁定;执行能力以专用管理界面状态为准\n');
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
broker.close();
|
|
37
|
+
server.close();
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const stop = () => { broker.close(); server.close(() => { instance.release(); }); server.closeAllConnections(); };
|
|
42
|
+
server.once('error', () => { stop(); process.exitCode = 1; process.stderr.write('密码库私有服务无法监听,请检查路径或已有实例\n'); });
|
|
43
|
+
process.once('SIGTERM', stop);
|
|
44
|
+
process.once('SIGINT', stop);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
process.stderr.write('密码库启动失败,请检查私有配置和独立 OS 身份;不会自动修改系统设置\n');
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { readPrivateUtf8 } from './privateFiles.js';
|
|
4
|
+
import { parse } from './schema.js';
|
|
5
|
+
import { HttpError } from '../errors.js';
|
|
6
|
+
const controls = ['separate-identity', 'hermes-no-control-access', 'browser-private-no-cdp', 'restricted-egress'];
|
|
7
|
+
const approval = z.object({ version: z.literal(1), approved: z.literal(true), brokerUid: z.number().int().positive(), hermesUid: z.number().int().positive(), hermesPid: z.number().int().positive(),
|
|
8
|
+
approvedAt: z.number().int().positive(), expiresAt: z.number().int().positive(), controls: z.array(z.enum(controls)).length(4) }).strict();
|
|
9
|
+
const processUid = (pid) => Number(execFileSync('/bin/ps', ['-o', 'uid=', '-p', String(pid)], { encoding: 'utf8', timeout: 2000, env: { PATH: '/usr/bin:/bin' } }).trim());
|
|
10
|
+
/** Manual operator approval is a deployment trust contract, NOT proof of OS,
|
|
11
|
+
* IPC/CDP/firewall isolation. Also checks the observable process identity.
|
|
12
|
+
* CLI uses the real probe; tests inject a dummy probe without inspecting users. */
|
|
13
|
+
export class OperatorIsolationGate {
|
|
14
|
+
path;
|
|
15
|
+
hermesUid;
|
|
16
|
+
hermesPid;
|
|
17
|
+
probe;
|
|
18
|
+
now;
|
|
19
|
+
constructor(path, hermesUid, hermesPid, probe = processUid, now = Date.now) {
|
|
20
|
+
this.path = path;
|
|
21
|
+
this.hermesUid = hermesUid;
|
|
22
|
+
this.hermesPid = hermesPid;
|
|
23
|
+
this.probe = probe;
|
|
24
|
+
this.now = now;
|
|
25
|
+
}
|
|
26
|
+
assert() {
|
|
27
|
+
try {
|
|
28
|
+
const a = parse(approval, JSON.parse(readPrivateUtf8(this.path, 8192))), uid = process.getuid?.();
|
|
29
|
+
if (!uid || uid !== a.brokerUid || uid === a.hermesUid || a.hermesUid !== this.hermesUid || a.hermesPid !== this.hermesPid || this.probe(a.hermesPid) !== a.hermesUid
|
|
30
|
+
|| a.approvedAt > this.now() || a.expiresAt <= this.now() || a.expiresAt - a.approvedAt > 31 * 86400000 || new Set(a.controls).size !== controls.length)
|
|
31
|
+
throw new Error();
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
throw new HttpError(503, '执行隔离尚未获得有效人工批准或身份已变化', 'vault_isolation_required');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { constants, openSync, fstatSync, readFileSync, closeSync } from 'node:fs';
|
|
2
|
+
/** Open first without following a final symlink, then check the actual inode. */
|
|
3
|
+
export function readPrivateUtf8(path, maxBytes) {
|
|
4
|
+
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
5
|
+
try {
|
|
6
|
+
const s = fstatSync(fd);
|
|
7
|
+
if (!s.isFile() || (s.mode & 0o077) || s.uid !== process.getuid?.() || s.size > maxBytes)
|
|
8
|
+
throw new Error('private file required');
|
|
9
|
+
const bytes = readFileSync(fd);
|
|
10
|
+
if (bytes.length > maxBytes)
|
|
11
|
+
throw new Error('private file size limit');
|
|
12
|
+
return bytes.toString('utf8');
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
closeSync(fd);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { mkdirSync, lstatSync } from 'node:fs';
|
|
2
|
+
import { WebsiteFormExecutor } from './websiteExecutor.js';
|
|
3
|
+
import { SshSftpExecutor } from './sshExecutor.js';
|
|
4
|
+
export class ProtectedCredentialExecutor {
|
|
5
|
+
gate;
|
|
6
|
+
mode = 'protected-adapters';
|
|
7
|
+
website;
|
|
8
|
+
ssh;
|
|
9
|
+
constructor(home, gate, testCA) {
|
|
10
|
+
this.gate = gate;
|
|
11
|
+
gate.assert();
|
|
12
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
13
|
+
const stat = lstatSync(home);
|
|
14
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || (stat.mode & 0o077) || stat.uid !== process.getuid?.())
|
|
15
|
+
throw new Error('private executor home required');
|
|
16
|
+
this.website = new WebsiteFormExecutor(home, gate, testCA);
|
|
17
|
+
this.ssh = new SshSftpExecutor(gate);
|
|
18
|
+
}
|
|
19
|
+
assertAvailable() { this.gate.assert(); }
|
|
20
|
+
execute(entry, input, signal) { this.gate.assert(); return entry.target.kind === 'website' ? this.website.execute(entry, input, signal) : this.ssh.execute(entry, input, signal); }
|
|
21
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { HttpError } from '../errors.js';
|
|
3
|
+
export const website = z.object({ kind: z.literal('website'), origin: z.string().max(2000).transform((value, ctx) => {
|
|
4
|
+
try {
|
|
5
|
+
const u = new URL(value);
|
|
6
|
+
if (u.protocol !== 'https:' || u.username || u.password || u.search || u.hash || (u.pathname !== '/' && u.pathname !== ''))
|
|
7
|
+
throw new Error();
|
|
8
|
+
return u.origin;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
ctx.addIssue({ code: 'custom', message: '网站需要准确的 HTTPS origin' });
|
|
12
|
+
return z.NEVER;
|
|
13
|
+
}
|
|
14
|
+
}) }).strict();
|
|
15
|
+
export const ssh = z.object({ kind: z.literal('ssh'), host: z.string().min(1).max(253).regex(/^[A-Za-z0-9.:[\]_-]+$/).transform(v => v.toLowerCase()),
|
|
16
|
+
port: z.number().int().min(1).max(65535), hostKey: z.string().regex(/^SHA256:[A-Za-z0-9+/]{43}=?$/) }).strict();
|
|
17
|
+
export const target = z.discriminatedUnion('kind', [website, ssh]);
|
|
18
|
+
const path = z.string().min(2).max(1024).refine(v => v.startsWith('/') && !v.includes('\\') && !/[\u0000-\u001f\u007f?#]/.test(v) && v.split('/').every((s, i) => i === 0 || !!s && s !== '.' && s !== '..'));
|
|
19
|
+
const name = z.string().min(1).max(100).regex(/^[A-Za-z][A-Za-z0-9_.:-]*$/);
|
|
20
|
+
const form = z.object({ kind: z.literal('website.form'), loginPath: path, submitPath: path, successPath: path, logoutPath: path.optional(), formId: name, usernameName: name, passwordName: name,
|
|
21
|
+
successSelector: z.string().min(1).max(256).regex(/^(#[A-Za-z][A-Za-z0-9_-]*|\[data-[a-z0-9-]+(?:="[A-Za-z0-9_-]+")?\])$/) }).strict();
|
|
22
|
+
const command = z.object({ kind: z.literal('ssh.exec'), command: z.string().max(512).regex(/^\/[A-Za-z0-9_/-]+$/).refine(v => !v.includes('//') && !v.endsWith('/')) }).strict();
|
|
23
|
+
const read = z.object({ kind: z.literal('sftp.read'), remotePath: path, maxBytes: z.number().int().min(1).max(1048576).default(65536) }).strict();
|
|
24
|
+
const write = z.object({ kind: z.literal('sftp.write'), remotePath: path, contents: z.string().max(65536) }).strict();
|
|
25
|
+
export const usage = z.discriminatedUnion('kind', [form, command, read, write]);
|
|
26
|
+
const updatedUsage = z.discriminatedUnion('kind', [form, command, read, write.extend({ contents: z.string().max(65536).optional() })]);
|
|
27
|
+
export const leaseInput = z.object({
|
|
28
|
+
credentialRef: z.string().uuid(), agentId: z.string().uuid(), workId: z.string().uuid(),
|
|
29
|
+
runnerId: z.string().uuid(), runnerInstance: z.string().uuid(), runnerEpoch: z.string().min(1).max(128),
|
|
30
|
+
operation: z.enum(['website.login', 'ssh.exec', 'sftp.read', 'sftp.write']), target,
|
|
31
|
+
seconds: z.number().int().min(15).max(120).default(60),
|
|
32
|
+
}).strict();
|
|
33
|
+
export const entryInput = z.object({ name: z.string().trim().min(1).max(120), username: z.string().min(1).max(256),
|
|
34
|
+
target, usage: usage.optional(), secret: z.string().min(1).max(32768), passphrase: z.string().max(4096).optional() }).strict();
|
|
35
|
+
export const updateInput = entryInput.extend({ secret: entryInput.shape.secret.optional(), usage: updatedUsage.optional(), revision: z.number().int().positive() });
|
|
36
|
+
export const storedEntry = entryInput.extend({ id: z.string().uuid(), revision: z.number().int().positive(), updatedAt: z.number().int().nonnegative() });
|
|
37
|
+
export function parse(schema, value) {
|
|
38
|
+
const result = schema.safeParse(value);
|
|
39
|
+
if (!result.success)
|
|
40
|
+
throw new HttpError(400, '密码库请求格式无效', 'vault_invalid_request');
|
|
41
|
+
return result.data;
|
|
42
|
+
}
|
|
43
|
+
export function masterPassword(value) {
|
|
44
|
+
return parse(z.string().min(12).max(1024), value);
|
|
45
|
+
}
|