Skip to content

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

add support for multiple app connection types in secret rotation

Matheus Nogueira886d7fdff6fa
diff --git a/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-fns.ts
index 8a633bd8cf..ec605cfa94 100644
--- a/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-fns.ts
@@ -10,6 +10,7 @@ import {
TRotationFactoryRotateCredentials
} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";
import { BadRequestError } from "@app/lib/errors";
+import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import {
executeWithPotentialGateway,
getSshConnectionClient,
@@ -211,17 +212,26 @@ export const hpIloRotationFactory: TRotationFactory<
const { connection, parameters, secretsMapping, activeIndex } = secretRotation;
const { username, passwordRequirements, rotationMethod = HpIloRotationMethod.LoginAsRoot } = parameters;
+ const $getSshConnection = () => {
+ if (connection.app !== AppConnection.SSH)
+ throw new BadRequestError({
+ message: "HP iLO Local Account rotations do not support HPE iLO Connections yet. Use an SSH Connection instead."
+ });
+ return connection;
+ };
+
const getRotationSshConfig = async (): Promise<TSshConnectionConfig> => {
+ const sshConnection = $getSshConnection();
const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({
- gatewayId: connection.gatewayId,
- gatewayPoolId: connection.gatewayPoolId
+ gatewayId: sshConnection.gatewayId,
+ gatewayPoolId: sshConnection.gatewayPoolId
});
return {
- method: connection.method,
- app: connection.app,
- orgId: connection.orgId,
+ method: sshConnection.method,
+ app: sshConnection.app,
+ orgId: sshConnection.orgId,
gatewayId: effectiveGatewayId,
- credentials: connection.credentials
+ credentials: sshConnection.credentials
} as TSshConnectionConfig;
};
@@ -229,7 +239,7 @@ export const hpIloRotationFactory: TRotationFactory<
const newPassword = generatePassword(passwordRequirements ?? HP_ILO_DEFAULT_PASSWORD_REQUIREMENTS);
const isSelfRotation = rotationMethod === HpIloRotationMethod.LoginAsTarget;
- if (username === connection.credentials.username)
+ if (username === $getSshConnection().credentials.username)
throw new BadRequestError({ message: "Provided username is used in Infisical app connections." });
const sshConfig = await getRotationSshConfig();
diff --git a/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-schemas.ts b/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-schemas.ts
index 7bf129b443..71a3a40687 100644
--- a/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-schemas.ts
+++ b/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-schemas.ts
@@ -89,6 +89,7 @@ export const UpdateHpIloRotationSchema = BaseUpdateSecretRotationSchema(SecretRo
export const HpIloRotationListItemSchema = z.object({
name: z.literal("HP iLO Local Account"),
connection: z.literal(AppConnection.SSH),
+ additionalConnections: z.array(z.nativeEnum(AppConnection)).optional(),
type: z.literal(SecretRotation.HpIloLocalAccount),
template: HpIloRotationTemplateSchema
});
diff --git a/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-types.ts b/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-types.ts
index c944079c36..fe522c7e85 100644
--- a/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-types.ts
+++ b/backend/src/ee/services/secret-rotation-v2/hp-ilo-rotation/hp-ilo-rotation-types.ts
@@ -1,5 +1,6 @@
import { z } from "zod";
+import { THpeIloConnection } from "@app/services/app-connection/hpe-ilo";
import { TSshConnection } from "@app/services/app-connection/ssh";
import {
@@ -16,7 +17,7 @@ export type THpIloRotationInput = z.infer<typeof CreateHpIloRotationSchema>;
export type THpIloRotationListItem = z.infer<typeof HpIloRotationListItemSchema>;
export type THpIloRotationWithConnection = THpIloRotation & {
- connection: TSshConnection;
+ connection: TSshConnection | THpeIloConnection;
};
export type THpIloRotationGeneratedCredentials = z.infer<typeof HpIloRotationGeneratedCredentialsSchema>;
diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts
index 9ee8b9a805..a7664998b7 100644
--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts
@@ -36,6 +36,7 @@ import { REDIS_CREDENTIALS_ROTATION_LIST_OPTION } from "./redis-credentials";
import { SALESFORCE_OAUTH_CREDENTIALS_ROTATION_LIST_OPTION } from "./salesforce-oauth-credentials";
import { TSecretRotationV2DALFactory } from "./secret-rotation-v2-dal";
import { SecretRotation, SecretRotationStatus } from "./secret-rotation-v2-enums";
+import { getSecretRotationConnectionApps } from "./secret-rotation-v2-maps";
import { TSecretRotationV2ServiceFactory, TSecretRotationV2ServiceFactoryDep } from "./secret-rotation-v2-service";
import {
TSecretRotationRotateSecretsJobPayload,
@@ -91,7 +92,14 @@ const SECRET_ROTATION_LIST_OPTIONS: Record<SecretRotation, TSecretRotationV2List
};
export const listSecretRotationOptions = () => {
- return Object.values(SECRET_ROTATION_LIST_OPTIONS).sort((a, b) => a.name.localeCompare(b.name));
+ return Object.values(SECRET_ROTATION_LIST_OPTIONS)
+ .map((option) => {
+ const additionalConnections = getSecretRotationConnectionApps(option.type).filter(
+ (app) => app !== option.connection
+ );
+ return additionalConnections.length ? { ...option, additionalConnections } : option;
+ })
+ .sort((a, b) => a.name.localeCompare(b.name));
};
const getNextUTCDayInterval = ({ hours, minutes }: TSecretRotationV2["rotateAtUtc"] = { hours: 0, minutes: 0 }) => {
diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-maps.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-maps.ts
index 0e0a14ce69..ee93af03e1 100644
--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-maps.ts
+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-maps.ts
@@ -66,3 +66,12 @@ export const SECRET_ROTATION_CONNECTION_MAP: Record<SecretRotation, AppConnectio
[SecretRotation.StripeApiKey]: AppConnection.Stripe,
[SecretRotation.GcpServiceAccountKey]: AppConnection.GCP
};
+
+const SECRET_ROTATION_ADDITIONAL_CONNECTION_MAP: Partial<Record<SecretRotation, AppConnection[]>> = {
+ [SecretRotation.HpIloLocalAccount]: [AppConnection.HpeIloRedFish]
+};
+
+export const getSecretRotationConnectionApps = (type: SecretRotation): [AppConnection, ...AppConnection[]] => [
+ SECRET_ROTATION_CONNECTION_MAP[type],
+ ...(SECRET_ROTATION_ADDITIONAL_CONNECTION_MAP[type] ?? [])
+];
diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-schemas.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-schemas.ts
index d7b885c928..cf6f0ee1a0 100644
--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-schemas.ts
+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-schemas.ts
@@ -2,7 +2,7 @@ import { z } from "zod";
import { SecretRotationsV2Schema } from "@app/db/schemas/secret-rotations-v2";
import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
-import { SECRET_ROTATION_CONNECTION_MAP } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-maps";
+import { getSecretRotationConnectionApps } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-maps";
import { SecretRotations } from "@app/lib/api-docs";
import { removeTrailingSlash } from "@app/lib/fn";
import { slugSchema } from "@app/server/lib/schemas";
@@ -23,7 +23,7 @@ export const BaseSecretRotationSchema = (type: SecretRotation) =>
secretsMapping: true
}).extend({
connection: z.object({
- app: z.literal(SECRET_ROTATION_CONNECTION_MAP[type]),
+ app: z.enum(getSecretRotationConnectionApps(type)),
name: z.string(),
id: z.string().uuid()
}),
diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts
index fcc8d1255d..7487fc05ee 100644
--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts
+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts
@@ -38,7 +38,7 @@ import {
throwOnImmutableParameterUpdate
} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-fns";
import {
- SECRET_ROTATION_CONNECTION_MAP,
+ getSecretRotationConnectionApps,
SECRET_ROTATION_NAME_MAP
} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-maps";
import {
@@ -74,6 +74,7 @@ import { recordSecretRotationOutcomeMetric } from "@app/lib/telemetry/metrics";
import { OrderByDirection, OrgServiceActor } from "@app/lib/types";
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
+import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { decryptAppConnection } from "@app/services/app-connection/app-connection-fns";
import { TAppConnectionServiceFactory } from "@app/services/app-connection/app-connection-service";
import { ActorType } from "@app/services/auth/auth-type";
@@ -432,7 +433,7 @@ export const secretRotationV2ServiceFactory = ({
getSecretRotationSubject(secretRotation)
);
- if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])
+ if (!getSecretRotationConnectionApps(type).includes(connection.app as AppConnection))
throw new BadRequestError({
message: `Secret Rotation with ID "${rotationId}" is not configured for ${SECRET_ROTATION_NAME_MAP[type]}`
});
@@ -475,7 +476,7 @@ export const secretRotationV2ServiceFactory = ({
getSecretRotationSubject(secretRotation)
);
- if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])
+ if (!getSecretRotationConnectionApps(type).includes(connection.app as AppConnection))
throw new BadRequestError({
message: `Secret Rotation with ID "${rotationId}" is not configured for ${SECRET_ROTATION_NAME_MAP[type]}`
});
@@ -537,7 +538,7 @@ export const secretRotationV2ServiceFactory = ({
getSecretRotationSubject(secretRotation)
);
- if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])
+ if (!getSecretRotationConnectionApps(type).includes(connection.app as AppConnection))
throw new BadRequestError({
message: `Secret Rotation with ID "${rotationId}" is not configured for ${SECRET_ROTATION_NAME_MAP[type]}`
});
@@ -597,11 +598,9 @@ export const secretRotationV2ServiceFactory = ({
message: `Could not find folder with path "${secretPath}" in environment "${environment}" for project with ID "${projectId}"`
});
- const typeApp = SECRET_ROTATION_CONNECTION_MAP[payload.type];
-
// validates permission to connect and app is valid for rotation type
const connection = await appConnectionService.validateAppConnectionUsageById(
- typeApp,
+ getSecretRotationConnectionApps(payload.type),
{ connectionId: payload.connectionId, projectId },
actor
);
@@ -815,7 +814,7 @@ export const secretRotationV2ServiceFactory = ({
getSecretRotationSubject(secretRotation)
);
- if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])
+ if (!getSecretRotationConnectionApps(type).includes(connection.app as AppConnection))
throw new BadRequestError({
message: `Secret Rotation with ID "${rotationId}" is not configured for ${SECRET_ROTATION_NAME_MAP[type]}`
});
@@ -965,7 +964,7 @@ export const secretRotationV2ServiceFactory = ({
getSecretRotationSubject(secretRotation)
);
- if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])
+ if (!getSecretRotationConnectionApps(type).includes(connection.app as AppConnection))
throw new BadRequestError({
message: `Secret Rotation with ID "${rotationId}" is not configured for ${SECRET_ROTATION_NAME_MAP[type]}`
});
@@ -1062,7 +1061,7 @@ export const secretRotationV2ServiceFactory = ({
const { projectId, folderId: sourceFolderId, secretsMapping, folder, environment, connection } = secretRotation;
- if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])
+ if (!getSecretRotationConnectionApps(type).includes(connection.app as AppConnection))
throw new BadRequestError({
message: `Secret Rotation with ID "${rotationId}" is not configured for ${SECRET_ROTATION_NAME_MAP[type]}`
});
@@ -1592,7 +1591,7 @@ export const secretRotationV2ServiceFactory = ({
getSecretRotationSubject(secretRotation)
);
- if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])
+ if (!getSecretRotationConnectionApps(type).includes(connection.app as AppConnection))
throw new BadRequestError({
message: `Secret Rotation with ID "${rotationId}" is not configured for ${SECRET_ROTATION_NAME_MAP[type]}`
});
@@ -1651,7 +1650,7 @@ export const secretRotationV2ServiceFactory = ({
getSecretRotationSubject(secretRotation)
);
- if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])
+ if (!getSecretRotationConnectionApps(type).includes(connection.app as AppConnection))
throw new BadRequestError({
message: `Secret Rotation with ID "${rotationId}" is not configured for ${SECRET_ROTATION_NAME_MAP[type]}`
});
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index b67d43fd0e..b4287ab959 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -1,7 +1,7 @@
import { AGENT_VAULT_MAX_REFERENCES_PER_FIELD } from "@app/ee/services/agent-vault/agent-vault-variable-fns";
import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
import {
- SECRET_ROTATION_CONNECTION_MAP,
+ getSecretRotationConnectionApps,
SECRET_ROTATION_NAME_MAP
} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-maps";
import { SecretScanningDataSource } from "@app/ee/services/secret-scanning-v2/secret-scanning-v2-enums";
@@ -3565,9 +3565,9 @@ export const SecretRotations = {
projectId: "The ID of the project to create the rotation in.",
environment: `The slug of the project environment to create the rotation in.`,
secretPath: `The secret path of the project to create the rotation in.`,
- connectionId: `The ID of the ${
- APP_CONNECTION_NAME_MAP[SECRET_ROTATION_CONNECTION_MAP[type]]
- } Connection to use for rotation.`,
+ connectionId: `The ID of the ${getSecretRotationConnectionApps(type)
+ .map((app) => APP_CONNECTION_NAME_MAP[app])
+ .join(" or ")} Connection to use for rotation.`,
isAutoRotationEnabled: `Whether secrets should be automatically rotated when the specified rotation interval has elapsed.`,
rotationInterval: `The interval, in days, to automatically rotate secrets.`,
rotateAtUtc: `The hours and minutes rotation should occur at in UTC. Defaults to Midnight (00:00) UTC.`
diff --git a/backend/src/services/app-connection/app-connection-fns.ts b/backend/src/services/app-connection/app-connection-fns.ts
index 14f8e02631..b2df0effda 100644
--- a/backend/src/services/app-connection/app-connection-fns.ts
+++ b/backend/src/services/app-connection/app-connection-fns.ts
@@ -12,7 +12,8 @@ import {
import { getOracleDBConnectionListItem, OracleDBConnectionMethod } from "@app/ee/services/app-connections/oracledb";
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
-import { SECRET_ROTATION_CONNECTION_MAP } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-maps";
+import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
+import { getSecretRotationConnectionApps } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-maps";
import { SECRET_SCANNING_DATA_SOURCE_CONNECTION_MAP } from "@app/ee/services/secret-scanning-v2/secret-scanning-v2-maps";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { crypto } from "@app/lib/crypto/cryptography";
@@ -322,7 +323,7 @@ const SECRET_SYNC_APP_CONNECTION_MAP = Object.fromEntries(
);
const SECRET_ROTATION_APP_CONNECTION_MAP = Object.fromEntries(
- Object.entries(SECRET_ROTATION_CONNECTION_MAP).map(([key, value]) => [value, key])
+ Object.values(SecretRotation).flatMap((type) => getSecretRotationConnectionApps(type).map((app) => [app, type]))
);
const SECRET_SCANNING_APP_CONNECTION_MAP = Object.fromEntries(
@@ -358,18 +359,13 @@ const PKI_APP_CONNECTIONS = [
const AGENT_VAULT_APP_CONNECTIONS = [AppConnection.AWS];
-// connections a Secret Manager feature will use but that no sync or rotation map references yet;
-// drop an entry once its rotation registers in SECRET_ROTATION_CONNECTION_MAP
-const PENDING_SECRET_MANAGER_APP_CONNECTIONS = [AppConnection.HpeIloRedFish];
-
export const isAppConnectionAllowedInProject = (app: AppConnection, projectType?: ProjectType) => {
switch (projectType) {
case ProjectType.SecretManager:
return (
Boolean(SECRET_SYNC_APP_CONNECTION_MAP[app]) ||
Boolean(SECRET_ROTATION_APP_CONNECTION_MAP[app]) ||
- EXTERNAL_MIGRATION_APP_CONNECTIONS.includes(app) ||
- PENDING_SECRET_MANAGER_APP_CONNECTIONS.includes(app)
+ EXTERNAL_MIGRATION_APP_CONNECTIONS.includes(app)
);
case ProjectType.SecretScanning:
return Boolean(SECRET_SCANNING_APP_CONNECTION_MAP[app]);
diff --git a/frontend/src/components/secret-rotations-v2/SecretRotationV2Select.tsx b/frontend/src/components/secret-rotations-v2/SecretRotationV2Select.tsx
index 9b22b0d5a1..0fdb107925 100644
--- a/frontend/src/components/secret-rotations-v2/SecretRotationV2Select.tsx
+++ b/frontend/src/components/secret-rotations-v2/SecretRotationV2Select.tsx
@@ -15,7 +15,7 @@ import {
import { ProviderIcon } from "@app/components/v3/platform/ProviderIcon";
import { APP_CONNECTION_MAP } from "@app/helpers/appConnections";
import {
- SECRET_ROTATION_CONNECTION_MAP,
+ getSecretRotationConnectionApps,
SECRET_ROTATION_MAP
} from "@app/helpers/secretRotationsV2";
import { SecretRotation, useSecretRotationV2Options } from "@app/hooks/api/secretRotationsV2";
@@ -26,7 +26,9 @@ type Props = {
const ProviderCard = ({ type, onSelect }: { type: SecretRotation; onSelect: () => void }) => {
const { image, name } = SECRET_ROTATION_MAP[type];
- const connectionName = APP_CONNECTION_MAP[SECRET_ROTATION_CONNECTION_MAP[type]].name;
+ const connectionName = getSecretRotationConnectionApps(type)
+ .map((app) => APP_CONNECTION_MAP[app].name)
+ .join(" or ");
return (
<button
@@ -60,8 +62,10 @@ export const SecretRotationV2Select = ({ onSelect }: Props) => {
return (secretRotationOptions ?? []).filter(({ type }) => {
const { name } = SECRET_ROTATION_MAP[type];
- const connectionName = APP_CONNECTION_MAP[SECRET_ROTATION_CONNECTION_MAP[type]].name;
- return [name, connectionName, type].some((value) => value.toLowerCase().includes(query));
+ const connectionNames = getSecretRotationConnectionApps(type).map(
+ (app) => APP_CONNECTION_MAP[app].name
+ );
+ return [name, ...connectionNames, type].some((value) => value.toLowerCase().includes(query));
});
}, [search, secretRotationOptions]);
diff --git a/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewSecretRotationV2GeneratedCredentials.tsx b/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewSecretRotationV2GeneratedCredentials.tsx
index 14e638b8da..6063110286 100644
--- a/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewSecretRotationV2GeneratedCredentials.tsx
+++ b/frontend/src/components/secret-rotations-v2/ViewSecretRotationV2GeneratedCredentials/ViewSecretRotationV2GeneratedCredentials.tsx
@@ -13,7 +13,6 @@ import { NoticeBannerV2 } from "@app/components/v2/NoticeBannerV2/NoticeBannerV2
import { APP_CONNECTION_MAP } from "@app/helpers/appConnections";
import {
IS_ROTATION_DUAL_CREDENTIALS,
- SECRET_ROTATION_CONNECTION_MAP,
SECRET_ROTATION_MAP
} from "@app/helpers/secretRotationsV2";
import {
@@ -272,7 +271,7 @@ const Content = ({ secretRotation }: ContentProps) => {
throw new Error("Unhandled View Generated Credential Rotation Type");
}
- const appName = APP_CONNECTION_MAP[SECRET_ROTATION_CONNECTION_MAP[type]].name;
+ const appName = APP_CONNECTION_MAP[secretRotation.connection.app].name;
return (
<div className="flex flex-col gap-y-4">
diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ConnectionField.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ConnectionField.tsx
index 854f3505e6..7de3ba50a2 100644
--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ConnectionField.tsx
+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ConnectionField.tsx
@@ -1,4 +1,4 @@
-import { useMemo } from "react";
+import { useMemo, useState } from "react";
import { Controller, useFormContext } from "react-hook-form";
import { SingleValue } from "react-select";
import { subject } from "@casl/ability";
@@ -19,9 +19,13 @@ import {
ProjectPermissionSecretRotationActions
} from "@app/context/ProjectPermissionContext/types";
import { APP_CONNECTION_MAP } from "@app/helpers/appConnections";
-import { SECRET_ROTATION_CONNECTION_MAP } from "@app/helpers/secretRotationsV2";
+import {
+ getSecretRotationConnectionApps,
+ SECRET_ROTATION_CONNECTION_MAP
+} from "@app/helpers/secretRotationsV2";
import { usePopUp } from "@app/hooks";
-import { useListAvailableAppConnections } from "@app/hooks/api/appConnections";
+import { useListAvailableAppConnectionsForApps } from "@app/hooks/api/appConnections";
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { AddAppConnectionModal } from "@app/pages/organization/AppConnections/AppConnectionsPage/components";
import { TSecretRotationV2Form } from "./schemas";
@@ -36,21 +40,22 @@ export const SecretRotationV2ConnectionField = ({ onChange: callback, isUpdate }
const { control, watch, setValue } = useFormContext<TSecretRotationV2Form>();
const { popUp, handlePopUpToggle, handlePopUpOpen } = usePopUp(["addConnection"] as const);
+ const [appToCreate, setAppToCreate] = useState<AppConnection | null>(null);
const rotationType = watch("type");
const environment = watch("environment");
const secretPath = watch("secretPath");
const app = SECRET_ROTATION_CONNECTION_MAP[rotationType];
+ const apps = getSecretRotationConnectionApps(rotationType);
const { currentProject } = useProject();
- const { data: availableConnections, isPending } = useListAvailableAppConnections(
- app,
+ const { connections: availableConnections, isPending } = useListAvailableAppConnectionsForApps(
+ apps,
currentProject.id
);
const allowedConnections = useMemo(() => {
- if (!availableConnections) return [];
const envSlug = environment?.slug;
if (!envSlug || !secretPath) return availableConnections;
return availableConnections.filter((conn) =>
@@ -65,14 +70,15 @@ export const SecretRotationV2ConnectionField = ({ onChange: callback, isUpdate }
);
}, [availableConnections, permission, environment?.slug, secretPath]);
- const connectionName = APP_CONNECTION_MAP[app].name;
+ const connectionLabel =
+ apps.length > 1 ? "Connection" : `${APP_CONNECTION_MAP[app].name} Connection`;
const canCreateConnection = permission.can(
ProjectPermissionAppConnectionActions.Create,
ProjectPermissionSub.AppConnections
);
- const appName = APP_CONNECTION_MAP[app].name;
+ const appNames = apps.map((accepted) => APP_CONNECTION_MAP[accepted].name).join(" or ");
return (
<>
@@ -83,14 +89,20 @@ export const SecretRotationV2ConnectionField = ({ onChange: callback, isUpdate }
htmlFor="secret-rotation-connection"
tooltip="App Connections can be created from the Organization Settings page."
>
- {connectionName} Connection
+ {connectionLabel}
</FieldLabelWithTooltip>
<FilterableSelect
inputId="secret-rotation-connection"
value={value ?? null}
onBlur={onBlur}
onChange={(newValue) => {
- if ((newValue as SingleValue<{ id: string; name: string }>)?.id === "_create") {
+ const selected = newValue as SingleValue<{
+ id: string;
+ name: string;
+ app?: AppConnection;
+ }>;
+ if (selected?.id?.startsWith("_create")) {
+ setAppToCreate(selected.app ?? app);
handlePopUpOpen("addConnection");
localStorage.setItem(
"secretRotationFormData",
@@ -107,9 +119,20 @@ export const SecretRotationV2ConnectionField = ({ onChange: callback, isUpdate }
}}
isLoading={isPending}
options={[
- ...(canCreateConnection ? [{ id: "_create", name: "Create Connection" }] : []),
+ ...(canCreateConnection
+ ? apps.map((creatable) => ({
+ id: `_create:${creatable}`,
+ name:
+ apps.length > 1
+ ? `Create ${APP_CONNECTION_MAP[creatable].name} Connection`
+ : "Create Connection",
+ app: creatable
+ }))
+ : []),
...allowedConnections
]}
+ groupBy={apps.length > 1 ? "app" : null}
+ getGroupHeaderLabel={(groupApp: AppConnection) => APP_CONNECTION_MAP[groupApp].name}
isDisabled={isUpdate}
placeholder="Select connection..."
getOptionLabel={(option) => option.name}
@@ -127,7 +150,7 @@ export const SecretRotationV2ConnectionField = ({ onChange: callback, isUpdate }
<>
Check out{" "}
<a
- href={`https://infisical.com/docs/integrations/app-connections/${app}`}
+ href={`https://infisical.com/docs/integrations/app-connections/${value?.app ?? app}`}
target="_blank"
className="underline"
rel="noopener noreferrer"
@@ -149,7 +172,7 @@ export const SecretRotationV2ConnectionField = ({ onChange: callback, isUpdate }
<Alert variant="warning">
<InfoIcon />
<AlertDescription>
- You do not have access to any {appName} Connections. Contact an admin to create one.
+ You do not have access to any {appNames} Connections. Contact an admin to create one.
</AlertDescription>
</Alert>
)}
@@ -161,7 +184,7 @@ export const SecretRotationV2ConnectionField = ({ onChange: callback, isUpdate }
}}
projectType={currentProject.type}
projectId={currentProject.id}
- app={app}
+ app={appToCreate ?? app}
onComplete={(connection) => {
if (connection) {
setValue("connection", connection, { shouldValidate: true, shouldDirty: true });
diff --git a/frontend/src/components/secret-rotations-v2/forms/schemas/base-secret-rotation-v2-schema.ts b/frontend/src/components/secret-rotations-v2/forms/schemas/base-secret-rotation-v2-schema.ts
index b9dba18051..32b625e2d4 100644
--- a/frontend/src/components/secret-rotations-v2/forms/schemas/base-secret-rotation-v2-schema.ts
+++ b/frontend/src/components/secret-rotations-v2/forms/schemas/base-secret-rotation-v2-schema.ts
@@ -1,11 +1,16 @@
import { z } from "zod";
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { slugSchema } from "@app/lib/schemas";
export const BaseSecretRotationSchema = z.object({
name: slugSchema({ field: "Name" }),
description: z.string().trim().max(256, "Cannot exceed 256 characters").nullish(),
- connection: z.object({ name: z.string(), id: z.string().uuid() }),
+ connection: z.object({
+ name: z.string(),
+ id: z.string().uuid(),
+ app: z.nativeEnum(AppConnection).optional()
+ }),
environment: z.object({ slug: z.string(), id: z.string(), name: z.string() }),
secretPath: z.string().min(1, "Secret path required"),
isAutoRotationEnabled: z.boolean(),
diff --git a/frontend/src/helpers/secretRotationsV2.ts b/frontend/src/helpers/secretRotationsV2.ts
index 0319f1b2cc..ecac86e2a3 100644
--- a/frontend/src/helpers/secretRotationsV2.ts
+++ b/frontend/src/helpers/secretRotationsV2.ts
@@ -190,6 +190,15 @@ export const SECRET_ROTATION_CONNECTION_MAP: Record<SecretRotation, AppConnectio
[SecretRotation.GcpServiceAccountKey]: AppConnection.GCP
};
+const SECRET_ROTATION_ADDITIONAL_CONNECTION_MAP: Partial<Record<SecretRotation, AppConnection[]>> = {
+ [SecretRotation.HpIloLocalAccount]: [AppConnection.HpeIloRedFish]
+};
+
+export const getSecretRotationConnectionApps = (type: SecretRotation): AppConnection[] => [
+ SECRET_ROTATION_CONNECTION_MAP[type],
+ ...(SECRET_ROTATION_ADDITIONAL_CONNECTION_MAP[type] ?? [])
+];
+
// if a rotation can potentially have downtime due to rotating a single credential set this to false
export const IS_ROTATION_DUAL_CREDENTIALS: Record<SecretRotation, boolean> = {
[SecretRotation.PostgresCredentials]: true,
diff --git a/frontend/src/hooks/api/secretRotationsV2/types/hp-ilo-rotation.ts b/frontend/src/hooks/api/secretRotationsV2/types/hp-ilo-rotation.ts
index c2e1a3057c..e67080e422 100644
--- a/frontend/src/hooks/api/secretRotationsV2/types/hp-ilo-rotation.ts
+++ b/frontend/src/hooks/api/secretRotationsV2/types/hp-ilo-rotation.ts
@@ -39,6 +39,7 @@ export type THpIloRotationOption = {
name: string;
type: SecretRotation.HpIloLocalAccount;
connection: AppConnection.SSH;
+ additionalConnections?: AppConnection[];
template: {
secretsMapping: THpIloRotation["secretsMapping"];
};