Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(ui): completed ssh app connection ui

=81cde1af8683
diff --git a/frontend/src/helpers/appConnections.ts b/frontend/src/helpers/appConnections.ts
index abe4845b72..f2bac4054d 100644
--- a/frontend/src/helpers/appConnections.ts
+++ b/frontend/src/helpers/appConnections.ts
@@ -59,6 +59,7 @@ import { NorthflankConnectionMethod } from "@app/hooks/api/appConnections/types/
import { OCIConnectionMethod } from "@app/hooks/api/appConnections/types/oci-connection";
import { RailwayConnectionMethod } from "@app/hooks/api/appConnections/types/railway-connection";
import { RenderConnectionMethod } from "@app/hooks/api/appConnections/types/render-connection";
+import { SshConnectionMethod } from "@app/hooks/api/appConnections/types/ssh-connection";
import { SupabaseConnectionMethod } from "@app/hooks/api/appConnections/types/supabase-connection";
export const APP_CONNECTION_MAP: Record<
@@ -138,7 +139,8 @@ export const APP_CONNECTION_MAP: Record<
size: 65
},
[AppConnection.Chef]: { name: "Chef", image: "Chef.png", enterprise: true },
- [AppConnection.OctopusDeploy]: { name: "Octopus Deploy", image: "Octopus Deploy.png" }
+ [AppConnection.OctopusDeploy]: { name: "Octopus Deploy", image: "Octopus Deploy.png" },
+ [AppConnection.SSH]: { name: "SSH", image: "SSH.png" }
};
export const getAppConnectionMethodDetails = (method: TAppConnection["method"]) => {
@@ -225,6 +227,10 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])
return { name: "API Key & Secret", icon: faKey };
case OctopusDeployConnectionMethod.ApiKey:
return { name: "API Key", icon: faKey };
+ case SshConnectionMethod.Password:
+ return { name: "Password", icon: faLock };
+ case SshConnectionMethod.SshKey:
+ return { name: "SSH Key", icon: faKey };
default:
throw new Error(`Unhandled App Connection Method: ${method}`);
}
diff --git a/frontend/src/hooks/api/appConnections/enums.ts b/frontend/src/hooks/api/appConnections/enums.ts
index 37f85d51ca..634f8ba208 100644
--- a/frontend/src/hooks/api/appConnections/enums.ts
+++ b/frontend/src/hooks/api/appConnections/enums.ts
@@ -43,5 +43,6 @@ export enum AppConnection {
MongoDB = "mongodb",
LaravelForge = "laravel-forge",
Chef = "chef",
- OctopusDeploy = "octopus-deploy"
+ OctopusDeploy = "octopus-deploy",
+ SSH = "ssh"
}
diff --git a/frontend/src/hooks/api/appConnections/types/app-options.ts b/frontend/src/hooks/api/appConnections/types/app-options.ts
index 1f7df908b3..bb26e0d59d 100644
--- a/frontend/src/hooks/api/appConnections/types/app-options.ts
+++ b/frontend/src/hooks/api/appConnections/types/app-options.ts
@@ -196,6 +196,10 @@ export type TDNSMadeEasyConnectionOption = TAppConnectionOptionBase & {
app: AppConnection.DNSMadeEasy;
};
+export type TSshConnectionOption = TAppConnectionOptionBase & {
+ app: AppConnection.SSH;
+};
+
export type TAppConnectionOption =
| TAwsConnectionOption
| TGitHubConnectionOption
@@ -241,7 +245,8 @@ export type TAppConnectionOption =
| TMongoDBConnectionOption
| TChefConnectionOption
| TDNSMadeEasyConnectionOption
- | TOctopusDeployConnectionOption;
+ | TOctopusDeployConnectionOption
+ | TSshConnectionOption;
export type TAppConnectionOptionMap = {
[AppConnection.AWS]: TAwsConnectionOption;
@@ -289,4 +294,5 @@ export type TAppConnectionOptionMap = {
[AppConnection.LaravelForge]: TLaravelForgeConnectionOption;
[AppConnection.Chef]: TChefConnectionOption;
[AppConnection.OctopusDeploy]: TOctopusDeployConnectionOption;
+ [AppConnection.SSH]: TSshConnectionOption;
};
diff --git a/frontend/src/hooks/api/appConnections/types/index.ts b/frontend/src/hooks/api/appConnections/types/index.ts
index 2644282393..4cf63d2182 100644
--- a/frontend/src/hooks/api/appConnections/types/index.ts
+++ b/frontend/src/hooks/api/appConnections/types/index.ts
@@ -39,6 +39,7 @@ import { TPostgresConnection } from "./postgres-connection";
import { TRailwayConnection } from "./railway-connection";
import { TRedisConnection } from "./redis-connection";
import { TRenderConnection } from "./render-connection";
+import { TSshConnection } from "./ssh-connection";
import { TSupabaseConnection } from "./supabase-connection";
import { TTeamCityConnection } from "./teamcity-connection";
import { TTerraformCloudConnection } from "./terraform-cloud-connection";
@@ -84,6 +85,7 @@ export * from "./postgres-connection";
export * from "./railway-connection";
export * from "./redis-connection";
export * from "./render-connection";
+export * from "./ssh-connection";
export * from "./supabase-connection";
export * from "./teamcity-connection";
export * from "./terraform-cloud-connection";
@@ -136,7 +138,8 @@ export type TAppConnection =
| TRedisConnection
| TMongoDBConnection
| TChefConnection
- | TDNSMadeEasyConnection;
+ | TDNSMadeEasyConnection
+ | TSshConnection;
export type TAvailableAppConnection = Pick<TAppConnection, "name" | "id" | "projectId">;
diff --git a/frontend/src/hooks/api/appConnections/types/ssh-connection.ts b/frontend/src/hooks/api/appConnections/types/ssh-connection.ts
new file mode 100644
index 0000000000..009a9b3c0b
--- /dev/null
+++ b/frontend/src/hooks/api/appConnections/types/ssh-connection.ts
@@ -0,0 +1,29 @@
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
+import { TRootAppConnection } from "@app/hooks/api/appConnections/types/root-connection";
+
+export enum SshConnectionMethod {
+ Password = "password",
+ SshKey = "ssh-key"
+}
+
+export type TSshConnection = TRootAppConnection & { app: AppConnection.SSH } & (
+ | {
+ method: SshConnectionMethod.Password;
+ credentials: {
+ host: string;
+ port?: number;
+ username: string;
+ password: string;
+ };
+ }
+ | {
+ method: SshConnectionMethod.SshKey;
+ credentials: {
+ host: string;
+ port?: number;
+ username: string;
+ privateKey: string;
+ passphrase?: string;
+ };
+ }
+ );
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
index 3a2708688c..199858f47b 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
@@ -48,6 +48,7 @@ import { PostgresConnectionForm } from "./PostgresConnectionForm";
import { RailwayConnectionForm } from "./RailwayConnectionForm";
import { RedisConnectionForm } from "./RedisConnectionForm";
import { RenderConnectionForm } from "./RenderConnectionForm";
+import { SshConnectionForm } from "./SshConnectionForm";
import { SupabaseConnectionForm } from "./SupabaseConnectionForm";
import { TeamCityConnectionForm } from "./TeamCityConnectionForm";
import { TerraformCloudConnectionForm } from "./TerraformCloudConnectionForm";
@@ -179,6 +180,8 @@ const CreateForm = ({ app, onComplete, projectId }: CreateFormProps) => {
return <MongoDBConnectionForm onSubmit={onSubmit} />;
case AppConnection.OctopusDeploy:
return <OctopusDeployConnectionForm onSubmit={onSubmit} />;
+ case AppConnection.SSH:
+ return <SshConnectionForm onSubmit={onSubmit} />;
default:
throw new Error(`Unhandled App ${app}`);
}
@@ -341,6 +344,8 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
return <MongoDBConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
case AppConnection.OctopusDeploy:
return <OctopusDeployConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
+ case AppConnection.SSH:
+ return <SshConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
default:
throw new Error(`Unhandled App ${(appConnection as TAppConnection).app}`);
}
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/SshConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/SshConnectionForm.tsx
new file mode 100644
index 0000000000..eb03ab0c2e
--- /dev/null
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/SshConnectionForm.tsx
@@ -0,0 +1,332 @@
+import { Controller, FormProvider, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useQuery } from "@tanstack/react-query";
+import { z } from "zod";
+
+import { OrgPermissionCan } from "@app/components/permissions";
+import {
+ Button,
+ FormControl,
+ Input,
+ ModalClose,
+ SecretInput,
+ Select,
+ SelectItem,
+ Tooltip
+} from "@app/components/v2";
+import { OrgPermissionSubjects, useSubscription } from "@app/context";
+import { OrgGatewayPermissionActions } from "@app/context/OrgPermissionContext/types";
+import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
+import { gatewaysQueryKeys } from "@app/hooks/api";
+import { SshConnectionMethod, TSshConnection } from "@app/hooks/api/appConnections";
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
+
+import {
+ genericAppConnectionFieldsSchema,
+ GenericAppConnectionsFields
+} from "./GenericAppConnectionFields";
+
+type Props = {
+ appConnection?: TSshConnection;
+ onSubmit: (formData: FormData) => Promise<void>;
+};
+
+const rootSchema = genericAppConnectionFieldsSchema.extend({
+ app: z.literal(AppConnection.SSH)
+});
+
+const formSchema = z.discriminatedUnion("method", [
+ rootSchema.extend({
+ method: z.literal(SshConnectionMethod.Password),
+ credentials: z.object({
+ host: z.string().trim().min(1, "Host required"),
+ port: z.coerce.number().int().min(1).max(65535, "Port must be between 1 and 65535"),
+ username: z.string().trim().min(1, "Username required"),
+ password: z.string().trim().min(1, "Password required")
+ })
+ }),
+ rootSchema.extend({
+ method: z.literal(SshConnectionMethod.SshKey),
+ credentials: z.object({
+ host: z.string().trim().min(1, "Host required"),
+ port: z.coerce.number().int().min(1).max(65535, "Port must be between 1 and 65535"),
+ username: z.string().trim().min(1, "Username required"),
+ privateKey: z.string().trim().min(1, "Private key required"),
+ passphrase: z.string().trim().optional()
+ })
+ })
+]);
+
+type FormData = z.infer<typeof formSchema>;
+
+export const SshConnectionForm = ({ appConnection, onSubmit }: Props) => {
+ const isUpdate = Boolean(appConnection);
+
+ const form = useForm<FormData>({
+ resolver: zodResolver(formSchema),
+ defaultValues: appConnection
+ ? {
+ ...appConnection,
+ credentials: {
+ ...appConnection.credentials,
+ ...(appConnection.method === SshConnectionMethod.Password
+ ? { password: "" }
+ : { privateKey: "", passphrase: "" })
+ }
+ }
+ : {
+ app: AppConnection.SSH,
+ method: SshConnectionMethod.Password,
+ gatewayId: null,
+ credentials: {
+ host: "",
+ port: 22,
+ username: "",
+ password: ""
+ }
+ }
+ });
+
+ const {
+ handleSubmit,
+ control,
+ formState: { isSubmitting, isDirty },
+ watch,
+ setValue
+ } = form;
+
+ const selectedMethod = watch("method");
+ const { subscription } = useSubscription();
+ const { data: gateways, isPending: isGatewaysLoading } = useQuery(gatewaysQueryKeys.list());
+
+ const handleMethodChange = (newMethod: SshConnectionMethod) => {
+ const currentCredentials = form.getValues("credentials");
+
+ if (newMethod === SshConnectionMethod.Password) {
+ setValue("method", SshConnectionMethod.Password);
+ setValue("credentials", {
+ host: currentCredentials.host,
+ port: currentCredentials.port,
+ username: currentCredentials.username,
+ password: ""
+ });
+ } else {
+ setValue("method", SshConnectionMethod.SshKey);
+ setValue("credentials", {
+ host: currentCredentials.host,
+ port: currentCredentials.port,
+ username: currentCredentials.username,
+ privateKey: "",
+ passphrase: ""
+ });
+ }
+ };
+
+ return (
+ <FormProvider {...form}>
+ <form onSubmit={handleSubmit(onSubmit)}>
+ {!isUpdate && <GenericAppConnectionsFields />}
+ {subscription.gateway && (
+ <OrgPermissionCan
+ I={OrgGatewayPermissionActions.AttachGateways}
+ a={OrgPermissionSubjects.Gateway}
+ >
+ {(isAllowed) => (
+ <Controller
+ control={control}
+ name="gatewayId"
+ defaultValue=""
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ label="Gateway"
+ >
+ <Tooltip
+ isDisabled={isAllowed}
+ content="Restricted access. You don't have permission to attach gateways to resources."
+ >
+ <div>
+ <Select
+ isDisabled={!isAllowed}
+ value={value as string}
+ onValueChange={onChange}
+ className="w-full border border-mineshaft-500"
+ dropdownContainerClassName="max-w-none"
+ isLoading={isGatewaysLoading}
+ placeholder="Default: Internet Gateway"
+ position="popper"
+ >
+ <SelectItem
+ value={null as unknown as string}
+ onClick={() => onChange(undefined)}
+ >
+ Internet Gateway
+ </SelectItem>
+ {gateways?.map((el) => (
+ <SelectItem value={el.id} key={el.id}>
+ {el.name}
+ </SelectItem>
+ ))}
+ </Select>
+ </div>
+ </Tooltip>
+ </FormControl>
+ )}
+ />
+ )}
+ </OrgPermissionCan>
+ )}
+ <Controller
+ name="method"
+ control={control}
+ render={({ field: { value }, fieldState: { error } }) => (
+ <FormControl
+ tooltipText={`The authentication method you would like to use to connect with ${
+ APP_CONNECTION_MAP[AppConnection.SSH].name
+ }. This field cannot be changed after creation.`}
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Authentication Method"
+ >
+ <Select
+ isDisabled={isUpdate}
+ value={value}
+ onValueChange={(val) => handleMethodChange(val as SshConnectionMethod)}
+ className="w-full border border-mineshaft-500"
+ position="popper"
+ dropdownContainerClassName="max-w-none"
+ >
+ {Object.values(SshConnectionMethod).map((method) => {
+ return (
+ <SelectItem value={method} key={method}>
+ {getAppConnectionMethodDetails(method).name}
+ </SelectItem>
+ );
+ })}
+ </Select>
+ </FormControl>
+ )}
+ />
+ <div className="mb-4 rounded-sm border border-mineshaft-600 bg-mineshaft-700/70 p-3 pb-0">
+ <div className="grid grid-cols-2 gap-2">
+ <Controller
+ name="credentials.host"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Host"
+ >
+ <Input {...field} placeholder="hostname or IP address" />
+ </FormControl>
+ )}
+ />
+ <Controller
+ name="credentials.port"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Port"
+ >
+ <Input {...field} type="number" placeholder="22" />
+ </FormControl>
+ )}
+ />
+ </div>
+ <Controller
+ name="credentials.username"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Username"
+ >
+ <Input {...field} placeholder="SSH username" />
+ </FormControl>
+ )}
+ />
+ {selectedMethod === SshConnectionMethod.Password ? (
+ <Controller
+ name="credentials.password"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Password"
+ >
+ <SecretInput
+ containerClassName="text-gray-400 group-focus-within:border-primary-400/50! border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"
+ value={value}
+ onChange={(e) => onChange(e.target.value)}
+ />
+ </FormControl>
+ )}
+ />
+ ) : (
+ <>
+ <Controller
+ name="credentials.privateKey"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Private Key"
+ >
+ <SecretInput
+ containerClassName="text-gray-400 group-focus-within:border-primary-400/50! border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"
+ value={field.value}
+ onChange={(e) => field.onChange(e.target.value)}
+ placeholder="-----BEGIN OPENSSH PRIVATE KEY-----"
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ name="credentials.passphrase"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Passphrase"
+ isOptional
+ >
+ <SecretInput
+ containerClassName="text-gray-400 group-focus-within:border-primary-400/50! border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"
+ value={value ?? ""}
+ onChange={(e) => onChange(e.target.value)}
+ />
+ </FormControl>
+ )}
+ />
+ </>
+ )}
+ </div>
+ <div className="mt-8 flex items-center">
+ <Button
+ className="mr-4"
+ size="sm"
+ type="submit"
+ colorSchema="secondary"
+ isLoading={isSubmitting}
+ isDisabled={isSubmitting || !isDirty}
+ >
+ {isUpdate ? "Update Credentials" : "Connect to SSH"}
+ </Button>
+ <ModalClose asChild>
+ <Button colorSchema="secondary" variant="plain">
+ Cancel
+ </Button>
+ </ModalClose>
+ </div>
+ </form>
+ </FormProvider>
+ );
+};