mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-09 10:28:21 +00:00
Add MongoDB credentials rotation support
- Introduced MongoDB credentials rotation router and schemas. - Updated backend services to handle MongoDB credentials rotation logic. - Enhanced frontend components to support MongoDB credentials management. - Integrated MongoDB credentials rotation into existing secret rotation options and forms.
This commit is contained in:
@@ -4,6 +4,7 @@ import { registerAuth0ClientSecretRotationRouter } from "./auth0-client-secret-r
|
||||
import { registerAwsIamUserSecretRotationRouter } from "./aws-iam-user-secret-rotation-router";
|
||||
import { registerAzureClientSecretRotationRouter } from "./azure-client-secret-rotation-router";
|
||||
import { registerLdapPasswordRotationRouter } from "./ldap-password-rotation-router";
|
||||
import { registerMongoDBCredentialsRotationRouter } from "./mongodb-credentials-rotation-router";
|
||||
import { registerMsSqlCredentialsRotationRouter } from "./mssql-credentials-rotation-router";
|
||||
import { registerMySqlCredentialsRotationRouter } from "./mysql-credentials-rotation-router";
|
||||
import { registerOktaClientSecretRotationRouter } from "./okta-client-secret-rotation-router";
|
||||
@@ -26,5 +27,6 @@ export const SECRET_ROTATION_REGISTER_ROUTER_MAP: Record<
|
||||
[SecretRotation.AwsIamUserSecret]: registerAwsIamUserSecretRotationRouter,
|
||||
[SecretRotation.LdapPassword]: registerLdapPasswordRotationRouter,
|
||||
[SecretRotation.OktaClientSecret]: registerOktaClientSecretRotationRouter,
|
||||
[SecretRotation.RedisCredentials]: registerRedisCredentialsRotationRouter
|
||||
[SecretRotation.RedisCredentials]: registerRedisCredentialsRotationRouter,
|
||||
[SecretRotation.MongoDBCredentials]: registerMongoDBCredentialsRotationRouter
|
||||
};
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import {
|
||||
CreateMongoDBCredentialsRotationSchema,
|
||||
MongoDBCredentialsRotationGeneratedCredentialsSchema,
|
||||
MongoDBCredentialsRotationSchema,
|
||||
UpdateMongoDBCredentialsRotationSchema
|
||||
} from "@app/ee/services/secret-rotation-v2/mongodb-credentials";
|
||||
import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
|
||||
|
||||
import { registerSecretRotationEndpoints } from "./secret-rotation-v2-endpoints";
|
||||
|
||||
export const registerMongoDBCredentialsRotationRouter = async (server: FastifyZodProvider) =>
|
||||
registerSecretRotationEndpoints({
|
||||
type: SecretRotation.MongoDBCredentials,
|
||||
server,
|
||||
responseSchema: MongoDBCredentialsRotationSchema,
|
||||
createSchema: CreateMongoDBCredentialsRotationSchema,
|
||||
updateSchema: UpdateMongoDBCredentialsRotationSchema,
|
||||
generatedCredentialsSchema: MongoDBCredentialsRotationGeneratedCredentialsSchema
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import { Auth0ClientSecretRotationListItemSchema } from "@app/ee/services/secret
|
||||
import { AwsIamUserSecretRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/aws-iam-user-secret";
|
||||
import { AzureClientSecretRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/azure-client-secret";
|
||||
import { LdapPasswordRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/ldap-password";
|
||||
import { MongoDBCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/mongodb-credentials";
|
||||
import { MsSqlCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/mssql-credentials";
|
||||
import { MySqlCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/mysql-credentials";
|
||||
import { OktaClientSecretRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/okta-client-secret";
|
||||
@@ -27,7 +28,8 @@ const SecretRotationV2OptionsSchema = z.discriminatedUnion("type", [
|
||||
AwsIamUserSecretRotationListItemSchema,
|
||||
LdapPasswordRotationListItemSchema,
|
||||
OktaClientSecretRotationListItemSchema,
|
||||
RedisCredentialsRotationListItemSchema
|
||||
RedisCredentialsRotationListItemSchema,
|
||||
MongoDBCredentialsRotationListItemSchema
|
||||
]);
|
||||
|
||||
export const registerSecretRotationV2Router = async (server: FastifyZodProvider) => {
|
||||
@@ -98,4 +100,4 @@ export const registerSecretRotationV2Router = async (server: FastifyZodProvider)
|
||||
return { secretRotations };
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from "./mongodb-credentials-rotation-constants";
|
||||
export * from "./mongodb-credentials-rotation-fns";
|
||||
export * from "./mongodb-credentials-rotation-schemas";
|
||||
export * from "./mongodb-credentials-rotation-types";
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
|
||||
import { TSecretRotationV2ListItem } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";
|
||||
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||
|
||||
export const MONGODB_CREDENTIALS_ROTATION_LIST_OPTION: TSecretRotationV2ListItem = {
|
||||
name: "MongoDB Credentials",
|
||||
type: SecretRotation.MongoDBCredentials,
|
||||
connection: AppConnection.MongoDB,
|
||||
template: {
|
||||
createUserStatement: `use [DATABASE_NAME]
|
||||
db.createUser({
|
||||
user: "infisical_user_1",
|
||||
pwd: "temporary_password",
|
||||
roles: [{ role: "readWrite", db: "[DATABASE_NAME]" }]
|
||||
})
|
||||
|
||||
db.createUser({
|
||||
user: "infisical_user_2",
|
||||
pwd: "temporary_password",
|
||||
roles: [{ role: "readWrite", db: "[DATABASE_NAME]" }]
|
||||
})`,
|
||||
secretsMapping: {
|
||||
username: "MONGODB_DB_USERNAME",
|
||||
password: "MONGODB_DB_PASSWORD"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+248
@@ -0,0 +1,248 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import { MongoClient } from "mongodb";
|
||||
|
||||
import { verifyHostInputValidity } from "@app/ee/services/dynamic-secret/dynamic-secret-fns";
|
||||
import {
|
||||
TRotationFactory,
|
||||
TRotationFactoryGetSecretsPayload,
|
||||
TRotationFactoryIssueCredentials,
|
||||
TRotationFactoryRevokeCredentials,
|
||||
TRotationFactoryRotateCredentials
|
||||
} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";
|
||||
|
||||
import { DEFAULT_PASSWORD_REQUIREMENTS, generatePassword } from "../shared/utils";
|
||||
import {
|
||||
TMongoDBCredentialsRotationGeneratedCredentials,
|
||||
TMongoDBCredentialsRotationWithConnection
|
||||
} from "./mongodb-credentials-rotation-types";
|
||||
|
||||
const redactPasswords = (e: unknown, credentials: TMongoDBCredentialsRotationGeneratedCredentials) => {
|
||||
const error = e as Error;
|
||||
|
||||
if (!error?.message) return "Unknown error";
|
||||
|
||||
let redactedMessage = error.message;
|
||||
|
||||
credentials.forEach(({ password }) => {
|
||||
redactedMessage = redactedMessage.replaceAll(password, "*******************");
|
||||
});
|
||||
|
||||
return redactedMessage;
|
||||
};
|
||||
|
||||
export const mongodbCredentialsRotationFactory: TRotationFactory<
|
||||
TMongoDBCredentialsRotationWithConnection,
|
||||
TMongoDBCredentialsRotationGeneratedCredentials
|
||||
> = (secretRotation) => {
|
||||
const {
|
||||
connection,
|
||||
parameters: { username1, username2 },
|
||||
activeIndex,
|
||||
secretsMapping
|
||||
} = secretRotation;
|
||||
|
||||
const passwordRequirement = DEFAULT_PASSWORD_REQUIREMENTS;
|
||||
|
||||
// Helper function to create MongoDB client with given credentials
|
||||
const $createMongoClient = async (
|
||||
authCredentials: { username: string; password: string },
|
||||
options?: { validateConnection?: boolean; requireTlsForSrv?: boolean }
|
||||
): Promise<MongoClient> => {
|
||||
let normalizedHost = connection.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);
|
||||
|
||||
const isSrv = !connection.credentials.port || isSrvFromHost;
|
||||
const uri = isSrv ? `mongodb+srv://${hostIp}` : `mongodb://${hostIp}:${connection.credentials.port}`;
|
||||
|
||||
const clientOptions: {
|
||||
auth?: { username: string; password?: string };
|
||||
authSource?: string;
|
||||
tls?: boolean;
|
||||
tlsInsecure?: boolean;
|
||||
ca?: string;
|
||||
directConnection?: boolean;
|
||||
} = {
|
||||
auth: {
|
||||
username: authCredentials.username,
|
||||
password: authCredentials.password
|
||||
},
|
||||
directConnection: !isSrv
|
||||
};
|
||||
|
||||
// SSL is enabled if explicitly enabled OR if using SRV (which requires TLS) and requireTlsForSrv is true
|
||||
if (connection.credentials.sslEnabled || (isSrv && options?.requireTlsForSrv)) {
|
||||
clientOptions.tls = true;
|
||||
clientOptions.tlsInsecure = !connection.credentials.sslRejectUnauthorized;
|
||||
if (connection.credentials.sslCertificate) {
|
||||
clientOptions.ca = connection.credentials.sslCertificate;
|
||||
}
|
||||
}
|
||||
|
||||
const client = new MongoClient(uri, clientOptions);
|
||||
|
||||
if (options?.validateConnection) {
|
||||
await client.db(connection.credentials.database).command({ ping: 1 });
|
||||
}
|
||||
|
||||
return client;
|
||||
};
|
||||
|
||||
const $getClient = async () => {
|
||||
let client: MongoClient | null = null;
|
||||
try {
|
||||
client = await $createMongoClient(
|
||||
{
|
||||
username: connection.credentials.username,
|
||||
password: connection.credentials.password
|
||||
},
|
||||
{ validateConnection: true }
|
||||
);
|
||||
return client;
|
||||
} catch (err) {
|
||||
if (client) await client.close();
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
const $validateCredentials = async (credentials: TMongoDBCredentialsRotationGeneratedCredentials[number]) => {
|
||||
let client: MongoClient | null = null;
|
||||
try {
|
||||
client = await $createMongoClient(
|
||||
{
|
||||
username: credentials.username,
|
||||
password: credentials.password
|
||||
},
|
||||
{ validateConnection: true, requireTlsForSrv: true }
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Error(redactPasswords(error, [credentials]));
|
||||
} finally {
|
||||
if (client) await client.close();
|
||||
}
|
||||
};
|
||||
|
||||
const issueCredentials: TRotationFactoryIssueCredentials<TMongoDBCredentialsRotationGeneratedCredentials> = async (
|
||||
callback
|
||||
) => {
|
||||
// For MongoDB, since we get existing users, we change both their passwords
|
||||
// on issue to invalidate their existing passwords
|
||||
const credentialsSet = [
|
||||
{ username: username1, password: generatePassword(passwordRequirement) },
|
||||
{ username: username2, password: generatePassword(passwordRequirement) }
|
||||
];
|
||||
|
||||
let client: MongoClient | null = null;
|
||||
try {
|
||||
client = await $getClient();
|
||||
const db = client.db(connection.credentials.database);
|
||||
|
||||
for (const credentials of credentialsSet) {
|
||||
await db.command({
|
||||
updateUser: credentials.username,
|
||||
pwd: credentials.password
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(redactPasswords(error, credentialsSet));
|
||||
} finally {
|
||||
if (client) await client.close();
|
||||
}
|
||||
|
||||
for (const credentials of credentialsSet) {
|
||||
await $validateCredentials(credentials);
|
||||
}
|
||||
|
||||
return callback(credentialsSet[0]);
|
||||
};
|
||||
|
||||
const revokeCredentials: TRotationFactoryRevokeCredentials<TMongoDBCredentialsRotationGeneratedCredentials> = async (
|
||||
credentialsToRevoke,
|
||||
callback
|
||||
) => {
|
||||
const revokedCredentials = credentialsToRevoke.map(({ username }) => ({
|
||||
username,
|
||||
password: generatePassword(passwordRequirement)
|
||||
}));
|
||||
|
||||
let client: MongoClient | null = null;
|
||||
try {
|
||||
client = await $getClient();
|
||||
const db = client.db(connection.credentials.database);
|
||||
|
||||
for (const credentials of revokedCredentials) {
|
||||
await db.command({
|
||||
updateUser: credentials.username,
|
||||
pwd: credentials.password
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(redactPasswords(error, revokedCredentials));
|
||||
} finally {
|
||||
if (client) await client.close();
|
||||
}
|
||||
|
||||
return callback();
|
||||
};
|
||||
|
||||
const rotateCredentials: TRotationFactoryRotateCredentials<TMongoDBCredentialsRotationGeneratedCredentials> = async (
|
||||
_,
|
||||
callback
|
||||
) => {
|
||||
const credentials = {
|
||||
username: activeIndex === 0 ? username2 : username1,
|
||||
password: generatePassword(passwordRequirement)
|
||||
};
|
||||
|
||||
let client: MongoClient | null = null;
|
||||
try {
|
||||
client = await $getClient();
|
||||
const db = client.db(connection.credentials.database);
|
||||
|
||||
await db.command({
|
||||
updateUser: credentials.username,
|
||||
pwd: credentials.password
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error(redactPasswords(error, [credentials]));
|
||||
} finally {
|
||||
if (client) await client.close();
|
||||
}
|
||||
|
||||
await $validateCredentials(credentials);
|
||||
|
||||
return callback(credentials);
|
||||
};
|
||||
|
||||
const getSecretsPayload: TRotationFactoryGetSecretsPayload<TMongoDBCredentialsRotationGeneratedCredentials> = (
|
||||
generatedCredentials
|
||||
) => {
|
||||
const { username, password } = secretsMapping;
|
||||
|
||||
const secrets = [
|
||||
{
|
||||
key: username,
|
||||
value: generatedCredentials.username
|
||||
},
|
||||
{
|
||||
key: password,
|
||||
value: generatedCredentials.password
|
||||
}
|
||||
];
|
||||
|
||||
return secrets;
|
||||
};
|
||||
|
||||
return {
|
||||
issueCredentials,
|
||||
revokeCredentials,
|
||||
rotateCredentials,
|
||||
getSecretsPayload
|
||||
};
|
||||
};
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
|
||||
import {
|
||||
BaseCreateSecretRotationSchema,
|
||||
BaseSecretRotationSchema,
|
||||
BaseUpdateSecretRotationSchema
|
||||
} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-schemas";
|
||||
import {
|
||||
SqlCredentialsRotationGeneratedCredentialsSchema,
|
||||
SqlCredentialsRotationParametersSchema,
|
||||
SqlCredentialsRotationTemplateSchema
|
||||
} from "@app/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-schemas";
|
||||
import { SecretRotations } from "@app/lib/api-docs";
|
||||
import { SecretNameSchema } from "@app/server/lib/schemas";
|
||||
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||
|
||||
export const MongoDBCredentialsRotationGeneratedCredentialsSchema = SqlCredentialsRotationGeneratedCredentialsSchema;
|
||||
export const MongoDBCredentialsRotationParametersSchema = SqlCredentialsRotationParametersSchema;
|
||||
export const MongoDBCredentialsRotationTemplateSchema = SqlCredentialsRotationTemplateSchema;
|
||||
|
||||
const MongoDBCredentialsRotationSecretsMappingSchema = z.object({
|
||||
username: SecretNameSchema.describe(SecretRotations.SECRETS_MAPPING.MONGODB_CREDENTIALS.username),
|
||||
password: SecretNameSchema.describe(SecretRotations.SECRETS_MAPPING.MONGODB_CREDENTIALS.password)
|
||||
});
|
||||
|
||||
export const MongoDBCredentialsRotationSchema = BaseSecretRotationSchema(SecretRotation.MongoDBCredentials).extend({
|
||||
type: z.literal(SecretRotation.MongoDBCredentials),
|
||||
parameters: MongoDBCredentialsRotationParametersSchema,
|
||||
secretsMapping: MongoDBCredentialsRotationSecretsMappingSchema
|
||||
});
|
||||
|
||||
export const CreateMongoDBCredentialsRotationSchema = BaseCreateSecretRotationSchema(
|
||||
SecretRotation.MongoDBCredentials
|
||||
).extend({
|
||||
parameters: MongoDBCredentialsRotationParametersSchema,
|
||||
secretsMapping: MongoDBCredentialsRotationSecretsMappingSchema
|
||||
});
|
||||
|
||||
export const UpdateMongoDBCredentialsRotationSchema = BaseUpdateSecretRotationSchema(
|
||||
SecretRotation.MongoDBCredentials
|
||||
).extend({
|
||||
parameters: MongoDBCredentialsRotationParametersSchema.optional(),
|
||||
secretsMapping: MongoDBCredentialsRotationSecretsMappingSchema.optional()
|
||||
});
|
||||
|
||||
export const MongoDBCredentialsRotationListItemSchema = z.object({
|
||||
name: z.literal("MongoDB Credentials"),
|
||||
connection: z.literal(AppConnection.MongoDB),
|
||||
type: z.literal(SecretRotation.MongoDBCredentials),
|
||||
template: MongoDBCredentialsRotationTemplateSchema
|
||||
});
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { TMongoDBConnection } from "@app/services/app-connection/mongodb";
|
||||
|
||||
import {
|
||||
CreateMongoDBCredentialsRotationSchema,
|
||||
MongoDBCredentialsRotationGeneratedCredentialsSchema,
|
||||
MongoDBCredentialsRotationListItemSchema,
|
||||
MongoDBCredentialsRotationSchema
|
||||
} from "./mongodb-credentials-rotation-schemas";
|
||||
|
||||
export type TMongoDBCredentialsRotation = z.infer<typeof MongoDBCredentialsRotationSchema>;
|
||||
|
||||
export type TMongoDBCredentialsRotationInput = z.infer<typeof CreateMongoDBCredentialsRotationSchema>;
|
||||
|
||||
export type TMongoDBCredentialsRotationListItem = z.infer<typeof MongoDBCredentialsRotationListItemSchema>;
|
||||
|
||||
export type TMongoDBCredentialsRotationWithConnection = TMongoDBCredentialsRotation & {
|
||||
connection: TMongoDBConnection;
|
||||
};
|
||||
|
||||
export type TMongoDBCredentialsRotationGeneratedCredentials = z.infer<
|
||||
typeof MongoDBCredentialsRotationGeneratedCredentialsSchema
|
||||
>;
|
||||
@@ -9,6 +9,7 @@ import { AUTH0_CLIENT_SECRET_ROTATION_LIST_OPTION } from "./auth0-client-secret"
|
||||
import { AWS_IAM_USER_SECRET_ROTATION_LIST_OPTION } from "./aws-iam-user-secret";
|
||||
import { AZURE_CLIENT_SECRET_ROTATION_LIST_OPTION } from "./azure-client-secret";
|
||||
import { LDAP_PASSWORD_ROTATION_LIST_OPTION, TLdapPasswordRotation } from "./ldap-password";
|
||||
import { MONGODB_CREDENTIALS_ROTATION_LIST_OPTION } from "./mongodb-credentials";
|
||||
import { MSSQL_CREDENTIALS_ROTATION_LIST_OPTION } from "./mssql-credentials";
|
||||
import { MYSQL_CREDENTIALS_ROTATION_LIST_OPTION } from "./mysql-credentials";
|
||||
import { OKTA_CLIENT_SECRET_ROTATION_LIST_OPTION } from "./okta-client-secret";
|
||||
@@ -37,7 +38,8 @@ const SECRET_ROTATION_LIST_OPTIONS: Record<SecretRotation, TSecretRotationV2List
|
||||
[SecretRotation.AwsIamUserSecret]: AWS_IAM_USER_SECRET_ROTATION_LIST_OPTION,
|
||||
[SecretRotation.LdapPassword]: LDAP_PASSWORD_ROTATION_LIST_OPTION,
|
||||
[SecretRotation.OktaClientSecret]: OKTA_CLIENT_SECRET_ROTATION_LIST_OPTION,
|
||||
[SecretRotation.RedisCredentials]: REDIS_CREDENTIALS_ROTATION_LIST_OPTION
|
||||
[SecretRotation.RedisCredentials]: REDIS_CREDENTIALS_ROTATION_LIST_OPTION,
|
||||
[SecretRotation.MongoDBCredentials]: MONGODB_CREDENTIALS_ROTATION_LIST_OPTION
|
||||
};
|
||||
|
||||
export const listSecretRotationOptions = () => {
|
||||
|
||||
@@ -84,6 +84,7 @@ import { TSecretVersionV2TagDALFactory } from "@app/services/secret-v2-bridge/se
|
||||
|
||||
import { TGatewayV2ServiceFactory } from "../gateway-v2/gateway-v2-service";
|
||||
import { awsIamUserSecretRotationFactory } from "./aws-iam-user-secret/aws-iam-user-secret-rotation-fns";
|
||||
import { mongodbCredentialsRotationFactory } from "./mongodb-credentials/mongodb-credentials-rotation-fns";
|
||||
import { oktaClientSecretRotationFactory } from "./okta-client-secret/okta-client-secret-rotation-fns";
|
||||
import { redisCredentialsRotationFactory } from "./redis-credentials/redis-credentials-rotation-fns";
|
||||
import { TSecretRotationV2DALFactory } from "./secret-rotation-v2-dal";
|
||||
@@ -134,7 +135,8 @@ const SECRET_ROTATION_FACTORY_MAP: Record<SecretRotation, TRotationFactoryImplem
|
||||
[SecretRotation.AwsIamUserSecret]: awsIamUserSecretRotationFactory as TRotationFactoryImplementation,
|
||||
[SecretRotation.LdapPassword]: ldapPasswordRotationFactory as TRotationFactoryImplementation,
|
||||
[SecretRotation.OktaClientSecret]: oktaClientSecretRotationFactory as TRotationFactoryImplementation,
|
||||
[SecretRotation.RedisCredentials]: redisCredentialsRotationFactory as TRotationFactoryImplementation
|
||||
[SecretRotation.RedisCredentials]: redisCredentialsRotationFactory as TRotationFactoryImplementation,
|
||||
[SecretRotation.MongoDBCredentials]: mongodbCredentialsRotationFactory as TRotationFactoryImplementation
|
||||
};
|
||||
|
||||
export const secretRotationV2ServiceFactory = ({
|
||||
|
||||
@@ -35,6 +35,12 @@ import {
|
||||
TLdapPasswordRotationListItem,
|
||||
TLdapPasswordRotationWithConnection
|
||||
} from "./ldap-password";
|
||||
import {
|
||||
TMongoDBCredentialsRotation,
|
||||
TMongoDBCredentialsRotationInput,
|
||||
TMongoDBCredentialsRotationListItem,
|
||||
TMongoDBCredentialsRotationWithConnection
|
||||
} from "./mongodb-credentials";
|
||||
import {
|
||||
TMsSqlCredentialsRotation,
|
||||
TMsSqlCredentialsRotationInput,
|
||||
@@ -86,7 +92,8 @@ export type TSecretRotationV2 =
|
||||
| TLdapPasswordRotation
|
||||
| TAwsIamUserSecretRotation
|
||||
| TOktaClientSecretRotation
|
||||
| TRedisCredentialsRotation;
|
||||
| TRedisCredentialsRotation
|
||||
| TMongoDBCredentialsRotation;
|
||||
|
||||
export type TSecretRotationV2WithConnection =
|
||||
| TPostgresCredentialsRotationWithConnection
|
||||
@@ -98,7 +105,8 @@ export type TSecretRotationV2WithConnection =
|
||||
| TLdapPasswordRotationWithConnection
|
||||
| TAwsIamUserSecretRotationWithConnection
|
||||
| TOktaClientSecretRotationWithConnection
|
||||
| TRedisCredentialsRotationWithConnection;
|
||||
| TRedisCredentialsRotationWithConnection
|
||||
| TMongoDBCredentialsRotationWithConnection;
|
||||
|
||||
export type TSecretRotationV2GeneratedCredentials =
|
||||
| TSqlCredentialsRotationGeneratedCredentials
|
||||
@@ -119,7 +127,8 @@ export type TSecretRotationV2Input =
|
||||
| TLdapPasswordRotationInput
|
||||
| TAwsIamUserSecretRotationInput
|
||||
| TOktaClientSecretRotationInput
|
||||
| TRedisCredentialsRotationInput;
|
||||
| TRedisCredentialsRotationInput
|
||||
| TMongoDBCredentialsRotationInput;
|
||||
|
||||
export type TSecretRotationV2ListItem =
|
||||
| TPostgresCredentialsRotationListItem
|
||||
@@ -131,7 +140,8 @@ export type TSecretRotationV2ListItem =
|
||||
| TLdapPasswordRotationListItem
|
||||
| TAwsIamUserSecretRotationListItem
|
||||
| TOktaClientSecretRotationListItem
|
||||
| TRedisCredentialsRotationListItem;
|
||||
| TRedisCredentialsRotationListItem
|
||||
| TMongoDBCredentialsRotationListItem;
|
||||
|
||||
export type TSecretRotationV2TemporaryParameters = TLdapPasswordRotationInput["temporaryParameters"] | undefined;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Auth0ClientSecretRotationSchema } from "@app/ee/services/secret-rotatio
|
||||
import { AwsIamUserSecretRotationSchema } from "@app/ee/services/secret-rotation-v2/aws-iam-user-secret";
|
||||
import { AzureClientSecretRotationSchema } from "@app/ee/services/secret-rotation-v2/azure-client-secret";
|
||||
import { LdapPasswordRotationSchema } from "@app/ee/services/secret-rotation-v2/ldap-password";
|
||||
import { MongoDBCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/mongodb-credentials";
|
||||
import { MsSqlCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/mssql-credentials";
|
||||
import { MySqlCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/mysql-credentials";
|
||||
import { OktaClientSecretRotationSchema } from "@app/ee/services/secret-rotation-v2/okta-client-secret";
|
||||
@@ -21,5 +22,6 @@ export const SecretRotationV2Schema = z.discriminatedUnion("type", [
|
||||
LdapPasswordRotationSchema,
|
||||
AwsIamUserSecretRotationSchema,
|
||||
OktaClientSecretRotationSchema,
|
||||
RedisCredentialsRotationSchema
|
||||
RedisCredentialsRotationSchema,
|
||||
MongoDBCredentialsRotationSchema
|
||||
]);
|
||||
|
||||
-2
@@ -85,8 +85,6 @@ export const sqlCredentialsRotationFactory: TRotationFactory<
|
||||
const issueCredentials: TRotationFactoryIssueCredentials<TSqlCredentialsRotationGeneratedCredentials> = async (
|
||||
callback
|
||||
) => {
|
||||
// For SQL, since we get existing users, we change both their passwords
|
||||
// on issue to invalidate their existing passwords
|
||||
// For SQL, since we get existing users, we change both their passwords
|
||||
// on issue to invalidate their existing passwords
|
||||
const credentialsSet = [
|
||||
|
||||
@@ -2842,6 +2842,12 @@ export const SecretRotations = {
|
||||
},
|
||||
REDIS_CREDENTIALS: {
|
||||
permissionScope: "The ACL permission scope to assign to the issued Redis users."
|
||||
},
|
||||
MONGODB_CREDENTIALS: {
|
||||
username1:
|
||||
"The username of the first MongoDB user to rotate passwords for. This user must already exist in your database.",
|
||||
username2:
|
||||
"The username of the second MongoDB user to rotate passwords for. This user must already exist in your database."
|
||||
}
|
||||
},
|
||||
SECRETS_MAPPING: {
|
||||
@@ -2872,6 +2878,10 @@ export const SecretRotations = {
|
||||
OKTA_CLIENT_SECRET: {
|
||||
clientId: "The name of the secret that the client ID will be mapped to.",
|
||||
clientSecret: "The name of the secret that the rotated client secret will be mapped to."
|
||||
},
|
||||
MONGODB_CREDENTIALS: {
|
||||
username: "The name of the secret that the active username will be mapped to.",
|
||||
password: "The name of the secret that the generated password will be mapped to."
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -34,6 +34,7 @@ export const validateMongoDBConnectionCredentials = async (config: TMongoDBConne
|
||||
|
||||
const clientOptions: {
|
||||
auth?: { username: string; password?: string };
|
||||
authSource?: string;
|
||||
tls?: boolean;
|
||||
tlsInsecure?: boolean;
|
||||
ca?: string;
|
||||
@@ -43,10 +44,11 @@ export const validateMongoDBConnectionCredentials = async (config: TMongoDBConne
|
||||
username: config.credentials.username,
|
||||
password: config.credentials.password
|
||||
},
|
||||
authSource: config.credentials.database,
|
||||
directConnection: !isSrv
|
||||
};
|
||||
|
||||
if (config.credentials.sslEnabled || isSrv) {
|
||||
if (config.credentials.sslEnabled) {
|
||||
clientOptions.tls = true;
|
||||
clientOptions.tlsInsecure = !config.credentials.sslRejectUnauthorized;
|
||||
if (config.credentials.sslCertificate) {
|
||||
@@ -56,7 +58,6 @@ export const validateMongoDBConnectionCredentials = async (config: TMongoDBConne
|
||||
|
||||
client = new MongoClient(uri, clientOptions);
|
||||
|
||||
// Validate connection by running ping command
|
||||
await client
|
||||
.db(config.credentials.database)
|
||||
.command({ ping: 1 })
|
||||
|
||||
Reference in New Issue
Block a user