Skip to content

Commit cbef79b

Browse files
fix(plugins): require execution authority for management
Require credential administration and terminal execution scopes before plugin management handlers run; keep the client gate consistent and cover restricted credentials. Carry the matching plugin-layer CI repairs and correct the failed-context accessible-name assertion.
1 parent caefa4e commit cbef79b

43 files changed

Lines changed: 727 additions & 288 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/plugins/PluginNotificationBannerHost.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
1111
import { AccessibilityInfo, Platform, Pressable, View } from "react-native";
1212
import { useSafeAreaInsets } from "react-native-safe-area-context";
1313

14-
import { AppText as Text } from "../../components/AppText";
14+
import { AppText as Text } from "../../components/ui/AppText";
1515
import { cn } from "../../lib/cn";
1616
import { useEnvironments } from "../../state/environments";
1717
import { pluginNotificationEnvironment } from "../../state/plugin-notifications";

‎apps/mobile/src/features/plugins/PluginSettingsSections.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { EnvironmentId, ExecutionEnvironmentCapabilities } from "@t3tools/c
44
import * as Option from "effect/Option";
55
import { AsyncResult } from "effect/reactivity";
66

7-
import { AppText as Text } from "../../components/AppText";
7+
import { AppText as Text } from "../../components/ui/AppText";
88
import { pluginEnvironment } from "../../state/plugins";
99
import { PluginSettingsValues } from "./PluginSettingsValues";
1010

‎apps/mobile/src/features/plugins/PluginSettingsValues.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as Option from "effect/Option";
55
import { AsyncResult } from "effect/reactivity";
66
import { View } from "react-native";
77

8-
import { AppText as Text } from "../../components/AppText";
8+
import { AppText as Text } from "../../components/ui/AppText";
99
import { pluginSettingsEnvironment } from "../../state/plugins";
1010
import { SettingsSection } from "../settings/components/SettingsSection";
1111
import { describePluginSettingValue } from "./PluginSettingsValues.logic";

‎apps/mobile/src/features/settings/SettingsPluginsRouteScreen.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ import { useEffect, useRef } from "react";
3333
import { Platform, Pressable, View } from "react-native";
3434
import { useSafeAreaInsets } from "react-native-safe-area-context";
3535

36-
import { AppText as Text } from "../../components/AppText";
37-
import { SymbolView } from "../../components/AppSymbol";
36+
import { AppText as Text } from "../../components/ui/AppText";
37+
import { SymbolView } from "../../components/ui/AppSymbol";
3838
import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
39-
import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
39+
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
4040
import { usePluginActionsSnapshot } from "../../state/plugin-actions";
4141
import {
4242
pluginEnvironment,

‎apps/mobile/src/features/threads/ThreadContributionStatusStrip.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
import { useMemo } from "react";
99
import { Alert, Platform, Pressable, ScrollView, View } from "react-native";
1010

11-
import { AppText as Text } from "../../components/AppText";
11+
import { AppText as Text } from "../../components/ui/AppText";
1212
import { ProviderIcon } from "../../components/ProviderIcon";
1313
import { cn } from "../../lib/cn";
1414
import { contributionStatusEnvironment } from "../../state/contribution-status";

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
CLIENT_GUARDED_RPC_SCOPES,
3+
PLUGIN_MANAGEMENT_REQUIRED_SCOPES,
34
type DeviceListInput,
45
clientRpcRequiredScopes,
56
authScopeRequiredResponse,
@@ -117,8 +118,7 @@ export const RPC_REQUIRED_SCOPES = {
117118
// Delivery logs hold request bodies, so they need the same scope as the URL.
118119
[WS_METHODS.scheduledTasksListWebhookDeliveries]: AuthOrchestrationOperateScope,
119120
[WS_METHODS.scheduledTasksGetWebhookDelivery]: AuthOrchestrationOperateScope,
120-
// Plugins run as the server's OS user, so changing what runs takes the administrative scope
121-
// that also manages pairing and sessions; standard pairing never grants it.
121+
// Plugin management also requires execution authority; see requiredScopesForRpcCall.
122122
[WS_METHODS.pluginsList]: AuthOrchestrationReadScope,
123123
[WS_METHODS.pluginsSubscribe]: AuthOrchestrationReadScope,
124124
[WS_METHODS.pluginsAdd]: AuthAccessWriteScope,
@@ -273,10 +273,26 @@ const requiredScopesForSettingsUpdate = (payload: unknown) => {
273273

274274
const decodeProjectMutation = Schema.decodeUnknownSync(ProjectMutation);
275275

276+
const pluginManagementMethods: ReadonlySet<string> = new Set([
277+
WS_METHODS.pluginsAdd,
278+
WS_METHODS.pluginsRefresh,
279+
WS_METHODS.pluginsConsent,
280+
WS_METHODS.pluginsEnable,
281+
WS_METHODS.pluginsDisable,
282+
WS_METHODS.pluginsRemove,
283+
WS_METHODS.pluginsResume,
284+
WS_METHODS.pluginsSettingsUpdate,
285+
WS_METHODS.pluginsNpmAdd,
286+
WS_METHODS.pluginsNpmStageUpdate,
287+
WS_METHODS.pluginsNpmApplyUpdate,
288+
WS_METHODS.pluginsNpmDiscardUpdate,
289+
]);
290+
276291
const requiredScopesForRpcCall = (
277292
method: string,
278293
payload: unknown,
279294
): ReadonlyArray<AuthEnvironmentScope> => {
295+
if (pluginManagementMethods.has(method)) return PLUGIN_MANAGEMENT_REQUIRED_SCOPES;
280296
if (method === WS_METHODS.serverRetryResourceTelemetry) {
281297
return [AuthEnvironmentMaintainScope, AuthDiagnosticsReadScope];
282298
}

‎apps/server/src/plugins/PluginCatalog.test.ts‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,16 +538,18 @@ it.layer(NodeServices.layer)("PluginCatalog", (it) => {
538538

539539
describe("interrupted management", () => {
540540
/** An approved, enabled installation in a catalogue that can be restarted on the same database. */
541-
const enabledInStub = Effect.fn("enabledInStub")(function* () {
541+
const enabledInStub = Effect.fn("enabledInStub")(function* (
542+
fileSystem?: FileSystem.FileSystem,
543+
) {
542544
const stub = yield* makeStubSupervisor;
543545
const before = yield* Scope.make();
544-
const catalog = yield* startStubCatalog(before, stub.service);
546+
const catalog = yield* startStubCatalog(before, stub.service, fileSystem);
545547
const plugin = yield* preparePlugin("test.interrupted");
546548
const { installation } = yield* catalog.add({ directory: plugin.directory });
547549
const installationId = installation.installationId;
548550
yield* catalog.consent({ installationId, digest: installation.source!.digest });
549551
yield* catalog.enable({ installationId });
550-
return { stub, before, catalog, installationId };
552+
return { stub, before, catalog, installationId, directory: installation.directory };
551553
});
552554

553555
/** Starts the catalogue again and waits until its startup re-registration has run. */
@@ -622,6 +624,37 @@ it.layer(NodeServices.layer)("PluginCatalog", (it) => {
622624
),
623625
);
624626

627+
it.effect("waits for an interrupted stop before inspecting and enabling again", () =>
628+
withDatabase(
629+
Effect.gen(function* () {
630+
const fs = yield* makeHoldingFileSystem;
631+
const { stub, catalog, installationId, directory } = yield* enabledInStub(fs.fileSystem);
632+
const stopping = yield* makeHold;
633+
stub.holds.disable = stopping;
634+
const disabling = yield* catalog
635+
.disable({ installationId })
636+
.pipe(Effect.forkChild({ startImmediately: true }));
637+
yield* Deferred.await(stopping.reached);
638+
yield* Fiber.interrupt(disabling);
639+
640+
const inspection = yield* fs.holdDirectory(directory);
641+
const enabling = yield* catalog
642+
.enable({ installationId })
643+
.pipe(Effect.forkChild({ startImmediately: true }));
644+
const inspectedBeforeStop = yield* Deferred.isDone(inspection.reached);
645+
expect(stub.registrations.size).toBe(0);
646+
647+
yield* Deferred.succeed(stopping.release, undefined);
648+
yield* Deferred.await(inspection.reached);
649+
yield* Deferred.succeed(inspection.release, undefined);
650+
const { installation } = yield* Fiber.join(enabling);
651+
expect(inspectedBeforeStop).toBe(false);
652+
expect(installation).toMatchObject({ enabled: true, generation: 2 });
653+
expect(stub.registrations.size).toBe(1);
654+
}),
655+
),
656+
);
657+
625658
it.effect("keeps a remove whose caller left while the process stopped", () =>
626659
withDatabase(
627660
Effect.gen(function* () {

‎apps/server/src/plugins/PluginCatalog.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,9 @@ export const make = Effect.fn("PluginCatalog.make")(function* (
502502
`${directory} is already installed.`,
503503
existing.record.installationId,
504504
);
505-
const installationId = PluginInstallationId.make(yield* crypto.randomUUIDv4().pipe(Effect.orDie));
505+
const installationId = PluginInstallationId.make(
506+
yield* crypto.randomUUIDv4().pipe(Effect.orDie),
507+
);
506508
const at = yield* now;
507509
const record: PluginInstallationRecord = {
508510
installationId,
@@ -562,6 +564,8 @@ export const make = Effect.fn("PluginCatalog.make")(function* (
562564

563565
const enable = Effect.fn("PluginCatalog.enable")(function* (input: PluginInstallationInput) {
564566
const installation = yield* find(input.installationId);
567+
// A caller may have left disable while its process was still exiting.
568+
if (installation.stopping) yield* Fiber.join(installation.stopping);
565569
// Checked even when already enabled: changed bytes stop it and need consent again.
566570
const inspection = yield* reinspect(installation);
567571
if (inspection._tag === "failed")

‎apps/server/src/plugins/PluginCatalogRpc.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
AuthAccessWriteScope,
3+
AuthTerminalOperateScope,
34
type AuthEnvironmentScope,
45
AuthOrchestrationReadScope,
56
AuthRelayReadScope,
@@ -91,6 +92,35 @@ const callWrites = (client: Effect.Success<ReturnType<typeof makeClient>>) =>
9192
]);
9293

9394
describe("plugin RPC scopes", () => {
95+
it.effect.each([
96+
{ scopes: [AuthAccessWriteScope], missing: AuthTerminalOperateScope },
97+
{ scopes: [AuthTerminalOperateScope], missing: AuthAccessWriteScope },
98+
] as const)(
99+
"refuses management missing $missing before any handler runs",
100+
({ scopes, missing }) =>
101+
Effect.gen(function* () {
102+
const handled: Array<string> = [];
103+
const client = yield* makeClient(scopes, handled);
104+
for (const failure of yield* callWrites(client)) {
105+
expect(failure).toMatchObject({
106+
_tag: "EnvironmentAuthorizationError",
107+
requiredScope: missing,
108+
requiredPermission: missing,
109+
});
110+
}
111+
expect(handled).toEqual([]);
112+
}).pipe(Effect.scoped),
113+
);
114+
it.effect("allows management with credential and execution authority", () =>
115+
Effect.gen(function* () {
116+
const handled: Array<string> = [];
117+
const client = yield* makeClient([AuthAccessWriteScope, AuthTerminalOperateScope], handled);
118+
for (const failure of yield* callWrites(client))
119+
expect(failure._tag).toBe("PluginCatalogError");
120+
expect(handled).toEqual([...writes]);
121+
}).pipe(Effect.scoped),
122+
);
123+
94124
it.effect("lets a read-only pairing read the catalogue but not change what runs", () =>
95125
Effect.gen(function* () {
96126
const handled: Array<string> = [];

‎apps/server/src/plugins/PluginNpmRpc.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
AuthAccessWriteScope,
3+
AuthTerminalOperateScope,
34
type AuthEnvironmentScope,
45
AuthOrchestrationReadScope,
56
AuthRelayReadScope,
@@ -85,6 +86,35 @@ const callWrites = (client: Effect.Success<ReturnType<typeof makeClient>>) =>
8586
]);
8687

8788
describe("npm plugin RPC scopes", () => {
89+
it.effect.each([
90+
{ scopes: [AuthAccessWriteScope], missing: AuthTerminalOperateScope },
91+
{ scopes: [AuthTerminalOperateScope], missing: AuthAccessWriteScope },
92+
] as const)(
93+
"refuses management missing $missing before any handler runs",
94+
({ scopes, missing }) =>
95+
Effect.gen(function* () {
96+
const handled: Array<string> = [];
97+
const client = yield* makeClient(scopes, handled);
98+
for (const failure of yield* callWrites(client)) {
99+
expect(failure).toMatchObject({
100+
_tag: "EnvironmentAuthorizationError",
101+
requiredScope: missing,
102+
requiredPermission: missing,
103+
});
104+
}
105+
expect(handled).toEqual([]);
106+
}).pipe(Effect.scoped),
107+
);
108+
it.effect("allows management with credential and execution authority", () =>
109+
Effect.gen(function* () {
110+
const handled: Array<string> = [];
111+
const client = yield* makeClient([AuthAccessWriteScope, AuthTerminalOperateScope], handled);
112+
for (const failure of yield* callWrites(client))
113+
expect(failure._tag).toBe("PluginCatalogError");
114+
expect(handled).toEqual([...writes]);
115+
}).pipe(Effect.scoped),
116+
);
117+
88118
it.effect("lets a read-only pairing list npm packages but not install or update them", () =>
89119
Effect.gen(function* () {
90120
const handled: Array<string> = [];

0 commit comments

Comments
 (0)