mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 06:21:59 +09:00
fix(federation): a policy denial of a consequential inbound message is final in legacy and observe mode (#4511)
task-assignment, memory-query, context-share, trust-change, topology-change, agent-spawn, claim-event and agent-handoff are no longer delivered after the policy engine denied them, and are refused when the evaluator throws. Co-authored-by: r <r@x>
This commit is contained in:
1 parent
c0f205629b
commit
cb9d030fc1
2 files changed
+42
-5
No files matched your search
@@ -153,7 +153,7 @@ describe('dispatchInbound — happy path', () => {
|
||||
signatureVersion: 'jcs-v1',
|
||||
},
|
||||
});
|
||||
await dispatchInbound('a', jcs('task-assignment'), deps);
|
||||
await dispatchInbound('a', jcs('task-assignment'), { ...deps, authorizationMode: 'legacy' });
|
||||
await dispatchInbound('a', jcs('memory-query'), deps);
|
||||
await dispatchInbound('a', jcs('context-share'), deps);
|
||||
expect(events.map((e) => e.event)).toEqual([
|
||||
@@ -402,11 +402,38 @@ describe('dispatchInbound — inbound authorization', () => {
|
||||
expect(events).toEqual([]);
|
||||
});
|
||||
|
||||
it('observe evaluates and reports denial without blocking', async () => {
|
||||
it.each(['legacy', 'observe'] as const)('%s still refuses a denied task-assignment, agent-spawn or memory-query', async (mode) => {
|
||||
for (const type of ['task-assignment', 'agent-spawn', 'memory-query', 'trust-change', 'claim-event']) {
|
||||
const peer = mkPeer('alpha');
|
||||
const { deps, events } = withVerifier([peer], () => true);
|
||||
const result = await dispatchInbound('a', jcsMessage(type), {
|
||||
...deps,
|
||||
authorizationMode: mode,
|
||||
authorizeInbound: () => ({ allowed: false, reason: 'untrusted peer' }),
|
||||
});
|
||||
expect(result, type).toEqual({ accepted: false, reason: 'AUTHORIZATION_DENIED' });
|
||||
expect(events, type).toHaveLength(0);
|
||||
}
|
||||
});
|
||||
|
||||
it('legacy and observe refuse a consequential message when the evaluator throws', async () => {
|
||||
for (const mode of ['legacy', 'observe'] as const) {
|
||||
const { deps, events } = withVerifier([mkPeer('alpha')], () => true);
|
||||
const result = await dispatchInbound('a', jcsMessage('agent-spawn'), {
|
||||
...deps,
|
||||
authorizationMode: mode,
|
||||
authorizeInbound: () => { throw new Error('boom'); },
|
||||
});
|
||||
expect(result).toEqual({ accepted: false, reason: 'AUTHORIZATION_ERROR' });
|
||||
expect(events).toHaveLength(0);
|
||||
}
|
||||
});
|
||||
|
||||
it('observe evaluates and reports denial without blocking a low-risk message', async () => {
|
||||
const peer = mkPeer('alpha');
|
||||
const { deps, events } = withVerifier([peer], () => true);
|
||||
const authorizeInbound = vi.fn(() => ({ allowed: false, reason: 'would deny' }));
|
||||
const result = await dispatchInbound('a', jcsMessage(), {
|
||||
const result = await dispatchInbound('a', jcsMessage('status-broadcast'), {
|
||||
...deps,
|
||||
authorizationMode: 'observe',
|
||||
authorizeInbound,
|
||||
|
||||
@@ -26,6 +26,12 @@ import type { FederationNode } from '../domain/entities/federation-node.js';
|
||||
import { FederationNodeState } from '../domain/value-objects/federation-node-state.js';
|
||||
|
||||
/** What gets emitted on the event bus per messageType. */
|
||||
/** Message types whose policy denial is enforced even outside enforce mode. */
|
||||
const CONSEQUENTIAL_MESSAGE_TYPES: ReadonlySet<string> = new Set([
|
||||
'task-assignment', 'memory-query', 'context-share', 'trust-change',
|
||||
'topology-change', 'agent-spawn', 'claim-event', 'agent-handoff',
|
||||
]);
|
||||
|
||||
export const FEDERATION_INBOUND_EVENT_PREFIX = 'federation:inbound';
|
||||
|
||||
/** Reasons we reject an inbound message — constant strings, no oracle leak. */
|
||||
@@ -379,6 +385,10 @@ export async function dispatchInbound(
|
||||
}
|
||||
|
||||
const authorizationMode = deps.authorizationMode ?? 'legacy';
|
||||
// Message types that start work, read memory or change who is trusted. A denial
|
||||
// for one of these is final in every mode: legacy/observe only soften claim
|
||||
// checks for the rest, they never deliver what the policy engine refused.
|
||||
const consequential = CONSEQUENTIAL_MESSAGE_TYPES.has(message.type);
|
||||
if (
|
||||
authorizationMode !== 'legacy' &&
|
||||
authorizationMode !== 'observe' &&
|
||||
@@ -408,7 +418,7 @@ export async function dispatchInbound(
|
||||
}
|
||||
authorizationDecision = decision;
|
||||
} catch {
|
||||
if (authorizationMode === 'enforce') {
|
||||
if (authorizationMode === 'enforce' || consequential) {
|
||||
await deps.audit.log('message_rejected', {
|
||||
sourceNodeId,
|
||||
metadata: { address, reason: 'AUTHORIZATION_ERROR', messageType: message.type },
|
||||
@@ -430,7 +440,7 @@ export async function dispatchInbound(
|
||||
}
|
||||
|
||||
if (authorizationDecision && !authorizationDecision.allowed) {
|
||||
if (authorizationMode === 'enforce') {
|
||||
if (authorizationMode === 'enforce' || consequential) {
|
||||
await deps.audit.log('message_rejected', {
|
||||
sourceNodeId,
|
||||
metadata: {
|
||||
|
||||
Reference in new issue
Block a user