Address Connect approval review findings
This commit is contained in:
1 parent
f09ee2dd7c
commit
136150d32f
5 files changed
+161
-32
No files matched your search
@@ -34,16 +34,36 @@ const approvedRecord: AuthConnectClients.AuthConnectClientRecord = {
|
||||
lastSeenAt: null,
|
||||
};
|
||||
|
||||
const secretStoreLayer = Layer.succeed(
|
||||
ServerSecretStore.ServerSecretStore,
|
||||
ServerSecretStore.ServerSecretStore.of({
|
||||
get: () => Effect.succeed(Option.some(textEncoder.encode("client-approval"))),
|
||||
set: () => Effect.void,
|
||||
create: () => Effect.void,
|
||||
getOrCreateRandom: () => Effect.succeed(new Uint8Array()),
|
||||
remove: () => Effect.void,
|
||||
}),
|
||||
);
|
||||
const makeSecretStoreLayer = (mode: string) =>
|
||||
Layer.succeed(
|
||||
ServerSecretStore.ServerSecretStore,
|
||||
ServerSecretStore.ServerSecretStore.of({
|
||||
get: () => Effect.succeed(Option.some(textEncoder.encode(mode))),
|
||||
set: () => Effect.void,
|
||||
create: () => Effect.void,
|
||||
getOrCreateRandom: () => Effect.succeed(new Uint8Array()),
|
||||
remove: () => Effect.void,
|
||||
}),
|
||||
);
|
||||
|
||||
const secretStoreLayer = makeSecretStoreLayer("client-approval");
|
||||
|
||||
const makeStoreOnlyLayer = (mode: string) =>
|
||||
Layer.effect(ConnectClientStore.ConnectClientStore, ConnectClientStore.make).pipe(
|
||||
Layer.provide(makeSecretStoreLayer(mode)),
|
||||
Layer.provide(
|
||||
Layer.succeed(
|
||||
AuthConnectClients.AuthConnectClientRepository,
|
||||
AuthConnectClients.AuthConnectClientRepository.of({
|
||||
upsertRequest: () => Effect.succeed(approvedRecord),
|
||||
updateStatus: () => Effect.succeed(Option.none()),
|
||||
revoke: () => Effect.succeed(false),
|
||||
markSeen: () => Effect.succeed(Option.some(approvedRecord)),
|
||||
listActive: () => Effect.succeed([]),
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const makeStoreLayer = (
|
||||
overrides: Partial<AuthConnectClients.AuthConnectClientRepository["Service"]>,
|
||||
@@ -65,6 +85,15 @@ const makeStoreLayer = (
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("fails closed when persisted security mode is invalid", () =>
|
||||
Effect.gen(function* () {
|
||||
const store = yield* ConnectClientStore.ConnectClientStore;
|
||||
const error = yield* Effect.flip(store.getSecurityMode());
|
||||
|
||||
expect(error._tag).toBe("ConnectSecurityModeLoadError");
|
||||
}).pipe(Effect.provide(makeStoreOnlyLayer("invalid-mode"))),
|
||||
);
|
||||
|
||||
it.effect("returns rejected when an approved client is rejected before last-seen update", () =>
|
||||
Effect.gen(function* () {
|
||||
const store = yield* ConnectClientStore.ConnectClientStore;
|
||||
|
||||
@@ -222,9 +222,18 @@ function fromPresentationMetadata(
|
||||
};
|
||||
}
|
||||
|
||||
function decodeSecurityMode(bytes: Uint8Array): AuthConnectSecurityMode {
|
||||
function decodeSecurityMode(
|
||||
bytes: Uint8Array,
|
||||
): Effect.Effect<AuthConnectSecurityMode, ConnectSecurityModeLoadError> {
|
||||
const value = textDecoder.decode(bytes).trim();
|
||||
return value === "client-approval" ? "client-approval" : "account";
|
||||
if (value === "account" || value === "client-approval") {
|
||||
return Effect.succeed(value);
|
||||
}
|
||||
return Effect.fail(
|
||||
new ConnectSecurityModeLoadError({
|
||||
cause: new Error(`Invalid Connect security mode: ${value}`),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function encodeSecurityMode(mode: AuthConnectSecurityMode): Uint8Array {
|
||||
@@ -256,10 +265,10 @@ export const make = Effect.gen(function* () {
|
||||
|
||||
const getSecurityMode: ConnectClientStore["Service"]["getSecurityMode"] = () =>
|
||||
secrets.get(CONNECT_SECURITY_MODE_SECRET).pipe(
|
||||
Effect.map((mode) =>
|
||||
Option.isSome(mode) ? decodeSecurityMode(mode.value) : ("account" as const),
|
||||
),
|
||||
Effect.mapError((cause) => new ConnectSecurityModeLoadError({ cause })),
|
||||
Effect.flatMap((mode) =>
|
||||
Option.isSome(mode) ? decodeSecurityMode(mode.value) : Effect.succeed("account" as const),
|
||||
),
|
||||
Effect.withSpan("ConnectClientStore.getSecurityMode"),
|
||||
);
|
||||
|
||||
|
||||
@@ -57,3 +57,71 @@ it.effect("clears stale last-seen timestamps when a revoked client re-registers"
|
||||
expect(reregistered.lastSeenAt).toBeNull();
|
||||
}).pipe(Effect.provide(layer)),
|
||||
);
|
||||
|
||||
it.effect("resets approval when the same proof key is requested by a different cloud user", () =>
|
||||
Effect.gen(function* () {
|
||||
const clients = yield* AuthConnectClients.AuthConnectClientRepository;
|
||||
const clientProofKeyThumbprint = "client-thumbprint-cloud-user-change";
|
||||
|
||||
yield* clients.upsertRequest({
|
||||
clientProofKeyThumbprint,
|
||||
cloudUserId: "cloud-user-a",
|
||||
deviceId: "device-1",
|
||||
client,
|
||||
requestedAt: DateTime.makeUnsafe("2026-06-27T13:00:00.000Z"),
|
||||
});
|
||||
yield* clients.updateStatus({
|
||||
clientProofKeyThumbprint,
|
||||
status: "approved",
|
||||
decidedAt: DateTime.makeUnsafe("2026-06-27T13:01:00.000Z"),
|
||||
});
|
||||
yield* clients.markSeen({
|
||||
clientProofKeyThumbprint,
|
||||
seenAt: DateTime.makeUnsafe("2026-06-27T13:02:00.000Z"),
|
||||
});
|
||||
|
||||
const reregistered = yield* clients.upsertRequest({
|
||||
clientProofKeyThumbprint,
|
||||
cloudUserId: "cloud-user-b",
|
||||
deviceId: "device-1",
|
||||
client,
|
||||
requestedAt: DateTime.makeUnsafe("2026-06-27T13:03:00.000Z"),
|
||||
});
|
||||
|
||||
expect(reregistered.cloudUserId).toBe("cloud-user-b");
|
||||
expect(reregistered.status).toBe("pending");
|
||||
expect(reregistered.approvedAt).toBeNull();
|
||||
expect(reregistered.rejectedAt).toBeNull();
|
||||
expect(reregistered.lastSeenAt).toBeNull();
|
||||
}).pipe(Effect.provide(layer)),
|
||||
);
|
||||
|
||||
it.effect("clears the opposite decision timestamp when approval status changes", () =>
|
||||
Effect.gen(function* () {
|
||||
const clients = yield* AuthConnectClients.AuthConnectClientRepository;
|
||||
const clientProofKeyThumbprint = "client-thumbprint-status-flip";
|
||||
|
||||
yield* clients.upsertRequest({
|
||||
clientProofKeyThumbprint,
|
||||
cloudUserId: "cloud-user",
|
||||
deviceId: "device-1",
|
||||
client,
|
||||
requestedAt: DateTime.makeUnsafe("2026-06-27T14:00:00.000Z"),
|
||||
});
|
||||
const rejected = yield* clients.updateStatus({
|
||||
clientProofKeyThumbprint,
|
||||
status: "rejected",
|
||||
decidedAt: DateTime.makeUnsafe("2026-06-27T14:01:00.000Z"),
|
||||
});
|
||||
expect(Option.isSome(rejected) ? rejected.value.rejectedAt : null).not.toBeNull();
|
||||
expect(Option.isSome(rejected) ? rejected.value.approvedAt : null).toBeNull();
|
||||
|
||||
const approved = yield* clients.updateStatus({
|
||||
clientProofKeyThumbprint,
|
||||
status: "approved",
|
||||
decidedAt: DateTime.makeUnsafe("2026-06-27T14:02:00.000Z"),
|
||||
});
|
||||
expect(Option.isSome(approved) ? approved.value.approvedAt : null).not.toBeNull();
|
||||
expect(Option.isSome(approved) ? approved.value.rejectedAt : null).toBeNull();
|
||||
}).pipe(Effect.provide(layer)),
|
||||
);
|
||||
@@ -237,7 +237,9 @@ export const make = Effect.gen(function* () {
|
||||
cloud_user_id = excluded.cloud_user_id,
|
||||
device_id = excluded.device_id,
|
||||
status = CASE
|
||||
WHEN auth_connect_clients.revoked_at IS NULL THEN auth_connect_clients.status
|
||||
WHEN auth_connect_clients.revoked_at IS NULL
|
||||
AND auth_connect_clients.cloud_user_id = excluded.cloud_user_id
|
||||
THEN auth_connect_clients.status
|
||||
ELSE 'pending'
|
||||
END,
|
||||
client_label = excluded.client_label,
|
||||
@@ -249,15 +251,21 @@ export const make = Effect.gen(function* () {
|
||||
requested_at = excluded.requested_at,
|
||||
updated_at = excluded.updated_at,
|
||||
approved_at = CASE
|
||||
WHEN auth_connect_clients.revoked_at IS NULL THEN auth_connect_clients.approved_at
|
||||
WHEN auth_connect_clients.revoked_at IS NULL
|
||||
AND auth_connect_clients.cloud_user_id = excluded.cloud_user_id
|
||||
THEN auth_connect_clients.approved_at
|
||||
ELSE NULL
|
||||
END,
|
||||
rejected_at = CASE
|
||||
WHEN auth_connect_clients.revoked_at IS NULL THEN auth_connect_clients.rejected_at
|
||||
WHEN auth_connect_clients.revoked_at IS NULL
|
||||
AND auth_connect_clients.cloud_user_id = excluded.cloud_user_id
|
||||
THEN auth_connect_clients.rejected_at
|
||||
ELSE NULL
|
||||
END,
|
||||
last_seen_at = CASE
|
||||
WHEN auth_connect_clients.revoked_at IS NULL THEN auth_connect_clients.last_seen_at
|
||||
WHEN auth_connect_clients.revoked_at IS NULL
|
||||
AND auth_connect_clients.cloud_user_id = excluded.cloud_user_id
|
||||
THEN auth_connect_clients.last_seen_at
|
||||
ELSE NULL
|
||||
END,
|
||||
revoked_at = NULL
|
||||
@@ -274,8 +282,8 @@ export const make = Effect.gen(function* () {
|
||||
SET
|
||||
status = ${status},
|
||||
updated_at = ${decidedAt},
|
||||
approved_at = CASE WHEN ${status} = 'approved' THEN ${decidedAt} ELSE approved_at END,
|
||||
rejected_at = CASE WHEN ${status} = 'rejected' THEN ${decidedAt} ELSE rejected_at END,
|
||||
approved_at = CASE WHEN ${status} = 'approved' THEN ${decidedAt} ELSE NULL END,
|
||||
rejected_at = CASE WHEN ${status} = 'rejected' THEN ${decidedAt} ELSE NULL END,
|
||||
last_seen_at = CASE
|
||||
WHEN ${status} = 'approved' AND status = 'approved' THEN last_seen_at
|
||||
ELSE NULL
|
||||
|
||||
@@ -1077,6 +1077,7 @@ const ConnectClientListRow = memo(function ConnectClientListRow({
|
||||
const pendingApproveKey = `approve:${connectClient.clientProofKeyThumbprint}`;
|
||||
const pendingRejectKey = `reject:${connectClient.clientProofKeyThumbprint}`;
|
||||
const pendingRevokeKey = `revoke:${connectClient.clientProofKeyThumbprint}`;
|
||||
const hasPendingAction = pendingActionKey !== null;
|
||||
const statusConfig =
|
||||
connectClient.status === "approved"
|
||||
? {
|
||||
@@ -1139,7 +1140,7 @@ const ConnectClientListRow = memo(function ConnectClientListRow({
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
disabled={pendingActionKey === pendingApproveKey}
|
||||
disabled={hasPendingAction}
|
||||
onClick={() => void onApprove(connectClient.clientProofKeyThumbprint)}
|
||||
>
|
||||
{pendingActionKey === pendingApproveKey ? "Approving…" : "Approve"}
|
||||
@@ -1149,7 +1150,7 @@ const ConnectClientListRow = memo(function ConnectClientListRow({
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
disabled={pendingActionKey === pendingRejectKey}
|
||||
disabled={hasPendingAction}
|
||||
onClick={() => void onReject(connectClient.clientProofKeyThumbprint)}
|
||||
>
|
||||
{pendingActionKey === pendingRejectKey ? "Rejecting…" : "Reject"}
|
||||
@@ -1159,7 +1160,7 @@ const ConnectClientListRow = memo(function ConnectClientListRow({
|
||||
<Button
|
||||
size="xs"
|
||||
variant="destructive-outline"
|
||||
disabled={pendingActionKey === pendingRevokeKey}
|
||||
disabled={hasPendingAction}
|
||||
onClick={() => void onRevoke(connectClient.clientProofKeyThumbprint)}
|
||||
>
|
||||
{pendingActionKey === pendingRevokeKey ? "Revoking…" : "Revoke"}
|
||||
@@ -2316,9 +2317,9 @@ export function ConnectionsSettings() {
|
||||
),
|
||||
);
|
||||
}, [authAccessChanges.data]);
|
||||
const desktopConnectSecurityMode: AuthConnectSecurityMode = useMemo(() => {
|
||||
const desktopConnectSecurityMode: AuthConnectSecurityMode | null = useMemo(() => {
|
||||
const event = authAccessChanges.data;
|
||||
return event?.type === "snapshot" ? event.payload.connectSecurityMode : "account";
|
||||
return event?.type === "snapshot" ? event.payload.connectSecurityMode : null;
|
||||
}, [authAccessChanges.data]);
|
||||
const desktopConnectClients = useMemo(() => {
|
||||
const event = authAccessChanges.data;
|
||||
@@ -2548,6 +2549,7 @@ export function ConnectionsSettings() {
|
||||
|
||||
const handleConnectClientAction = useCallback(
|
||||
async (action: "approve" | "reject" | "revoke", clientProofKeyThumbprint: string) => {
|
||||
if (pendingConnectClientActionKey !== null) return;
|
||||
const actionKey = `${action}:${clientProofKeyThumbprint}`;
|
||||
setPendingConnectClientActionKey(actionKey);
|
||||
setDesktopAccessManagementMutationError(null);
|
||||
@@ -2574,7 +2576,7 @@ export function ConnectionsSettings() {
|
||||
setPendingConnectClientActionKey(null);
|
||||
}
|
||||
},
|
||||
[],
|
||||
[pendingConnectClientActionKey],
|
||||
);
|
||||
|
||||
const handleAddSavedBackend = useCallback(async () => {
|
||||
@@ -2784,6 +2786,13 @@ export function ConnectionsSettings() {
|
||||
);
|
||||
const isLocalBackendRemotelyReachable =
|
||||
isLocalBackendNetworkAccessible || tailscaleHttpsEndpoint?.status === "available";
|
||||
const shouldShowT3ConnectClients =
|
||||
hasCloudPublicConfig() &&
|
||||
(desktopConnectSecurityMode !== "account" ||
|
||||
desktopConnectClients.length > 0 ||
|
||||
isLoadingDesktopAccessManagement ||
|
||||
desktopAccessManagementError !== null);
|
||||
const shouldShowAuthorizedClients = isLocalBackendRemotelyReachable || shouldShowT3ConnectClients;
|
||||
const defaultDesktopNetworkAdvertisedEndpoint = useMemo(
|
||||
() =>
|
||||
selectPairingEndpoint(visibleDesktopNetworkAdvertisedEndpoints, defaultAdvertisedEndpointKey),
|
||||
@@ -3095,14 +3104,20 @@ export function ConnectionsSettings() {
|
||||
<SettingsRow
|
||||
title="T3 Connect approval"
|
||||
description={
|
||||
desktopConnectSecurityMode === "client-approval"
|
||||
? "New T3 Connect clients must be approved here before they can connect."
|
||||
: "Any signed-in client on this T3 account can connect through T3 Connect."
|
||||
desktopConnectSecurityMode === null
|
||||
? "Loading T3 Connect approval state."
|
||||
: desktopConnectSecurityMode === "client-approval"
|
||||
? "New T3 Connect clients must be approved here before they can connect."
|
||||
: "Any signed-in client on this T3 account can connect through T3 Connect."
|
||||
}
|
||||
control={
|
||||
<Switch
|
||||
checked={desktopConnectSecurityMode === "client-approval"}
|
||||
disabled={isUpdatingConnectSecurityMode || isLoadingDesktopAccessManagement}
|
||||
disabled={
|
||||
desktopConnectSecurityMode === null ||
|
||||
isUpdatingConnectSecurityMode ||
|
||||
isLoadingDesktopAccessManagement
|
||||
}
|
||||
onCheckedChange={(checked) => void handleUpdateConnectSecurityMode(checked)}
|
||||
aria-label="Require T3 Connect client approval"
|
||||
/>
|
||||
@@ -3206,7 +3221,7 @@ export function ConnectionsSettings() {
|
||||
)}
|
||||
</SettingsSection>
|
||||
|
||||
{isLocalBackendRemotelyReachable ? (
|
||||
{shouldShowAuthorizedClients ? (
|
||||
<SettingsSection
|
||||
title="Authorized clients"
|
||||
headerAction={
|
||||
|
||||
Reference in new issue
Block a user