feat(mcp): добавить диагностику инцидентов и проверку отказоустойчивости сети
Docker images / prepare-release (push) Successful in 12s
Docker images / backend-test (push) Successful in 10m31s
Docker images / frontend-image (push) Successful in 2m18s
Docker images / updater-image (push) Successful in 39s
Docker images / netflow-agent-image (push) Successful in 31s
Docker images / backend-image (push) Successful in 2m11s
Docker images / publish-release (push) Successful in 11s
Docker images / notify-webhook (push) Successful in 2s
Docker images / prepare-release (push) Successful in 12s
Docker images / backend-test (push) Successful in 10m31s
Docker images / frontend-image (push) Successful in 2m18s
Docker images / updater-image (push) Successful in 39s
Docker images / netflow-agent-image (push) Successful in 31s
Docker images / backend-image (push) Successful in 2m11s
Docker images / publish-release (push) Successful in 11s
Docker images / notify-webhook (push) Successful in 2s
This commit is contained in:
1 parent
c44bcd8f59
commit
b896e469a7
22 files changed
+1695
-28
No files matched your search
@@ -48,6 +48,17 @@ export async function verifyMcpFlowAnalytics(actor: AuthUser) {
|
||||
assert.equal((await read({offset:1,limit:1})).analytics.conversationsList.length,1)
|
||||
assert.equal((await read({interface:"analytics-in"})).analytics.bytes,100)
|
||||
assert.equal((await read({userId:users[0]})).analytics.bytes,100)
|
||||
const tuple = { srcIp: "::ffff:198.18.241.2", dstIp: "8.8.8.8", srcPort: 12345, dstPort: 443, protocol: 6 }
|
||||
result = await read({ ...tuple, limit: 1 })
|
||||
assert.equal(result.analytics.bytes, 200)
|
||||
assert.equal(result.analytics.admittedTotals, undefined)
|
||||
assert.equal(result.pages.conversationsList.total, 1)
|
||||
assert.equal(result.pages.conversationsList.nextOffset, null)
|
||||
assert.equal((await read({ ...tuple, offset: 1 })).analytics.conversationsList.length, 0)
|
||||
for (const mismatch of [{ srcIp: "198.18.241.9" }, { dstIp: "8.8.4.4" }, { srcPort: 12346 }, { dstPort: 0 }, { protocol: 17 }]) {
|
||||
assert.equal((await read({ ...tuple, ...mismatch })).analytics.bytes, 0)
|
||||
}
|
||||
for (const invalid of [{ srcIp: "198.18.241.0/24" }, { dstPort: 65536 }, { protocol: 256 }]) await assert.rejects(read(invalid))
|
||||
await put(110,"analytics-duplicate-in",50,"198.18.241.1")
|
||||
assert.equal((await read()).analytics.bytes,300)
|
||||
assert.equal((await read({dedup:false,excludeMesh:false,excludeOverlay:false})).analytics.bytes,350)
|
||||
|
||||
@@ -61,7 +61,18 @@ export async function verifyMcpTerminalDiagnostics(actor: AuthUser, app: Fastify
|
||||
assert.equal(fixture.requests.length, beforeDenied)
|
||||
await pool.query("UPDATE servers SET enabled=true WHERE id=$1", [sourceId])
|
||||
const interfaces = fixture.payloads["/interface"], logs = fixture.payloads["/log"], resource = fixture.payloads["/system/resource"]
|
||||
fixture.payloads["/interface"] = [{ ".id": "*1", name: "private-fixture", comment: `password=${password} token=NEVER_LOG_TOKEN`, type: "ether" }]
|
||||
fixture.payloads["/interface"] = [{ ".id": "*1", name: "private-fixture", comment: `password=${password} token=NEVER_LOG_TOKEN`, type: "ether", "rx-error": "7", "link-downs": "0" }]
|
||||
const typed = await invoke({ diagnostic: "interface_counters", interface: "private-fixture", limit: 1 }) as unknown as {
|
||||
interfaceCounters: { rows: { name: string; counters: { rxErrors: string; linkDowns: string } }[]; routerUptime: string; resetHistoryAvailable: boolean }
|
||||
}
|
||||
assert.equal(typed.interfaceCounters.rows[0].name, "private-fixture")
|
||||
assert.equal(typed.interfaceCounters.rows[0].counters.rxErrors, "7")
|
||||
assert.equal(typed.interfaceCounters.rows[0].counters.linkDowns, "0")
|
||||
assert.equal(typed.interfaceCounters.resetHistoryAvailable, false)
|
||||
assert.ok(typed.interfaceCounters.routerUptime)
|
||||
assert.ok(!JSON.stringify(typed).includes(password))
|
||||
await assert.rejects(invoke({ diagnostic: "interface_counters", count: 1 }))
|
||||
await assert.rejects(invoke({ diagnostic: "interfaces", interface: "private-fixture" }))
|
||||
const redacted = await invoke({ diagnostic: "interfaces" })
|
||||
assert.ok(!redacted.output.includes(password)); assert.ok(!redacted.output.includes("NEVER_LOG_TOKEN")); assert.ok(redacted.output.includes("[redacted]"))
|
||||
fixture.payloads["/log"] = [{ ".id": "*1", time: "0", topics: "system,info", message: `${password} password=NEVER_PRINT_LOG_PASSWORD token=NEVER_PRINT_LOG_TOKEN` }]
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { randomUUID } from "node:crypto"
|
||||
import { routeAiProfileSchema } from "@mmapp/contracts/mcp-routing"
|
||||
import { pool } from "../db/index.js"
|
||||
import { PATH_PROOF_VERSION, pathProofTag } from "../modules/mcp/path-proof-purpose.js"
|
||||
import { fingerprint, privateFingerprinter } from "../modules/mcp/security.js"
|
||||
|
||||
export async function assertSignedResilienceHistory({ connectionId, foreignConnectionId, serverId, callReport }: {
|
||||
connectionId: string
|
||||
foreignConnectionId?: string
|
||||
serverId: number
|
||||
callReport: (input: Record<string, unknown>) => Promise<unknown>
|
||||
}) {
|
||||
const profileId = randomUUID()
|
||||
const profile = routeAiProfileSchema.parse({
|
||||
name: "Failover acceptance", serverId, community: "65000:911", family: "ipv4",
|
||||
candidates: ["primary", "backup"].map(id => ({
|
||||
id, wanInterface: id + "-wan", downstreamInterface: id + "-down", jumpHostId: serverId, exitNodeId: serverId,
|
||||
gateway: "192.0.2.1", gatewayRef: { resource: "ipv4_route", id: "*a" },
|
||||
controlProbe: { targetInterface: id + "-exit", expectedHops: [{ serverId, interface: id + "-exit" }] },
|
||||
})),
|
||||
})
|
||||
const profileHash = fingerprint(profile)
|
||||
const sign = await privateFingerprinter("route-control-path-context-v1")
|
||||
const base = Date.now() - 60000
|
||||
const time = (offset: number) => new Date(base + offset).toISOString()
|
||||
const window = { from: time(0), outageAt: time(10000), restoreAt: time(20000), to: time(30000) }
|
||||
const run = () => callReport({
|
||||
target: { kind: "route-ai", profileId },
|
||||
controlProbe: { primaryCandidateId: "primary", backupCandidateId: "backup" },
|
||||
window, targetFailoverMs: 1500, targetFailbackMs: 1500,
|
||||
})
|
||||
const fixtureIds: string[] = []
|
||||
async function store(candidateId: string, status: "passed" | "failed", started: number, ended: number, owner = connectionId, epoch = "1") {
|
||||
const id = randomUUID()
|
||||
const dependencyProof = "f".repeat(64)
|
||||
const payload = {
|
||||
id, connectionId: owner, profileHash, candidateId, status, dependencyProof,
|
||||
proofPurpose: "control-path", proofVersion: PATH_PROOF_VERSION,
|
||||
startedAt: time(started), observedAt: time(ended), sourceProofs: [{ serverId, proof: epoch.repeat(64) }],
|
||||
}
|
||||
const proof = sign(pathProofTag("control-path") + fingerprint({ dependencyProof, value: payload }))
|
||||
await pool.query(
|
||||
"INSERT INTO mcp_path_checks(id,connection_id,profile_hash,candidate_id,status,evidence,created_at) VALUES ($1,$2,$3,$4,$5,$6::jsonb,$7)",
|
||||
[id, owner, profileHash, candidateId, status, JSON.stringify({ ...payload, proof }), payload.observedAt],
|
||||
)
|
||||
fixtureIds.push(id)
|
||||
return id
|
||||
}
|
||||
try {
|
||||
await pool.query(
|
||||
"INSERT INTO mcp_routing_profiles(id,connection_id,config,grant_expires_at) VALUES ($1,$2,$3::jsonb,$4)",
|
||||
[profileId, connectionId, JSON.stringify(profile), time(30000)],
|
||||
)
|
||||
const baseline = await store("primary", "passed", 8000, 9000)
|
||||
await store("primary", "failed", 10100, 10400)
|
||||
const firstGood = await store("backup", "passed", 10500, 11000)
|
||||
await store("primary", "passed", 20400, 20900)
|
||||
if (foreignConnectionId) await store("backup", "failed", 16000, 16500, foreignConnectionId)
|
||||
const passed = await run() as { status: string; baseline: { id: string }; failover: { firstGood: { id: string }; upperBoundMs: number }; serviceFailover: string; https: string; managementSsh: string }
|
||||
assert.equal(passed.status, "passed")
|
||||
assert.equal(passed.baseline.id, baseline)
|
||||
assert.equal(passed.failover.firstGood.id, firstGood)
|
||||
assert.equal(passed.failover.upperBoundMs, 1000)
|
||||
assert.equal(passed.serviceFailover, "inconclusive")
|
||||
assert.equal(passed.https, "inconclusive")
|
||||
assert.equal(passed.managementSsh, "inconclusive")
|
||||
|
||||
const moved = await store("backup", "passed", 13000, 13500, connectionId, "2")
|
||||
const changed = await run() as { status: string; reason: string }
|
||||
assert.equal(changed.status, "inconclusive")
|
||||
assert.equal(changed.reason, "SOURCE_IDENTITY_CHANGED")
|
||||
await pool.query("DELETE FROM mcp_path_checks WHERE id=$1", [moved])
|
||||
|
||||
await pool.query("UPDATE mcp_path_checks SET evidence=evidence-'proofPurpose' WHERE id=$1", [firstGood])
|
||||
const tampered = await run() as { status: string; reason: string }
|
||||
assert.equal(tampered.status, "inconclusive")
|
||||
assert.equal(tampered.reason, "INVALID_CONTROL_PATH_EVIDENCE")
|
||||
} finally {
|
||||
await pool.query("DELETE FROM mcp_path_checks WHERE id=ANY($1::uuid[])", [fixtureIds])
|
||||
await pool.query("DELETE FROM mcp_routing_profiles WHERE id=$1", [profileId])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user