Skip to content

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

refactor(pam): switch MongoDB to connectionString field, add tooltip support

bernie-gc75f33eefe8d
diff --git a/backend/src/ee/services/pam-account/pam-account-schemas.ts b/backend/src/ee/services/pam-account/pam-account-schemas.ts
index 20c6450908..4d7f383484 100644
--- a/backend/src/ee/services/pam-account/pam-account-schemas.ts
+++ b/backend/src/ee/services/pam-account/pam-account-schemas.ts
@@ -143,15 +143,8 @@ export const ACCOUNT_TYPE_CONFIGS = {
name: "MongoDB",
icon: "MongoDB.png",
connectionDetails: z.object({
- host: z.string().trim().min(1).max(255),
- port: z.coerce.number(),
+ connectionString: z.string().trim().min(1).max(2048),
database: z.string().trim().min(1).max(255),
- authSource: z
- .string()
- .trim()
- .max(255)
- .transform((v) => v || undefined)
- .optional(),
sslEnabled: z.boolean(),
sslRejectUnauthorized: z.boolean(),
sslCertificate: z
@@ -171,8 +164,12 @@ export const ACCOUNT_TYPE_CONFIGS = {
}),
sanitizedCredentials: z.object({ username: z.string().optional() }),
ui: {
- port: { defaultValue: 27017 },
- authSource: { label: "Auth Source" },
+ connectionString: {
+ label: "Connection String",
+ widget: PamFieldWidget.Textarea,
+ tooltip: "Supports mongodb:// and mongodb+srv:// URIs. Do not include credentials or database in the URI."
+ },
+ database: { defaultValue: "admin" },
sslEnabled: { label: "SSL Enabled" },
sslRejectUnauthorized: {
label: "Reject Unauthorized",
@@ -335,7 +332,6 @@ export const extractGatewayTarget = (
case PamAccountType.SSH:
case PamAccountType.Postgres:
case PamAccountType.MySQL:
- case PamAccountType.MongoDB:
case PamAccountType.MsSQL:
return {
host: (validated as { host: string; port: number }).host,
@@ -346,6 +342,18 @@ export const extractGatewayTarget = (
const parsed = new URL(url);
return { host: parsed.hostname };
}
+ case PamAccountType.MongoDB: {
+ const { connectionString } = validated as { connectionString: string };
+ try {
+ const url = new URL(connectionString);
+ return {
+ host: url.hostname,
+ port: url.port ? Number(url.port) : undefined
+ };
+ } catch {
+ return { host: connectionString };
+ }
+ }
default:
throw new Error(`No gateway target extraction defined for account type '${accountType}'`);
}
@@ -406,7 +414,10 @@ export const PamFieldDescriptorSchema = z.object({
defaultValue: z.union([z.string(), z.number(), z.boolean()]).optional(),
// Only render when the referenced field equals this value
- showWhen: z.object({ field: z.string(), equals: z.union([z.string(), z.boolean()]) }).optional()
+ showWhen: z.object({ field: z.string(), equals: z.union([z.string(), z.boolean()]) }).optional(),
+
+ // Info tooltip shown next to the label
+ tooltip: z.string().optional()
});
type PamFieldDescriptor = z.infer<typeof PamFieldDescriptorSchema>;
@@ -429,6 +440,7 @@ type TFieldUiHint = {
secret?: boolean;
defaultValue?: string | number | boolean;
showWhen?: PamFieldDescriptor["showWhen"];
+ tooltip?: string;
};
const humanizeKey = (key: string) => {
@@ -491,7 +503,8 @@ const describeField = (
? { options: enumValues.map((v) => ({ label: humanizeKey(v), value: v })) }
: {}),
...(hint.defaultValue !== undefined ? { defaultValue: hint.defaultValue } : {}),
- ...(resolvedShowWhen ? { showWhen: resolvedShowWhen } : {})
+ ...(resolvedShowWhen ? { showWhen: resolvedShowWhen } : {}),
+ ...(hint.tooltip ? { tooltip: hint.tooltip } : {})
};
};
diff --git a/backend/src/ee/services/pam-session/pam-session-service.ts b/backend/src/ee/services/pam-session/pam-session-service.ts
index 119c3c3c3f..bd30535b7c 100644
--- a/backend/src/ee/services/pam-session/pam-session-service.ts
+++ b/backend/src/ee/services/pam-session/pam-session-service.ts
@@ -215,18 +215,8 @@ export const pamSessionServiceFactory = ({
};
}
- const mergedCredentials: Record<string, unknown> = { ...connectionDetails, ...credentials };
-
- if (account.accountType === PamAccountType.MongoDB) {
- const host = connectionDetails.host as string;
- const port = connectionDetails.port as number;
- const authSource = (connectionDetails.authSource as string) || undefined;
- const qs = authSource ? `?authSource=${encodeURIComponent(authSource)}` : "";
- mergedCredentials.connectionString = `mongodb://${host}:${port}${qs}`;
- }
-
return {
- credentials: mergedCredentials,
+ credentials: { ...connectionDetails, ...credentials },
recording,
projectId: session.projectId,
accountId: session.accountId,
diff --git a/frontend/src/hooks/api/pam/types/index.ts b/frontend/src/hooks/api/pam/types/index.ts
index b840be9038..e66d708de2 100644
--- a/frontend/src/hooks/api/pam/types/index.ts
+++ b/frontend/src/hooks/api/pam/types/index.ts
@@ -33,6 +33,7 @@ export type TPamFieldDescriptor = {
options?: { label: string; value: string }[];
defaultValue?: string | number | boolean;
showWhen?: { field: string; equals: string | boolean };
+ tooltip?: string;
};
export type TPamPolicyDescriptor = {
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamSchemaFields.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamSchemaFields.tsx
index 12f8388675..c9dbf69440 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/PamSchemaFields.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamSchemaFields.tsx
@@ -1,4 +1,5 @@
import { Control, Controller, ControllerRenderProps, useWatch } from "react-hook-form";
+import { Info } from "lucide-react";
import { Field, FieldContent, FieldError, FieldLabel } from "@app/components/v3/generic/Field";
import { Input } from "@app/components/v3/generic/Input";
@@ -11,6 +12,11 @@ import {
} from "@app/components/v3/generic/Select";
import { Switch } from "@app/components/v3/generic/Switch";
import { TextArea } from "@app/components/v3/generic/TextArea";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
+} from "@app/components/v3/generic/Tooltip";
import { PamFieldWidget, TPamFieldDescriptor } from "@app/hooks/api/pam";
import { TAccountFormValues } from "./accountFormSchema";
@@ -108,6 +114,14 @@ export const PamSchemaFields = ({ control, namePrefix, fields }: Props) => {
<FieldLabel>
{descriptor.label}
{(descriptor.required || descriptor.secret) && <RequiredMark />}
+ {descriptor.tooltip && (
+ <Tooltip>
+ <TooltipTrigger>
+ <Info className="ml-1 inline h-3.5 w-3.5 text-muted-foreground" />
+ </TooltipTrigger>
+ <TooltipContent>{descriptor.tooltip}</TooltipContent>
+ </Tooltip>
+ )}
</FieldLabel>
<Switch
variant="pam"
@@ -120,6 +134,14 @@ export const PamSchemaFields = ({ control, namePrefix, fields }: Props) => {
<FieldLabel>
{descriptor.label}
{(descriptor.required || descriptor.secret) && <RequiredMark />}
+ {descriptor.tooltip && (
+ <Tooltip>
+ <TooltipTrigger>
+ <Info className="ml-1 inline h-3.5 w-3.5 text-muted-foreground" />
+ </TooltipTrigger>
+ <TooltipContent>{descriptor.tooltip}</TooltipContent>
+ </Tooltip>
+ )}
</FieldLabel>
<FieldContent>
<FieldWidget field={field} descriptor={descriptor} isError={!!fieldState.error} />