Skip to content

Commit 8392be5

Browse files
committed
feat: Fallback to Fabric Connect during Cluster Setup
If cookie auth and basic auth don’t work, fallback to Fabric Connect as a last resort. This will let us support aggressive corporate VPNs that don’t like talking to non-standard ports. https://harperdb.atlassian.net/browse/STUDIO-583
1 parent a5970e6 commit 8392be5

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

src/features/instance/operations/mutations/useInstanceLoginMutation.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { forceBasicAuth } from '@/config/constants';
1+
import { forceBasicAuth, isLocalStudio } from '@/config/constants';
2+
import { getInstanceClient } from '@/config/getInstanceClient';
23
import { InstanceClientIdConfig } from '@/config/instanceClientConfig';
34
import { authStore } from '@/features/auth/store/authStore';
45
import { getInstanceUserInfo } from '@/features/instance/operations/queries/getInstanceUserInfo';
56
import { LocalUser } from '@/lib/api.patch';
67
import { useMutation } from '@tanstack/react-query';
8+
import { AxiosInstance } from 'axios';
79

810
interface InstanceLoginCredentials extends InstanceClientIdConfig {
911
username: string;
@@ -13,6 +15,7 @@ interface InstanceLoginCredentials extends InstanceClientIdConfig {
1315
export interface LoginInfoResponse {
1416
message: string;
1517
user: LocalUser;
18+
instanceClient?: AxiosInstance;
1619
}
1720

1821
export async function onInstanceLoginSubmit({
@@ -40,17 +43,38 @@ export async function onInstanceLoginSubmit({
4043
}
4144
}
4245

46+
try {
47+
const user = await getInstanceUserInfo({
48+
instanceClient,
49+
auth: {
50+
username,
51+
password,
52+
},
53+
});
54+
authStore.flagForBasicAuth(entityId, { username, password });
55+
return {
56+
message,
57+
user,
58+
};
59+
} catch (err) {
60+
if (isLocalStudio) {
61+
throw err;
62+
}
63+
console.error('Failed to get user with basic auth, trying Fabric Connect', err);
64+
}
65+
66+
const fabricInstanceClient = getInstanceClient({
67+
id: entityId,
68+
forceFabricConnect: true,
69+
});
4370
const user = await getInstanceUserInfo({
44-
instanceClient,
45-
auth: {
46-
username,
47-
password,
48-
},
71+
instanceClient: fabricInstanceClient,
4972
});
50-
authStore.flagForBasicAuth(entityId, { username, password });
73+
authStore.flagForFabricConnect(entityId, true);
5174
return {
5275
message,
5376
user,
77+
instanceClient,
5478
};
5579
}
5680

src/features/instance/operations/mutations/useInstanceResetPasswordMutation.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ async function onInstanceResetPassword({
2222
desiredUsername,
2323
newPassword,
2424
tempPassword,
25-
instanceClient,
25+
instanceClient: initialInstanceClient,
2626
}: InstanceResetPasswordParams): Promise<LoginInfoResponse> {
2727
// Do we have a temporary password?
2828
if (!tempPassword) {
2929
throw new Error('You may not have permission to set the password on this cluster.');
3030
}
31+
let instanceClient = initialInstanceClient;
3132
try {
3233
// Sign in with the temporary password,
3334
const loginResponse = await onInstanceLoginSubmit({
@@ -36,25 +37,31 @@ async function onInstanceResetPassword({
3637
instanceClient,
3738
entityId: clusterId,
3839
});
39-
// then alter or create a new user
40+
if (loginResponse.instanceClient) {
41+
instanceClient = loginResponse.instanceClient;
42+
}
43+
// then we can either alter...
4044
if (desiredUsername === defaultClusterUsername) {
4145
await onAlterUser({
4246
username: desiredUsername,
4347
password: newPassword,
4448
instanceClient,
4549
});
4650
} else {
51+
// ... or create a new user!
4752
await onAddUserSubmit({
4853
username: desiredUsername,
4954
password: newPassword,
5055
role: 'super_user',
5156
active: true,
5257
instanceClient,
5358
});
59+
// since we created a new user, we should clean up the old one
5460
await onDeleteUser({
5561
username: defaultClusterUsername,
5662
instanceClient,
5763
});
64+
/// and login with the new one.
5865
await onInstanceLoginSubmit({
5966
username: desiredUsername,
6067
password: newPassword,

0 commit comments

Comments
 (0)