fix(ipsec): восстановить создание клиентов и экспорт сертификатов
Docker images / prepare-release (push) Successful in 11s
Docker images / backend-test (push) Successful in 12m5s
Docker images / frontend-image (push) Successful in 2m29s
Docker images / updater-image (push) Successful in 40s
Docker images / netflow-agent-image (push) Successful in 32s
Docker images / backend-image (push) Successful in 2m16s
Docker images / publish-release (push) Successful in 11s
Docker images / notify-webhook (push) Successful in 2s

This commit is contained in:
Denozordec committed 2026-11-22 14:24:19 +07:00
1 parent 42efc3191b
commit 1af3755a77
11 files changed
+68 -27

No files matched your search

@@ -62,11 +62,17 @@ const router = createServer(async (req, res) => {
if (req.method === "GET") { res.end(JSON.stringify(catalogs[path] ?? [])); return }
let raw = ""; for await (const chunk of req) raw += chunk
const fields = raw ? JSON.parse(raw) as Row : {}
if (path === "/file/get" || path === "/file/print") { res.end(JSON.stringify({ ret: fakeP12 })); return }
if (path === "/file/get") {
assert(catalogs["/file"].some(row => row[".id"] === fields[".id"] && row[".id"].startsWith("**")))
res.end(JSON.stringify({ ret: fakeP12 }))
return
}
commands.push({ method: req.method!, path, ...(fields.name ? { name: fields.name } : {}) })
if (req.method === "POST" && path === "/certificate/export-certificate") {
assert(catalogs["/certificate"].some(row => row.name === fields.name))
catalogs["/file"].push({ ".id": `*new${++serial}`, name: `${fields["file-name"]}.p12`, size: String(Buffer.byteLength(fakeP12)), type: "file" })
const certificate = catalogs["/certificate"].find(row => row[".id"] === fields[".id"])
assert(certificate && !("name" in fields))
commands.at(-1)!.name = certificate.name
catalogs["/file"].push({ ".id": `**New${++serial}`, name: `${fields["file-name"]}.p12`, size: String(Buffer.byteLength(fakeP12)), type: "file" })
if (mode === "lost") { req.socket.destroy(); return }
} else if (req.method === "DELETE" && path.startsWith("/file/")) {
catalogs["/file"] = catalogs["/file"].filter(row => row[".id"] !== path.slice("/file/".length))
@@ -42,7 +42,11 @@ export async function acceptIpsecUserCreate(actor: AuthUser) {
if (req.method === "GET") { res.end(JSON.stringify(catalogs[path] ?? [])); return }
let raw = ""; for await (const chunk of req) raw += chunk
const fields = raw ? JSON.parse(raw) as Row : {}
if (path === "/file/get" || path === "/file/print") { res.end(JSON.stringify({ ret: fakeP12 })); return }
if (path === "/file/get") {
assert(catalogs["/file"].some(row => row[".id"] === fields[".id"] && row[".id"].startsWith("**")))
res.end(JSON.stringify({ ret: mode === "download-failed" ? "short" : fakeP12 }))
return
}
commands.push({ method: req.method!, path, fields })
// RouterOS 7.24 (stand probe 2026-11-21): no `comment` on /certificate; sign and export by `.id` only, no `name`/`days-valid`.
const refusal = req.method === "PUT" && path === "/certificate" && "comment" in fields ? "unknown parameter comment"
@@ -54,7 +58,7 @@ export async function acceptIpsecUserCreate(actor: AuthUser) {
if (path === "/certificate/sign") {
const row = catalogs["/certificate"].find(row => row[".id"] === fields[".id"]); assert(row)
Object.assign(row, { ca: fields.ca, "digest-algorithm": "sha256", fingerprint: "synthetic-fingerprint", "invalid-before": "2026-01-01", "invalid-after": "2030-01-01", "private-key": "true", "serial-number": "synthetic" })
} else if (path === "/certificate/export-certificate") assert(catalogs["/certificate"].some(row => row[".id"] === fields[".id"])), catalogs["/file"].push({ ".id": `*new${++serial}`, name: `${fields["file-name"]}.p12`, size: String(Buffer.byteLength(fakeP12)), type: "file" })
} else if (path === "/certificate/export-certificate") assert(catalogs["/certificate"].some(row => row[".id"] === fields[".id"])), catalogs["/file"].push({ ".id": `**New${++serial}`, name: `${fields["file-name"]}.p12`, size: String(Buffer.byteLength(fakeP12)), type: "file" })
else {
const catalog = Object.keys(catalogs).find(value => path === value || path.startsWith(value + "/")); assert(catalog)
if (req.method === "PUT") { result = { ".id": `*new${++serial}`, ...fields, "native-default": "NEVER_NATIVE_DEFAULT" }; catalogs[catalog].push(result) }
@@ -101,6 +105,7 @@ export async function acceptIpsecUserCreate(actor: AuthUser) {
const stored = (await query("SELECT * FROM mcp_artifacts WHERE id=$1", [saved.artifactId])).rows[0]; hidden(stored); assert.equal(stored.access_scope.kind, "ipsec-user-bundle"); assert(stored.expires_at.getTime() <= Date.now() + 900000)
const download = await portal.inject({ url: saved.downloadPath, headers }); assert.equal(download.statusCode, 200, download.body); assert.equal(download.headers["cache-control"], "private, no-store")
const bundle = download.json(); assert.equal(Buffer.from(bundle.contentB64, "base64").toString(), fakeP12); assert.equal(bundle.passphrase, "NEVER_EXPORT_PASSPHRASE")
assert.equal(JSON.parse(bundle.sswanContent).local.p12, bundle.contentB64)
assert.equal((await portal.inject({ url: saved.downloadPath, headers: { authorization: `Bearer ${token("other-owner")}` } })).statusCode, 403)
assert.equal((await portal.inject({ url: saved.downloadPath, headers: { authorization: `Bearer ${token(actor.id, ["mm:network:read"])}` } })).statusCode, 403)
const listing: { statusCode: number; body: string; json: () => { items: Array<{ id: string; artifactReceipts: Array<{ artifactId: string }> }> } } = await portal.inject({ url: `/api/mcp/operations?connectionId=${connectionId}`, headers }); assert.equal(listing.statusCode, 200, listing.body); hidden(listing.json()); assert(listing.json().items.find((row: { id: string }) => row.id === result.operation.id)!.artifactReceipts.some((row: { artifactId: string }) => row.artifactId === saved.artifactId))
@@ -110,6 +115,12 @@ export async function acceptIpsecUserCreate(actor: AuthUser) {
const response = await rest.inject({ method: "POST", url: "/api/ipsec/users", payload: { serverId, name: "Alice", authMethod, ...(staticIp ? { staticIp } : {}), ...(authMethod === "certificate" ? { daysValid: 365, passphrase: "NEVER_EXPORT_PASSPHRASE" } : { psk: "NEVER_PSK_SECRET", remoteId: "alice.example.test" }) } }); assert.equal(response.statusCode, 201, response.body)
assert.deepEqual(normalize(commands.slice(restStart)), accepted)
}
reset(); mode = "download-failed"
const failedExport = await rest.inject({ method: "POST", url: "/api/ipsec/users", payload: { serverId, name: "Alice", staticIp: "192.0.2.7" } })
assert.equal(failedExport.statusCode, 502, failedExport.body)
assert.equal(failedExport.json().state, "partial")
assert.deepEqual(catalogs["/ip/ipsec/identity"], base["/ip/ipsec/identity"])
assert.deepEqual(catalogs["/ip/ipsec/mode-config"], base["/ip/ipsec/mode-config"])
reset(); const rawStart = commands.length
for (const request of [{ name: "Alice" }, { name: "Alice", authMethod: "pre-shared-key", psk: "NEVER_RAW" }, { name: "Alice", privateKeyExport: true, staticIp: "bad" }]) await assert.rejects(prepare(request))
assert.equal(commands.length, rawStart)
@@ -148,5 +148,5 @@ export function createIpsecUserCreateAdapter(overrides: Partial<typeof productio
export function registerIpsecUserCreateActions(register: typeof add) {
const adapter = createIpsecUserCreateAdapter()
registerMcpService(operation, adapter.service)
register(operation, "mm_ipsec_user_create_plan", "Создать клиента IPsec с проверкой всех native-команд, явным приватным экспортом и managed-only историей", "network", "mm:network:write", "write", "servers", ipsecUserCreateActionSchema, { version: 3, prepare: adapter.prepare })
register(operation, "mm_ipsec_user_create_plan", "Создать клиента IPsec с проверкой всех native-команд, явным приватным экспортом и managed-only историей", "network", "mm:network:write", "write", "servers", ipsecUserCreateActionSchema, { version: 4, prepare: adapter.prepare })
}
@@ -10,7 +10,7 @@ assert.equal(findMcpOperation(fullFlowSettings.operation.id)?.version, 3)
assert.equal(fullFlowSettings.schema.safeParse({ settings: { collectorIp: "10.255.254.1", enabled: false, mapServiceMinSharePct: 0 } }).success, true)
assert.equal(fullFlowSettings.schema.safeParse({ topN: 10 }).success, false)
assert.equal(findAction("mm_netflow_host_keys_generate_plan").operation.id, "traffic.flow.settings.generate-keys")
assert.equal(findAction("mm_ipsec_user_create_plan").operation.version, 3)
assert.equal(findAction("mm_ipsec_user_create_plan").operation.version, 4)
assert.equal(findAction("mm_ipsec_server_init_plan").operation.version, 5)
// RouterOS 7.24 certificate bodies (no comment, sign/export by .id): earlier prepared plans need a new approval.
assert.equal(findAction("mm_ipsec_existing_certificate_export_plan").operation.version, 2)