Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Add MongoDB integration and documentation updates
Victor Santosed475f0ed8ff
diff --git a/backend/src/services/app-connection/mongodb/mongodb-connection-fns.ts b/backend/src/services/app-connection/mongodb/mongodb-connection-fns.tsindex 18aac82252..5587fc388b 100644--- a/backend/src/services/app-connection/mongodb/mongodb-connection-fns.ts+++ b/backend/src/services/app-connection/mongodb/mongodb-connection-fns.ts@@ -17,11 +17,19 @@ export const getMongoDBConnectionListItem = () => {};export const validateMongoDBConnectionCredentials = async (config: TMongoDBConnectionConfig) => {- const [hostIp] = await verifyHostInputValidity(config.credentials.host);+ let normalizedHost = config.credentials.host.trim();+ const isSrvFromHost = normalizedHost.startsWith("mongodb+srv://");+ if (isSrvFromHost) {+ normalizedHost = normalizedHost.replace(/^mongodb\+srv:\/\//, "");+ } else if (normalizedHost.startsWith("mongodb://")) {+ normalizedHost = normalizedHost.replace(/^mongodb:\/\//, "");+ }++ const [hostIp] = await verifyHostInputValidity(normalizedHost);let client: MongoClient | null = null;try {- const isSrv = !config.credentials.port;+ const isSrv = !config.credentials.port || isSrvFromHost;const uri = isSrv ? `mongodb+srv://${hostIp}` : `mongodb://${hostIp}:${config.credentials.port}`;const clientOptions: {diff --git a/docs/docs.json b/docs/docs.jsonindex aea022fd4b..295a81bbb3 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -129,6 +129,7 @@"integrations/app-connections/laravel-forge","integrations/app-connections/ldap","integrations/app-connections/mssql",+ "integrations/app-connections/mongodb","integrations/app-connections/mysql","integrations/app-connections/netlify","integrations/app-connections/northflank",@@ -1889,6 +1890,18 @@"api-reference/endpoints/app-connections/mssql/delete"]},+ {+ "group": "MongoDB",+ "pages": [+ "api-reference/endpoints/app-connections/mongodb/list",+ "api-reference/endpoints/app-connections/mongodb/available",+ "api-reference/endpoints/app-connections/mongodb/get-by-id",+ "api-reference/endpoints/app-connections/mongodb/get-by-name",+ "api-reference/endpoints/app-connections/mongodb/create",+ "api-reference/endpoints/app-connections/mongodb/update",+ "api-reference/endpoints/app-connections/mongodb/delete"+ ]+ },{"group": "MySQL","pages": [diff --git a/docs/images/app-connections/general/add-connection.png b/docs/images/app-connections/general/add-connection.pngindex b6dce69ac1..5ebadae098 100644Binary files a/docs/images/app-connections/general/add-connection.png and b/docs/images/app-connections/general/add-connection.png differdiff --git a/docs/images/app-connections/mongodb/mongodb-app-connection-form.png b/docs/images/app-connections/mongodb/mongodb-app-connection-form.pngnew file mode 100644index 0000000000..f57ca1aa54Binary files /dev/null and b/docs/images/app-connections/mongodb/mongodb-app-connection-form.png differdiff --git a/docs/images/app-connections/mongodb/mongodb-app-connection-generated.png b/docs/images/app-connections/mongodb/mongodb-app-connection-generated.pngnew file mode 100644index 0000000000..eed7d01af4Binary files /dev/null and b/docs/images/app-connections/mongodb/mongodb-app-connection-generated.png differdiff --git a/docs/images/app-connections/mongodb/mongodb-app-connection-option.png b/docs/images/app-connections/mongodb/mongodb-app-connection-option.pngnew file mode 100644index 0000000000..0999decb30Binary files /dev/null and b/docs/images/app-connections/mongodb/mongodb-app-connection-option.png differdiff --git a/docs/integrations/app-connections/mongodb.mdx b/docs/integrations/app-connections/mongodb.mdxnew file mode 100644index 0000000000..b32874350e--- /dev/null+++ b/docs/integrations/app-connections/mongodb.mdx@@ -0,0 +1,141 @@+---+title: "MongoDB Connection"+description: "Learn how to configure a MongoDB Connection for Infisical."+---++Infisical supports the use of Username & Password authentication to connect with MongoDB databases.++## Configure a MongoDB user for Infisical++<Steps>+ <Step title="Create a MongoDB user">+ Infisical recommends creating a designated user in your MongoDB database for your connection.++ ```javascript+ use admin+ db.createUser({+ user: "infisical_manager",+ pwd: "[ENTER-YOUR-USER-PASSWORD]",+ roles: []+ })+ ```+ </Step>++ <Step title="Grant Relevant Permissions">+ Depending on how you intend to use your MongoDB connection, you'll need to grant one or more of the following permissions.++ <Tip>+ To learn more about MongoDB's permission system, please visit their [documentation](https://www.mongodb.com/docs/manual/core/security-built-in-roles/).+ </Tip>++ <Tabs>+ <Tab title="Secret Rotation">+ For Secret Rotations, your Infisical user will require the ability to create, update, and delete users in the target database:++ ```javascript+ use [TARGET-DATABASE]+ db.grantRolesToUser("infisical_manager", [+ { role: "userAdmin", db: "[TARGET-DATABASE]" }+ ])+ ```++ <Note>+ The `userAdmin` role allows managing users (create, update passwords, delete) within the specified database. If you need to rotate users across multiple databases, grant `userAdminAnyDatabase` on the `admin` database instead.+ </Note>+ </Tab>+ </Tabs>+ </Step>+</Steps>+++## Create MongoDB Connection in Infisical++<Tabs>+ <Tab title="Infisical UI">+ <Steps>+ <Step title="Navigate to App Connections">+ In your Infisical dashboard, navigate to the **App Connections** page in the desired project.++ + </Step>+ <Step title="Select MongoDB Connection">+ Click the **+ Add Connection** button and select the **MongoDB Connection** option from the available integrations.++ + </Step>+ <Step title="Fill out the MongoDB Connection Modal">+ Complete the MongoDB Connection form by entering:+ - A descriptive name for the connection+ - An optional description for future reference+ - The MongoDB host URL for your database+ - The MongoDB port for your database+ - The MongoDB username for your database+ - The MongoDB password for your database+ - The MongoDB database name to connect to++ You can optionally configure SSL/TLS for your MongoDB connection in the **SSL** section.++ + </Step>+ <Step title="Connection Created">+ After clicking Create, your **MongoDB Connection** is established and ready to use with your Infisical project.++ + </Step>+ </Steps>+ </Tab>+ <Tab title="API">+ To create a MongoDB Connection, make an API request to the [Create MongoDB Connection](/api-reference/endpoints/app-connections/mongodb/create) API endpoint.++ ### Sample request++ ```bash Request+ curl --request POST \+ --url https://app.infisical.com/api/v1/app-connections/mongodb \+ --header 'Content-Type: application/json' \+ --data '{+ "name": "my-mongodb-connection",+ "method": "username-and-password",+ "projectId": "7ffbb072-2575-495a-b5b0-127f88caef78",+ "credentials": {+ "host": "[MONGODB HOST]",+ "port": 27017,+ "username": "[MONGODB USERNAME]",+ "password": "[MONGODB PASSWORD]",+ "database": "[MONGODB DATABASE]"+ }+ }'+ ```++ ### Sample response++ ```bash Response+ {+ "appConnection": {+ "id": "e5d18aca-86f7-4026-a95e-efb8aeb0d8e6",+ "name": "my-mongodb-connection",+ "projectId": "7ffbb072-2575-495a-b5b0-127f88caef78",+ "description": null,+ "version": 1,+ "orgId": "6f03caa1-a5de-43ce-b127-95a145d3464c",+ "createdAt": "2025-04-23T19:46:34.831Z",+ "updatedAt": "2025-04-23T19:46:34.831Z",+ "isPlatformManagedCredentials": false,+ "credentialsHash": "7c2d371dec195f82a6a0d5b41c970a229cfcaf88e894a5b6395e2dbd0280661f",+ "app": "mongodb",+ "method": "username-and-password",+ "credentials": {+ "host": "[MONGODB HOST]",+ "port": 27017,+ "username": "[MONGODB USERNAME]",+ "database": "[MONGODB DATABASE]",+ "sslEnabled": false,+ "sslRejectUnauthorized": false,+ "sslCertificate": ""+ }+ }+ }+ ```+ </Tab>+</Tabs>+diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/MongoDBConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/MongoDBConnectionForm.tsxindex c9b3421cee..32b38fea02 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/MongoDBConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/MongoDBConnectionForm.tsx@@ -1,4 +1,4 @@-import { useEffect, useState } from "react";+import { useState } from "react";import { Controller, FormProvider, useForm } from "react-hook-form";import { faQuestionCircle } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";@@ -84,19 +84,11 @@ export const MongoDBConnectionForm = ({ appConnection, onSubmit }: Props) => {handleSubmit,watch,control,- setValue,formState: { isSubmitting, isDirty }} = form;- const host = watch("credentials.host");const sslEnabled = watch("credentials.sslEnabled");- useEffect(() => {- if (host && host.includes("+srv") && !sslEnabled) {- setValue("credentials.sslEnabled", true, { shouldDirty: true });- }- }, [host, sslEnabled, setValue]);-return (<FormProvider {...form}><form onSubmit={handleSubmit(onSubmit)}>diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/RedisConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/RedisConnectionForm.tsxindex f4b7b85861..8f425b7278 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/RedisConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/RedisConnectionForm.tsx@@ -307,4 +307,4 @@ export const RedisConnectionForm = ({ appConnection, onSubmit }: Props) => {</form></FormProvider>);-};+};\ No newline at end of file