feat: connect policy hook so plugins can require approved access

This commit is contained in:
LukeGus committed 2026-11-05 22:28:38 -06:00
1 parent 1f5a19f54d
commit 67b70f8a97
20 files changed
+549 -7

No files matched your search

@@ -8,6 +8,7 @@ import {
requireSshAuthProvider,
} from "./auth-provider-registry.js";
import { ensureCoreSshAuthProviders } from "./core-providers.js";
import { ConnectPolicyError, assertConnectAllowed } from "../connect-policy.js";
import type {
MutableConnectConfig,
SshAuthEnv,
@@ -113,6 +114,8 @@ export interface BuildConnectConfigOptions {
/** Terminal socket for the changed-host-key prompt. */
hostKeySocket?: WebSocket | null;
interactive?: boolean;
/** Plugin id that asked for the connection, or "core". For connect policies. */
origin?: string;
log?: SshAuthLog;
/** Applied after the purpose defaults and before auth is prepared. */
overrides?: Partial<MutableConnectConfig>;
@@ -197,6 +200,35 @@ export async function buildConnectConfig(
log: options.log ?? noopLog,
};
try {
await assertConnectAllowed({
userId: options.userId,
hostId: serverHostId,
protocol: "ssh",
purpose: String(options.purpose),
profile,
interactive: options.interactive ?? false,
origin: options.origin ?? "core",
});
} catch (error) {
if (error instanceof ConnectPolicyError) {
return {
config,
provider: null,
env,
outcome: {
status: "error",
code: error.code,
message: error.message,
...(error.result.requestTab
? { requestTab: error.result.requestTab }
: {}),
},
};
}
throw error;
}
let provider: SshAuthProvider;
try {
provider = requireSshAuthProvider(authType);