Skip to content

Commit 2f5cf89

Browse files
committed
fix(daemon): stop an attested tenant from downgrading its own isolation
When the auth hook attests a tenant, isolation is the server's answer. The RPC handler was defaulting to `'tenant'` rather than deciding it, so a client that sent `sessionIsolation: 'none'` kept it: `scopeRequestSession` then returned early, the session never got its `<tenant>:` prefix, and the request landed in the `cwd:<hash>:` namespace instead — one the client names and another tenant can name too. An attested tenant now always gets tenant isolation, on both carriers, so a downstream consumer that reads the flag cannot see an isolation the meta just overrode. Stacked on #2382, which threads the attested/declared distinction this uses.
1 parent 527a56a commit 2f5cf89

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

‎src/daemon/__tests__/http-server-tenant-trust.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,35 @@ test('RPC: no hook configured keeps a client-declared flags.tenant unchanged (re
323323
});
324324
});
325325

326+
test('RPC: an attested tenant cannot downgrade its own session isolation', async (t) => {
327+
if (await skipWhenLoopbackUnavailable(t)) return;
328+
const root = mkdtempForTestSync('agent-device-tenant-trust-downgrade-');
329+
try {
330+
const hookPath = writeAttestingAuthHook(root);
331+
await withRpcServer(hookPath, async ({ baseUrl, observedRequests }) => {
332+
const response = await callRpc(baseUrl, {
333+
jsonrpc: '2.0',
334+
id: 'rpc-downgrade',
335+
method: 'agent_device.command',
336+
params: {
337+
command: 'session_list',
338+
positionals: [],
339+
// Both carriers `scopeRequestSession` reads, and both the ones downstream
340+
// consumers read: neither may survive as `none` under an attested tenant.
341+
meta: { tenantId: ATTESTED_TENANT_ID, sessionIsolation: 'none' },
342+
flags: { sessionIsolation: 'none' },
343+
},
344+
});
345+
assert.equal(response.status, 200);
346+
assert.equal(observedRequests[0]?.meta?.tenantId, ATTESTED_TENANT_ID);
347+
assert.equal(observedRequests[0]?.meta?.sessionIsolation, 'tenant');
348+
assert.equal(observedRequests[0]?.flags?.sessionIsolation, 'tenant');
349+
});
350+
} finally {
351+
fs.rmSync(root, { recursive: true, force: true });
352+
}
353+
});
354+
326355
test('aux route: a hook configured but silent on tenant refuses a client-declared header claiming another tenant', async (t) => {
327356
if (await skipWhenLoopbackUnavailable(t)) return;
328357
const root = mkdtempForTestSync('agent-device-tenant-trust-aux-');

‎src/daemon/server/http-server.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -755,18 +755,24 @@ export async function createDaemonHttpServer(options: {
755755
...daemonRequest.meta,
756756
tenantId: tenantTrust.tenantId,
757757
// Attestation is what partitions the session namespace: only an attested
758-
// tenant defaults this request to tenant isolation, so only then does
759-
// `scopeRequestSession` name the session `<tenant>:...`. The diagnostics
760-
// route reads the same distinction back out of `authorizeAuxiliaryHttpRequest`.
761-
sessionIsolation: tenantTrust.attested
762-
? (daemonRequest.meta?.sessionIsolation ??
763-
daemonRequest.flags?.sessionIsolation ??
764-
'tenant')
765-
: daemonRequest.meta?.sessionIsolation,
758+
// tenant gets tenant isolation, so only then does `scopeRequestSession`
759+
// name the session `<tenant>:...`. The diagnostics route reads the same
760+
// distinction back out of `authorizeAuxiliaryHttpRequest`.
761+
//
762+
// When the hook attested the tenant, isolation is the SERVER's answer and
763+
// the request does not get a say: honoring a client-supplied `'none'` here
764+
// dropped the prefix and dropped the caller into the `cwd:<hash>:` namespace
765+
// instead, which the client names and another tenant can name too.
766+
sessionIsolation: tenantTrust.attested ? 'tenant' : daemonRequest.meta?.sessionIsolation,
766767
};
767768
if (daemonRequest.flags?.tenant !== undefined) {
768769
daemonRequest.flags = { ...daemonRequest.flags, tenant: tenantTrust.tenantId };
769770
}
771+
// Consumers that read the flag rather than the meta (`session-doctor-options.ts`)
772+
// must not see the isolation the meta just overrode.
773+
if (tenantTrust.attested && daemonRequest.flags?.sessionIsolation !== undefined) {
774+
daemonRequest.flags = { ...daemonRequest.flags, sessionIsolation: 'tenant' };
775+
}
770776
daemonRequest = restrictRemoteHttpRequest(
771777
daemonRequest,
772778
authHook !== null,

0 commit comments

Comments
 (0)