feat(mcp): разрешить автономное выполнение планов сервисным ключом
Docker images / prepare-release (push) Successful in 14s
Docker images / backend-test (push) Failing after 3m16s
Docker images / backend-image (push) Skipped
Docker images / frontend-image (push) Successful in 2m47s
Docker images / updater-image (push) Successful in 39s
Docker images / netflow-agent-image (push) Successful in 32s
Docker images / publish-release (push) Skipped
Docker images / notify-webhook (push) Skipped
Docker images / prepare-release (push) Successful in 14s
Docker images / backend-test (push) Failing after 3m16s
Docker images / backend-image (push) Skipped
Docker images / frontend-image (push) Successful in 2m47s
Docker images / updater-image (push) Successful in 39s
Docker images / netflow-agent-image (push) Successful in 32s
Docker images / publish-release (push) Skipped
Docker images / notify-webhook (push) Skipped
This commit is contained in:
1 parent
26249e1a4d
commit
79ab7b45aa
18 files changed
+184
-60
No files matched your search
@@ -22,7 +22,7 @@ export interface VerifiedMcpServiceMetadata {
|
||||
}
|
||||
// `authorize` guards reads inside a stage and may reuse a recent proof; `authorizeWrite`, when given, is a
|
||||
// fresh check before every native or application write (each write is a stage boundary).
|
||||
interface VerifiedChange { active: boolean; actorId: string; connectionId: string; approved: boolean; serverIds: number[]; objects: McpObjectRef[]; serverWide: boolean; authorize?: () => Promise<void>; authorizeWrite?: () => Promise<void>; beforeDispatch?: () => Promise<void>; serviceExecution?:VerifiedMcpServiceMetadata }
|
||||
interface VerifiedChange { active: boolean; actorId: string; connectionId: string; approved: boolean; approvalSource?: "connection-policy" | null; serverIds: number[]; objects: McpObjectRef[]; serverWide: boolean; authorize?: () => Promise<void>; authorizeWrite?: () => Promise<void>; beforeDispatch?: () => Promise<void>; serviceExecution?:VerifiedMcpServiceMetadata }
|
||||
const verified = new AsyncLocalStorage<VerifiedChange>()
|
||||
declare const serviceExecutionBrand:unique symbol
|
||||
export type VerifiedMcpServiceExecution=Readonly<{[serviceExecutionBrand]:true}>
|
||||
@@ -136,7 +136,7 @@ export async function assertDatabaseRestoreAllowed() {
|
||||
const inherited = verified.getStore(), context = inherited?.active ? inherited : undefined
|
||||
const { rows } = await pool.query("SELECT object_ref FROM mcp_protections")
|
||||
for (const row of rows) {
|
||||
if (row.object_ref.protection === "deny" || !context?.approved) {
|
||||
if (row.object_ref.protection === "deny" || !context?.approved || context.approvalSource) {
|
||||
const code = row.object_ref.protection === "deny" ? "PROTECTED_OBJECT" : "APPROVAL_REQUIRED"
|
||||
await audit(pool, context?.actorId ?? actor.getStore() ?? "system", "configuration.denied", context?.connectionId ?? null, { domain: "database.restore", code })
|
||||
throw new McpError(code, "Полное восстановление затрагивает защищённый объект", 409)
|
||||
@@ -165,7 +165,7 @@ export async function executeGuardedConfigurationWrite<T>(serverId: number, meth
|
||||
// typed plan instead of guessing that their writes miss a protected object.
|
||||
const matches = !context || context.serverWide || protection.kind === "server" || context.objects.some(object => object.serverId === serverId && object.kind === protection.kind && object.id === protection.id)
|
||||
if (!matches) continue
|
||||
if (protection.protection === "deny" || !context?.approved) {
|
||||
if (protection.protection === "deny" || !context?.approved || context.approvalSource) {
|
||||
const code = protection.protection === "deny" ? "PROTECTED_OBJECT" : "APPROVAL_REQUIRED"
|
||||
await auditConfiguration(actorId, "configuration.denied", context?.connectionId ?? null, { serverId, method, path, code })
|
||||
throw new McpError(code, protection.protection === "deny" ? "Изменение заблокировано защитой объекта. Используйте план с проверкой зависимостей." : "Защищённый объект требует подтверждённого плана изменений.", 409)
|
||||
@@ -208,7 +208,7 @@ export async function executeGuardedApplicationWrite<T>(object: { kind: string;
|
||||
const { rows } = await pool.query("SELECT object_ref FROM mcp_protections WHERE object_ref->>'serverId'=ANY($1::text[]) OR (object_ref->>'kind'='server' AND object_ref->>'id'=ANY($1::text[])) OR (object_ref->>'kind'=$2 AND object_ref->>'id'=$3) OR EXISTS(SELECT 1 FROM jsonb_array_elements($4::jsonb) AS target WHERE target->>'kind'=object_ref->>'kind' AND target->>'id'=object_ref->>'id')", [serverIds.map(String), object.kind, object.id, JSON.stringify(objects)])
|
||||
for (const row of rows) {
|
||||
const protection = row.object_ref as { protection: string }
|
||||
if (protection.protection === "deny" || !context?.approved) {
|
||||
if (protection.protection === "deny" || !context?.approved || context.approvalSource) {
|
||||
await auditConfiguration(actorId, "configuration.denied", context?.connectionId ?? null, { domain: "application", object, serverIds })
|
||||
throw new McpError(protection.protection === "deny" ? "PROTECTED_OBJECT" : "APPROVAL_REQUIRED", "Изменение приложения затрагивает защищённый объект; нужен проверенный план", 409)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ const admissionSchema = z.object({ receipt_id: uuid, identity_kind: z.literal("m
|
||||
const operationSchema = z.object({ id: uuid, plan_id: uuid, connection_id: uuid, state: z.literal("applied"), verification: z.literal("passed"),
|
||||
error_code: z.null(), result: z.unknown(), created_at: time, finished_at: time }).passthrough()
|
||||
const planSchema = z.object({ id: uuid, connection_id: uuid, operation_id: z.literal("servers.poll"), operation_version: z.literal(1),
|
||||
state: z.literal("completed"), created_at: time, approved_by: actor, approved_at: time, expires_at: time, payload: sealed, evidence: sealed }).passthrough()
|
||||
state: z.literal("completed"), created_at: time, approved_by: actor, approved_at: time, expires_at: time, payload: sealed,
|
||||
evidence: sealed.extend({ approvalSource: z.literal("connection-policy").optional() }) }).passthrough()
|
||||
const stepSchema = z.object({ operation_id: uuid, step_index: z.literal(0), server_id: z.null(), state: z.literal("verified"), intended_state: z.unknown(),
|
||||
result: z.unknown(), finished_at: time }).passthrough()
|
||||
const inputSchema = z.object({ serverId: sid, receiptId: uuid, inputDigest: hash, bindingCiphertext: z.string().min(1).max(2097152) }).strict()
|
||||
|
||||
Reference in new issue
Block a user