Skip to content

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

allow import using project app connection

adilson636ea9924687
diff --git a/backend/src/server/routes/v3/external-migration-router.ts b/backend/src/server/routes/v3/external-migration-router.ts
index 59592bcfad..88e95644e7 100644
--- a/backend/src/server/routes/v3/external-migration-router.ts
+++ b/backend/src/server/routes/v3/external-migration-router.ts
@@ -325,6 +325,9 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
},
schema: {
operationId: "getVaultNamespacesV3",
+ querystring: z.object({
+ connectionId: z.string().uuid().optional()
+ }),
response: {
200: z.object({
namespaces: z.array(z.object({ id: z.string().nullish(), name: z.string().nullish() }))
@@ -334,7 +337,8 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const namespaces = await server.services.migration.getVaultNamespaces({
- actor: req.permission
+ actor: req.permission,
+ connectionId: req.query.connectionId
});
return { namespaces };
@@ -378,7 +382,8 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
schema: {
operationId: "getVaultMountsV3",
querystring: z.object({
- namespace: z.string()
+ namespace: z.string(),
+ connectionId: z.string().uuid().optional()
}),
response: {
200: z.object({
@@ -390,7 +395,8 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
handler: async (req) => {
const mounts = await server.services.migration.getVaultMounts({
actor: req.permission,
- namespace: req.query.namespace
+ namespace: req.query.namespace,
+ connectionId: req.query.connectionId
});
return { mounts };
@@ -440,7 +446,8 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
environment: z.string(),
secretPath: z.string(),
vaultNamespace: z.string(),
- vaultSecretPaths: z.array(z.string()).min(1)
+ vaultSecretPaths: z.array(z.string()).min(1),
+ connectionId: z.string().uuid().optional()
}),
response: {
200: z.object({
@@ -571,7 +578,8 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
operationId: "getVaultSecretPathsV3",
querystring: z.object({
namespace: z.string(),
- mountPath: z.string()
+ mountPath: z.string(),
+ connectionId: z.string().uuid().optional()
}),
response: {
200: z.object({
@@ -584,7 +592,8 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
const secretPaths = await server.services.migration.getVaultSecretPaths({
actor: req.permission,
namespace: req.query.namespace,
- mountPath: req.query.mountPath
+ mountPath: req.query.mountPath,
+ connectionId: req.query.connectionId
});
return { secretPaths };
@@ -695,13 +704,24 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
// ─── Doppler In-Platform Migration Routes ────────────────────────────────────
+ const assertExactlyOneDopplerSelector = (configId?: string, connectionId?: string) => {
+ if (Boolean(configId) === Boolean(connectionId)) {
+ throw new BadRequestError({
+ message: "Exactly one of configId or connectionId must be provided"
+ });
+ }
+ };
+
server.route({
method: "GET",
url: "/doppler/projects",
config: { rateLimit: readLimit },
schema: {
operationId: "getDopplerProjectsV3",
- querystring: z.object({ configId: z.string().uuid() }),
+ querystring: z.object({
+ configId: z.string().uuid().optional(),
+ connectionId: z.string().uuid().optional()
+ }),
response: {
200: z.object({
projects: z
@@ -717,8 +737,10 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
+ assertExactlyOneDopplerSelector(req.query.configId, req.query.connectionId);
const projects = await server.services.migration.getDopplerProjects({
configId: req.query.configId,
+ connectionId: req.query.connectionId,
actor: req.permission
});
return { projects };
@@ -732,7 +754,8 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
schema: {
operationId: "getDopplerEnvironmentsV3",
querystring: z.object({
- configId: z.string().uuid(),
+ configId: z.string().uuid().optional(),
+ connectionId: z.string().uuid().optional(),
projectSlug: z.string().min(1)
}),
response: {
@@ -751,8 +774,10 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
+ assertExactlyOneDopplerSelector(req.query.configId, req.query.connectionId);
const environments = await server.services.migration.getDopplerEnvironments({
configId: req.query.configId,
+ connectionId: req.query.connectionId,
projectSlug: req.query.projectSlug,
actor: req.permission
});
@@ -767,7 +792,8 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
schema: {
operationId: "getDopplerConfigsV3",
querystring: z.object({
- configId: z.string().uuid(),
+ configId: z.string().uuid().optional(),
+ connectionId: z.string().uuid().optional(),
projectSlug: z.string().min(1)
}),
response: {
@@ -786,8 +812,10 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
+ assertExactlyOneDopplerSelector(req.query.configId, req.query.connectionId);
const configs = await server.services.migration.getDopplerConfigs({
configId: req.query.configId,
+ connectionId: req.query.connectionId,
projectSlug: req.query.projectSlug,
actor: req.permission
});
@@ -802,7 +830,8 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
schema: {
operationId: "importDopplerSecretsV3",
body: z.object({
- configId: z.string().uuid(),
+ configId: z.string().uuid().optional(),
+ connectionId: z.string().uuid().optional(),
dopplerProject: z.string().min(1),
dopplerEnvironment: z.string().min(1),
targetProjectId: z.string().min(1),
@@ -815,6 +844,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
+ assertExactlyOneDopplerSelector(req.body.configId, req.body.connectionId);
const result = await server.services.migration.importDopplerSecrets({
...req.body,
actor: req.permission,
diff --git a/backend/src/services/external-migration/external-migration-service.ts b/backend/src/services/external-migration/external-migration-service.ts
index 11084e992b..5a929ebaef 100644
--- a/backend/src/services/external-migration/external-migration-service.ts
+++ b/backend/src/services/external-migration/external-migration-service.ts
@@ -31,6 +31,7 @@ import {
HCVaultAuthType,
JsonValue,
listHCVaultMounts,
+ listHCVaultNamespaces,
listHCVaultPolicies,
listHCVaultSecretPaths,
TGatewayDetails,
@@ -145,7 +146,11 @@ export const externalMigrationServiceFactory = ({
return gatewayDetails;
};
- // Helper to verify admin permissions and get vault connection
+ // CASL is enforced inside connectAppConnectionById for project- or org-scoped connections.
+ const getVaultConnectionById = async (connectionId: string, actor: OrgServiceActor) =>
+ appConnectionService.connectAppConnectionById<THCVaultConnection>(AppConnection.HCVault, connectionId, actor);
+
+ // Org-admin only; resolves via the org-level external migration config matched by namespace.
const getVaultConnectionForNamespace = async (actor: OrgServiceActor, namespace: string, action: string) => {
const { hasRole } = await permissionService.getOrgPermission({
scope: OrganizationActionScope.Any,
@@ -202,6 +207,14 @@ export const externalMigrationServiceFactory = ({
} as THCVaultConnection;
};
+ const resolveVaultConnection = async (
+ actor: OrgServiceActor,
+ { namespace, connectionId, action }: { namespace: string; connectionId?: string; action: string }
+ ) =>
+ connectionId
+ ? getVaultConnectionById(connectionId, actor)
+ : getVaultConnectionForNamespace(actor, namespace, action);
+
const importEnvKeyData = async ({
decryptionKey,
encryptedJson,
@@ -544,7 +557,12 @@ export const externalMigrationServiceFactory = ({
});
};
- const getVaultNamespaces = async ({ actor }: { actor: OrgServiceActor }) => {
+ const getVaultNamespaces = async ({ actor, connectionId }: { actor: OrgServiceActor; connectionId?: string }) => {
+ if (connectionId) {
+ const connection = await getVaultConnectionById(connectionId, actor);
+ return listHCVaultNamespaces(connection, gatewayService, gatewayV2Service);
+ }
+
const { hasRole } = await permissionService.getOrgPermission({
actorId: actor.id,
actor: actor.type,
@@ -593,8 +611,20 @@ export const externalMigrationServiceFactory = ({
return listHCVaultPolicies(namespace, connection, gatewayService, gatewayV2Service, gatewayDetails);
};
- const getVaultMounts = async ({ actor, namespace }: { actor: OrgServiceActor; namespace: string }) => {
- const connection = await getVaultConnectionForNamespace(actor, namespace, "view vault mounts");
+ const getVaultMounts = async ({
+ actor,
+ namespace,
+ connectionId
+ }: {
+ actor: OrgServiceActor;
+ namespace: string;
+ connectionId?: string;
+ }) => {
+ const connection = await resolveVaultConnection(actor, {
+ namespace,
+ connectionId,
+ action: "view vault mounts"
+ });
const gatewayDetails = await getGatewayDetails(connection);
@@ -604,13 +634,19 @@ export const externalMigrationServiceFactory = ({
const getVaultSecretPaths = async ({
actor,
namespace,
- mountPath
+ mountPath,
+ connectionId
}: {
actor: OrgServiceActor;
namespace: string;
mountPath: string;
+ connectionId?: string;
}) => {
- const connection = await getVaultConnectionForNamespace(actor, namespace, "view vault secret paths");
+ const connection = await resolveVaultConnection(actor, {
+ namespace,
+ connectionId,
+ action: "view vault secret paths"
+ });
const gatewayDetails = await getGatewayDetails(connection);
@@ -624,6 +660,7 @@ export const externalMigrationServiceFactory = ({
secretPath,
vaultNamespace,
vaultSecretPaths,
+ connectionId,
auditLogInfo
}: {
actor: OrgServiceActor;
@@ -632,9 +669,14 @@ export const externalMigrationServiceFactory = ({
secretPath: string;
vaultNamespace: string;
vaultSecretPaths: string[];
+ connectionId?: string;
auditLogInfo: AuditLogInfo;
}) => {
- const connection = await getVaultConnectionForNamespace(actor, vaultNamespace, "import vault secrets");
+ const connection = await resolveVaultConnection(actor, {
+ namespace: vaultNamespace,
+ connectionId,
+ action: "import vault secrets"
+ });
if (!vaultSecretPaths.length) {
throw new BadRequestError({ message: "At least one Vault secret path is required" });
@@ -815,6 +857,10 @@ export const externalMigrationServiceFactory = ({
// ─── Doppler In-Platform Migration ──────────────────────────────────────────
+ // CASL is enforced inside connectAppConnectionById for project- or org-scoped connections.
+ const getDopplerConnectionById = async (connectionId: string, actor: OrgServiceActor) =>
+ appConnectionService.connectAppConnectionById<TDopplerConnection>(AppConnection.Doppler, connectionId, actor);
+
const getDopplerConnectionForConfig = async (configId: string, actor: OrgServiceActor) => {
const { hasRole } = await permissionService.getOrgPermission({
scope: OrganizationActionScope.Any,
@@ -848,39 +894,61 @@ export const externalMigrationServiceFactory = ({
return appConnection;
};
- const getDopplerProjects = async ({ configId, actor }: { configId: string; actor: OrgServiceActor }) => {
- const appConnection = await getDopplerConnectionForConfig(configId, actor);
+ const resolveDopplerConnection = async (
+ actor: OrgServiceActor,
+ { configId, connectionId }: { configId?: string; connectionId?: string }
+ ) => {
+ if (connectionId) return getDopplerConnectionById(connectionId, actor);
+ if (configId) return getDopplerConnectionForConfig(configId, actor);
+ throw new BadRequestError({ message: "Either connectionId or configId must be provided" });
+ };
+
+ const getDopplerProjects = async ({
+ configId,
+ connectionId,
+ actor
+ }: {
+ configId?: string;
+ connectionId?: string;
+ actor: OrgServiceActor;
+ }) => {
+ const appConnection = await resolveDopplerConnection(actor, { configId, connectionId });
return listDopplerProjects(appConnection);
};
const getDopplerEnvironments = async ({
configId,
+ connectionId,
projectSlug,
actor
}: {
- configId: string;
+ configId?: string;
+ connectionId?: string;
projectSlug: string;
actor: OrgServiceActor;
}) => {
- const appConnection = await getDopplerConnectionForConfig(configId, actor);
+ const appConnection = await resolveDopplerConnection(actor, { configId, connectionId });
return listDopplerEnvironments(appConnection, projectSlug);
};
const getDopplerConfigs = async ({
configId,
+ connectionId,
projectSlug,
actor
}: {
- configId: string;
+ configId?: string;
+ connectionId?: string;
projectSlug: string;
actor: OrgServiceActor;
}) => {
- const appConnection = await getDopplerConnectionForConfig(configId, actor);
+ const appConnection = await resolveDopplerConnection(actor, { configId, connectionId });
return listDopplerConfigs(appConnection, projectSlug);
};
const importDopplerSecrets = async ({
configId,
+ connectionId,
dopplerProject,
dopplerEnvironment,
targetProjectId,
@@ -889,7 +957,7 @@ export const externalMigrationServiceFactory = ({
actor,
auditLogInfo
}: TImportDopplerSecretsDTO) => {
- const appConnection = await getDopplerConnectionForConfig(configId, actor);
+ const appConnection = await resolveDopplerConnection(actor, { configId, connectionId });
const dopplerSecrets = await getDopplerSecrets(appConnection, dopplerProject, dopplerEnvironment);
diff --git a/backend/src/services/external-migration/external-migration-types.ts b/backend/src/services/external-migration/external-migration-types.ts
index fd3dbfcf45..77b883a247 100644
--- a/backend/src/services/external-migration/external-migration-types.ts
+++ b/backend/src/services/external-migration/external-migration-types.ts
@@ -147,7 +147,8 @@ export type TDeleteDopplerExternalMigrationDTO = {
};
export type TImportDopplerSecretsDTO = {
- configId: string;
+ configId?: string;
+ connectionId?: string;
dopplerProject: string;
dopplerEnvironment: string;
targetProjectId: string;
diff --git a/frontend/src/hooks/api/migration/queries.tsx b/frontend/src/hooks/api/migration/queries.tsx
index a2007f17a3..989e02c16d 100644
--- a/frontend/src/hooks/api/migration/queries.tsx
+++ b/frontend/src/hooks/api/migration/queries.tsx
@@ -20,18 +20,23 @@ export const externalMigrationQueryKeys = {
provider
],
configs: (provider: ExternalMigrationProviders) => ["external-migration-configs", provider],
- vaultNamespaces: () => ["vault-namespaces"],
+ vaultNamespaces: (connectionId?: string) => ["vault-namespaces", connectionId],
vaultPolicies: (namespace?: string) => ["vault-policies", namespace],
- vaultMounts: (namespace?: string) => ["vault-mounts", namespace],
+ vaultMounts: (namespace?: string, connectionId?: string) => [
+ "vault-mounts",
+ namespace,
+ connectionId
+ ],
vaultAuthMounts: (namespace?: string, authType?: string) => [
"vault-auth-mounts",
namespace,
authType
],
- vaultSecretPaths: (namespace?: string, mountPath?: string) => [
+ vaultSecretPaths: (namespace?: string, mountPath?: string, connectionId?: string) => [
"vault-secret-paths",
namespace,
- mountPath
+ mountPath,
+ connectionId
],
vaultKubernetesAuthRoles: (namespace?: string, mountPath?: string) => [
"vault-kubernetes-auth-roles",
@@ -53,16 +58,22 @@ export const externalMigrationQueryKeys = {
namespace,
mountPath
],
- dopplerProjects: (configId?: string) => ["doppler-projects", configId],
- dopplerEnvironments: (configId?: string, projectSlug?: string) => [
+ dopplerProjects: (configId?: string, connectionId?: string) => [
+ "doppler-projects",
+ configId,
+ connectionId
+ ],
+ dopplerEnvironments: (configId?: string, projectSlug?: string, connectionId?: string) => [
"doppler-environments",
configId,
- projectSlug
+ projectSlug,
+ connectionId
],
- dopplerConfigs: (configId?: string, projectSlug?: string) => [
+ dopplerConfigs: (configId?: string, projectSlug?: string, connectionId?: string) => [
"doppler-configs",
configId,
- projectSlug
+ projectSlug,
+ connectionId
]
};
@@ -88,13 +99,15 @@ export const useGetExternalMigrationConfigs = (provider: ExternalMigrationProvid
});
};
-export const useGetVaultNamespaces = () => {
+export const useGetVaultNamespaces = (connectionId?: string) => {
return useQuery({
- queryKey: externalMigrationQueryKeys.vaultNamespaces(),
+ queryKey: externalMigrationQueryKeys.vaultNamespaces(connectionId),
queryFn: async () => {
const { data } = await apiRequest.get<{
namespaces: Array<{ id: string; name: string }>;
- }>("/api/v3/external-migration/vault/namespaces");
+ }>("/api/v3/external-migration/vault/namespaces", {
+ params: connectionId ? { connectionId } : undefined
+ });
return data.namespaces;
}
});
@@ -118,15 +131,16 @@ export const useGetVaultPolicies = (enabled = true, namespace?: string) => {
});
};
-export const useGetVaultMounts = (enabled = true, namespace?: string) => {
+export const useGetVaultMounts = (enabled = true, namespace?: string, connectionId?: string) => {
return useQuery({
- queryKey: externalMigrationQueryKeys.vaultMounts(namespace),
+ queryKey: externalMigrationQueryKeys.vaultMounts(namespace, connectionId),
queryFn: async () => {
const { data } = await apiRequest.get<{
mounts: Array<{ path: string; type: string; version: string | null }>;
}>("/api/v3/external-migration/vault/mounts", {
params: {
- namespace
+ namespace,
+ ...(connectionId ? { connectionId } : {})
}
});
@@ -136,9 +150,14 @@ export const useGetVaultMounts = (enabled = true, namespace?: string) => {
});
};
-export const useGetVaultSecretPaths = (enabled = true, namespace?: string, mountPath?: string) => {
+export const useGetVaultSecretPaths = (
+ enabled = true,
+ namespace?: string,
+ mountPath?: string,
+ connectionId?: string
+) => {
return useQuery({
- queryKey: externalMigrationQueryKeys.vaultSecretPaths(namespace, mountPath),
+ queryKey: externalMigrationQueryKeys.vaultSecretPaths(namespace, mountPath, connectionId),
queryFn: async () => {
if (!namespace || !mountPath) {
throw new Error("Both namespace and mountPath are required");
@@ -149,7 +168,8 @@ export const useGetVaultSecretPaths = (enabled = true, namespace?: string, mount
}>("/api/v3/external-migration/vault/secret-paths", {
params: {
namespace,
- mountPath
+ mountPath,
+ ...(connectionId ? { connectionId } : {})
}
});
@@ -282,50 +302,58 @@ export const useGetVaultLdapRoles = (enabled = true, namespace?: string, mountPa
});
};
-export const useGetDopplerProjects = (configId?: string) => {
+export const useGetDopplerProjects = (configId?: string, connectionId?: string) => {
return useQuery({
- queryKey: externalMigrationQueryKeys.dopplerProjects(configId),
+ queryKey: externalMigrationQueryKeys.dopplerProjects(configId, connectionId),
queryFn: async () => {
const { data } = await apiRequest.get<{ projects: TDopplerProject[] }>(
"/api/v3/external-migration/doppler/projects",
{
- params: { configId }
+ params: connectionId ? { connectionId } : { configId }
}
);
return data.projects;
},
- enabled: !!configId
+ enabled: !!configId || !!connectionId
});
};
-export const useGetDopplerEnvironments = (configId?: string, projectSlug?: string) => {
+export const useGetDopplerEnvironments = (
+ configId?: string,
+ projectSlug?: string,
+ connectionId?: string
+) => {
return useQuery({
- queryKey: externalMigrationQueryKeys.dopplerEnvironments(configId, projectSlug),
+ queryKey: externalMigrationQueryKeys.dopplerEnvironments(configId, projectSlug, connectionId),
queryFn: async () => {
const { data } = await apiRequest.get<{ environments: TDopplerEnvironment[] }>(
"/api/v3/external-migration/doppler/environments",
{
- params: { configId, projectSlug }
+ params: connectionId ? { connectionId, projectSlug } : { configId, projectSlug }
}
);
return data.environments;
},
- enabled: !!configId && !!projectSlug
+ enabled: (!!configId || !!connectionId) && !!projectSlug
});
};
-export const useGetDopplerConfigs = (configId?: string, projectSlug?: string) => {
+export const useGetDopplerConfigs = (
+ configId?: string,
+ projectSlug?: string,
+ connectionId?: string
+) => {
return useQuery({
- queryKey: externalMigrationQueryKeys.dopplerConfigs(configId, projectSlug),
+ queryKey: externalMigrationQueryKeys.dopplerConfigs(configId, projectSlug, connectionId),
queryFn: async () => {
const { data } = await apiRequest.get<{ configs: TDopplerConfig[] }>(
"/api/v3/external-migration/doppler/doppler-configs",
{
- params: { configId, projectSlug }
+ params: connectionId ? { connectionId, projectSlug } : { configId, projectSlug }
}
);
return data.configs;
},
- enabled: !!configId && !!projectSlug
+ enabled: (!!configId || !!connectionId) && !!projectSlug
});
};
diff --git a/frontend/src/hooks/api/migration/types.ts b/frontend/src/hooks/api/migration/types.ts
index 64e9b3a92c..195d7b84e6 100644
--- a/frontend/src/hooks/api/migration/types.ts
+++ b/frontend/src/hooks/api/migration/types.ts
@@ -64,7 +64,8 @@ export type TDopplerConfig = {
};
export type TImportDopplerSecretsDTO = {
- configId: string;
+ configId?: string;
+ connectionId?: string;
dopplerProject: string;
dopplerEnvironment: string;
targetProjectId: string;
@@ -83,6 +84,7 @@ export type TImportVaultSecretsDTO = {
secretPath: string;
vaultNamespace: string;
vaultSecretPaths: string[];
+ connectionId?: string;
};
export type VaultKubernetesAuthRole = {
diff --git a/frontend/src/hooks/index.ts b/frontend/src/hooks/index.ts
index 764c3b2b9d..680a5fd821 100644
--- a/frontend/src/hooks/index.ts
+++ b/frontend/src/hooks/index.ts
@@ -1,3 +1,4 @@
+export { useCanUseAppConnectionImport } from "./useCanUseAppConnectionImport";
export { useDebounce } from "./useDebounce";
export * from "./useGetProjectTypeFromRoute";
export { useLastLogin } from "./useLastLogin";
diff --git a/frontend/src/hooks/useCanUseAppConnectionImport.tsx b/frontend/src/hooks/useCanUseAppConnectionImport.tsx
new file mode 100644
index 0000000000..0ddd1dcb87
--- /dev/null
+++ b/frontend/src/hooks/useCanUseAppConnectionImport.tsx
@@ -0,0 +1,27 @@
+import { useMemo } from "react";
+
+import { ProjectPermissionSub, useProjectPermission } from "@app/context";
+import { ProjectPermissionAppConnectionActions } from "@app/context/ProjectPermissionContext/types";
+
+type Params = {
+ canReadSecrets: boolean;
+ canCreateSecrets: boolean;
+};
+
+export const useCanUseAppConnectionImport = ({ canReadSecrets, canCreateSecrets }: Params) => {
+ const { permission } = useProjectPermission();
+ return useMemo(
+ () =>
+ permission.can(
+ ProjectPermissionAppConnectionActions.Read,
+ ProjectPermissionSub.AppConnections
+ ) &&
+ permission.can(
+ ProjectPermissionAppConnectionActions.Create,
+ ProjectPermissionSub.AppConnections
+ ) &&
+ canReadSecrets &&
+ canCreateSecrets,
+ [permission, canReadSecrets, canCreateSecrets]
+ );
+};
diff --git a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
index ca40e5fe02..65a885c594 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
@@ -97,7 +97,6 @@ import {
ProjectPermissionActions,
ProjectPermissionDynamicSecretActions,
ProjectPermissionSub,
- useOrgPermission,
useProject,
useProjectPermission,
useSubscription
@@ -108,13 +107,13 @@ import {
ProjectPermissionSecretRotationActions
} from "@app/context/ProjectPermissionContext/types";
import { downloadSecretEnvFile } from "@app/helpers/download";
-import { OrgMembershipRole } from "@app/helpers/roles";
import {
getUserTablePreference,
PreferenceKey,
setUserTablePreference
} from "@app/helpers/userTablePreferences";
import {
+ useCanUseAppConnectionImport,
useLocalStorageState,
usePagination,
usePopUp,
@@ -138,6 +137,8 @@ import {
useUpdateSecretImport,
useUpdateSecretV3
} from "@app/hooks/api";
+import { useListAvailableAppConnections } from "@app/hooks/api/appConnections";
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
import {
dashboardKeys,
fetchDashboardProjectSecretsByKeys,
@@ -303,12 +304,9 @@ const OverviewPageContent = () => {
const [searchFilter, setSearchFilter] = useState("");
const secretPath = (routerSearch?.secretPath as string) || "/";
const { subscription } = useSubscription();
- const { hasOrgRole } = useOrgPermission();
- const isOrgAdmin = hasOrgRole(OrgMembershipRole.Admin);
const { data: vaultConfigs = [] } = useGetExternalMigrationConfigs(
ExternalMigrationProviders.Vault
);
- const hasVaultConnection = vaultConfigs.some((config) => config.connectionId);
const { data: dopplerConfigs = [] } = useGetExternalMigrationConfigs(
ExternalMigrationProviders.Doppler
);
@@ -316,7 +314,6 @@ const OverviewPageContent = () => {
() => dopplerConfigs.filter((c) => c.connectionId),
[dopplerConfigs]
);
- const hasDopplerConnection = dopplerImportConfigs.length > 0;
const { mutateAsync: importVaultSecrets } = useImportVaultSecrets();
const { mutateAsync: importDopplerSecrets } = useImportDopplerSecrets();
const prevPageSize = useRef(0);
@@ -522,6 +519,26 @@ const OverviewPageContent = () => {
? permission.can(ProjectPermissionSecretActions.Create, secretSubject)
: true;
+ const canUseAppConnectionImport = useCanUseAppConnectionImport({
+ canReadSecrets,
+ canCreateSecrets
+ });
+
+ const { data: vaultAppConnections = [] } = useListAvailableAppConnections(
+ AppConnection.HCVault,
+ projectId,
+ { enabled: canUseAppConnectionImport }
+ );
+ const { data: dopplerAppConnections = [] } = useListAvailableAppConnections(
+ AppConnection.Doppler,
+ projectId,
+ { enabled: canUseAppConnectionImport }
+ );
+
+ const hasVaultConnection =
+ vaultAppConnections.length > 0 || vaultConfigs.some((config) => config.connectionId);
+ const hasDopplerConnection = dopplerAppConnections.length > 0 || dopplerImportConfigs.length > 0;
+
const singleEnvChangesCount = subscription.pitRecovery ? singleEnvCommitCount : 0;
const isSingleEnvChangesCountLoading = subscription.pitRecovery
? isSingleEnvCommitCountPending && isSingleEnvCommitCountFetching
@@ -874,13 +891,18 @@ const OverviewPageContent = () => {
handlePopUpOpen("addSecretImport");
};
- const handleVaultImport = async (vaultPaths: string[], namespace: string) => {
+ const handleVaultImport = async (
+ vaultPaths: string[],
+ namespace: string,
+ connectionId?: string
+ ) => {
const { status } = await importVaultSecrets({
projectId,
environment: singleEnvSlug,
secretPath,
vaultNamespace: namespace,
- vaultSecretPaths: vaultPaths
+ vaultSecretPaths: vaultPaths,
+ connectionId
});
if (status === ExternalMigrationImportStatus.ApprovalRequired) {
@@ -905,10 +927,10 @@ const OverviewPageContent = () => {
const handleDopplerImport = async (
dopplerProject: string,
dopplerEnvironment: string,
- configId: string
+ selector: { configId?: string; connectionId?: string }
) => {
await importDopplerSecrets({
- configId,
+ ...selector,
dopplerProject,
dopplerEnvironment,
targetProjectId: projectId,
@@ -2605,7 +2627,6 @@ const OverviewPageContent = () => {
isSingleEnvSelected={isSingleEnvView}
hasVaultConnection={hasVaultConnection}
hasDopplerConnection={hasDopplerConnection}
- isOrgAdmin={isOrgAdmin}
onImportFromVault={() => handlePopUpOpen("importFromVault")}
onImportFromDoppler={() => handlePopUpOpen("importFromDoppler")}
/>
@@ -3627,13 +3648,15 @@ const OverviewPageContent = () => {
onOpenChange={(isOpen) => handlePopUpToggle("importFromVault", isOpen)}
environment={singleEnvSlug}
secretPath={secretPath}
+ appConnections={vaultAppConnections}
onImport={handleVaultImport}
/>
- {dopplerImportConfigs.length > 0 && (
+ {hasDopplerConnection && (
<DopplerSecretImportModal
isOpen={popUp.importFromDoppler.isOpen}
onOpenChange={(isOpen) => handlePopUpToggle("importFromDoppler", isOpen)}
configs={dopplerImportConfigs}
+ appConnections={dopplerAppConnections}
environment={singleEnvSlug}
secretPath={secretPath}
onImport={handleDopplerImport}
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx
index 8c79a21aff..efef2f56e2 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/AddResourceButtons/AddResourceButtons.tsx
@@ -44,7 +44,6 @@ type Props = {
isSingleEnvSelected: boolean;
hasVaultConnection: boolean;
hasDopplerConnection: boolean;
- isOrgAdmin: boolean;
};
export function AddResourceButtons({
@@ -65,15 +64,8 @@ export function AddResourceButtons({
isSecretImportAvailable,
isSingleEnvSelected,
hasVaultConnection,
- hasDopplerConnection,
- isOrgAdmin
+ hasDopplerConnection
}: Props) {
- const getInPlatformImportTooltip = (platform: string) => {
- if (!isOrgAdmin) return `Only organization admins can import secrets from ${platform}`;
- if (!isSingleEnvSelected) return `Select a single environment to import from ${platform}`;
- return "Access Restricted";
- };
-
return (
<ButtonGroup>
<ProjectPermissionCan I={ProjectPermissionActions.Create} a={ProjectPermissionSub.Secrets}>
@@ -205,68 +197,68 @@ export function AddResourceButtons({
</Tooltip>
)}
</ProjectPermissionCan>
- {hasVaultConnection && (
- <ProjectPermissionCan
- I={ProjectPermissionActions.Create}
- a={ProjectPermissionSub.Secrets}
- >
- {(isAllowed) => (
- <Tooltip
- open={!isAllowed || !isOrgAdmin || !isSingleEnvSelected ? undefined : false}
- >
- <TooltipTrigger className="block w-full">
- <DropdownMenuItem
- onClick={onImportFromVault}
- isDisabled={!isAllowed || !isOrgAdmin || !isSingleEnvSelected}
- >
- <div className="flex w-4.5 justify-center rounded-full bg-foreground/75">
- <img
- src="/images/integrations/Vault.png"
- alt="HashiCorp Vault"
- className="mt-0.5 h-4 w-4"
- />
- </div>
- Add from HashiCorp Vault
- </DropdownMenuItem>
- </TooltipTrigger>
- <TooltipContent side="left">
- {getInPlatformImportTooltip("HashiCorp Vault")}
- </TooltipContent>
- </Tooltip>
- )}
- </ProjectPermissionCan>
- )}
- {hasDopplerConnection && (
- <ProjectPermissionCan
- I={ProjectPermissionActions.Create}
- a={ProjectPermissionSub.Secrets}
- >
- {(isAllowed) => (
- <Tooltip
- open={!isAllowed || !isOrgAdmin || !isSingleEnvSelected ? undefined : false}
- >
- <TooltipTrigger className="block w-full">
- <DropdownMenuItem
- onClick={onImportFromDoppler}
- isDisabled={!isAllowed || !isOrgAdmin || !isSingleEnvSelected}
- >
- <div className="flex w-4.5 justify-center rounded-full bg-foreground/75">
- <img
- src="/images/integrations/Doppler.png"
- alt="Doppler"
- className="mt-0.5 h-4 w-4"
- />
- </div>
- Add from Doppler
- </DropdownMenuItem>
- </TooltipTrigger>
- <TooltipContent side="left">
- {getInPlatformImportTooltip("Doppler")}
- </TooltipContent>
- </Tooltip>
- )}
- </ProjectPermissionCan>
- )}
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Create}
+ a={ProjectPermissionSub.Secrets}
+ >
+ {(isAllowed) => (
+ <Tooltip
+ open={!isAllowed || !isSingleEnvSelected || !hasVaultConnection ? undefined : false}
+ >
+ <TooltipTrigger className="block w-full">
+ <DropdownMenuItem
+ onClick={onImportFromVault}
+ isDisabled={!isAllowed || !isSingleEnvSelected || !hasVaultConnection}
+ >
+ <div className="flex w-4.5 justify-center rounded-full bg-foreground/75">
+ <img
+ src="/images/integrations/Vault.png"
+ alt="HashiCorp Vault"
+ className="mt-0.5 h-4 w-4"
+ />
+ </div>
+ Add from HashiCorp Vault
+ </DropdownMenuItem>
+ </TooltipTrigger>
+ <TooltipContent side="left">
+ {!hasVaultConnection
+ ? "No HashiCorp Vault connection found"
+ : "Access Restricted"}
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </ProjectPermissionCan>
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Create}
+ a={ProjectPermissionSub.Secrets}
+ >
+ {(isAllowed) => (
+ <Tooltip
+ open={
+ !isAllowed || !isSingleEnvSelected || !hasDopplerConnection ? undefined : false
+ }
+ >
+ <TooltipTrigger className="block w-full">
+ <DropdownMenuItem
+ onClick={onImportFromDoppler}
+ isDisabled={!isAllowed || !isSingleEnvSelected || !hasDopplerConnection}
+ >
+ <div className="flex w-4.5 justify-center rounded-full bg-foreground/75">
+ <img
+ src="/images/integrations/Doppler.png"
+ alt="Doppler"
+ className="mt-0.5 h-4 w-4"
+ />
+ </div>
+ Add from Doppler
+ </DropdownMenuItem>
+ </TooltipTrigger>
+ <TooltipContent side="left">
+ {!hasDopplerConnection ? "No Doppler connection found" : "Access Restricted"}
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </ProjectPermissionCan>
</DropdownMenuContent>
</DropdownMenu>
</ButtonGroup>
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/ActionBar.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/ActionBar.tsx
index 05313880f8..3b41c985c8 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/ActionBar.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/ActionBar.tsx
@@ -1,3 +1,4 @@
+import { useMemo } from "react";
import { TypeOptions } from "react-toastify";
import { subject } from "@casl/ability";
import {
@@ -62,7 +63,6 @@ import {
ProjectPermissionActions,
ProjectPermissionDynamicSecretActions,
ProjectPermissionSub,
- useOrgPermission,
useProject,
useProjectPermission,
useSubscription
@@ -72,8 +72,7 @@ import {
ProjectPermissionSecretActions,
ProjectPermissionSecretRotationActions
} from "@app/context/ProjectPermissionContext/types";
-import { OrgMembershipRole } from "@app/helpers/roles";
-import { usePopUp } from "@app/hooks";
+import { useCanUseAppConnectionImport, usePopUp } from "@app/hooks";
import {
useCreateFolder,
useCreateSecretBatch,
@@ -81,6 +80,8 @@ import {
useMoveSecrets,
useUpdateSecretBatch
} from "@app/hooks/api";
+import { useListAvailableAppConnections } from "@app/hooks/api/appConnections";
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
import {
dashboardKeys,
fetchDashboardProjectSecretsByKeys
@@ -219,9 +220,30 @@ export const ActionBar = ({
const { data: vaultConfigs = [] } = useGetExternalMigrationConfigs(
ExternalMigrationProviders.Vault
);
- const hasVaultConnection = vaultConfigs.some((config) => config.connectionId);
- const { hasOrgRole } = useOrgPermission();
- const isOrgAdmin = hasOrgRole(OrgMembershipRole.Admin);
+ const vaultSecretSubject = useMemo(
+ () =>
+ subject(ProjectPermissionSub.Secrets, {
+ environment,
+ secretPath,
+ secretName: "*",
+ secretTags: ["*"]
+ }),
+ [environment, secretPath]
+ );
+ const canUseAppConnectionImport = useCanUseAppConnectionImport({
+ canReadSecrets: permission.can(
+ ProjectPermissionSecretActions.DescribeSecret,
+ vaultSecretSubject
+ ),
+ canCreateSecrets: permission.can(ProjectPermissionSecretActions.Create, vaultSecretSubject)
+ });
+ const { data: vaultAppConnections = [] } = useListAvailableAppConnections(
+ AppConnection.HCVault,
+ projectId,
+ { enabled: canUseAppConnectionImport }
+ );
+ const hasVaultConnection =
+ vaultAppConnections.length > 0 || vaultConfigs.some((config) => config.connectionId);
const handleFolderCreate = async (folderName: string, description: string | null) => {
if (isBatchMode) {
@@ -678,13 +700,18 @@ export const ActionBar = ({
}
};
- const handleVaultImport = async (vaultPaths: string[], namespace: string) => {
+ const handleVaultImport = async (
+ vaultPaths: string[],
+ namespace: string,
+ connectionId?: string
+ ) => {
const { status } = await importVaultSecrets({
projectId,
environment,
secretPath,
vaultNamespace: namespace,
- vaultSecretPaths: vaultPaths
+ vaultSecretPaths: vaultPaths,
+ connectionId
});
if (status === ExternalMigrationImportStatus.ApprovalRequired) {
@@ -1122,33 +1149,25 @@ export const ActionBar = ({
})}
>
{(isAllowed) => (
- <Tooltip
- content={
- !isOrgAdmin
- ? "Only organization admins can import secrets from HashiCorp Vault"
- : undefined
+ <Button
+ leftIcon={
+ <img
+ src="/images/integrations/Vault.png"
+ alt="HashiCorp Vault"
+ className="h-4 w-4"
+ />
}
+ onClick={() => {
+ handlePopUpOpen("importFromVault");
+ handlePopUpClose("misc");
+ }}
+ isDisabled={!isAllowed}
+ variant="outline_bg"
+ className="h-10 text-left"
+ isFullWidth
>
- <Button
- leftIcon={
- <img
- src="/images/integrations/Vault.png"
- alt="HashiCorp Vault"
- className="h-4 w-4"
- />
- }
- onClick={() => {
- handlePopUpOpen("importFromVault");
- handlePopUpClose("misc");
- }}
- isDisabled={!isAllowed || !isOrgAdmin}
- variant="outline_bg"
- className="h-10 text-left"
- isFullWidth
- >
- Add from HashiCorp Vault
- </Button>
- </Tooltip>
+ Add from HashiCorp Vault
+ </Button>
)}
</ProjectPermissionCan>
)}
@@ -1384,6 +1403,7 @@ export const ActionBar = ({
onOpenChange={(isOpen) => handlePopUpToggle("importFromVault", isOpen)}
environment={environment}
secretPath={secretPath}
+ appConnections={vaultAppConnections}
onImport={handleVaultImport}
/>
</>
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/DopplerSecretImportModal.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/DopplerSecretImportModal.tsx
index aff2609235..23d9057c38 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/DopplerSecretImportModal.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/DopplerSecretImportModal.tsx
@@ -21,24 +21,39 @@ import {
} from "@app/components/v3";
import { FilterableSelect } from "@app/components/v3/generic/ReactSelect";
import { useListAppConnections } from "@app/hooks/api/appConnections/queries";
+import { TAvailableAppConnection } from "@app/hooks/api/appConnections/types";
import { useGetDopplerConfigs, useGetDopplerProjects } from "@app/hooks/api/migration/queries";
import { TDopplerConfig, TExternalMigrationConfig } from "@app/hooks/api/migration/types";
+type SourceKind = "config" | "connection";
+
const schema = z.object({
- configId: z.string().min(1, "Doppler configuration is required"),
+ sourceId: z.string().min(1, "Doppler source is required"),
+ sourceKind: z.enum(["config", "connection"]),
dopplerProject: z.string().min(1, "Doppler project is required"),
dopplerEnvironment: z.string().min(1, "Doppler config is required")
});
type FormData = z.infer<typeof schema>;
+type SourceOption = {
+ id: string;
+ label: string;
+ kind: SourceKind;
+};
+
type Props = {
isOpen: boolean;
onOpenChange: (isOpen: boolean) => void;
configs: TExternalMigrationConfig[];
+ appConnections: TAvailableAppConnection[];
environment: string;
secretPath: string;
- onImport: (dopplerProject: string, dopplerEnvironment: string, configId: string) => Promise<void>;
+ onImport: (
+ dopplerProject: string,
+ dopplerEnvironment: string,
+ selector: { configId?: string; connectionId?: string }
+ ) => Promise<void>;
};
const DopplerConfigGroupHeading = (props: GroupHeadingProps<TDopplerConfig>) => (
@@ -72,10 +87,25 @@ const DopplerConfigOption = (props: OptionProps<TDopplerConfig>) => {
);
};
+const SourceOptionRow = (props: OptionProps<SourceOption>) => {
+ const { data } = props;
+ return (
+ <components.Option {...props}>
+ <div className="flex items-center gap-2">
+ <span>{data.label}</span>
+ <Badge variant={data.kind === "connection" ? "project" : "default"}>
+ {data.kind === "connection" ? "App Connection" : "Org Migration"}
+ </Badge>
+ </div>
+ </components.Option>
+ );
+};
+
export const DopplerSecretImportModal = ({
isOpen,
onOpenChange,
configs,
+ appConnections,
environment,
secretPath,
onImport
@@ -84,41 +114,67 @@ export const DopplerSecretImportModal = ({
control,
handleSubmit,
watch,
+ setValue,
reset,
formState: { errors, isSubmitting }
} = useForm<FormData>({
resolver: zodResolver(schema),
defaultValues: {
- configId: "",
+ sourceId: "",
+ sourceKind: "config",
dopplerProject: "",
dopplerEnvironment: ""
}
});
- const selectedConfigId = watch("configId");
+ const sourceId = watch("sourceId");
+ const sourceKind = watch("sourceKind");
const selectedDopplerProject = watch("dopplerProject");
+ const selectedConfigId = sourceKind === "config" ? sourceId : undefined;
+ const selectedConnectionId = sourceKind === "connection" ? sourceId : undefined;
+
+ // App connections referenced by org migration configs — for labeling org-config options
const hasMultipleConfigs = configs.length > 1;
- const { data: appConnections = [] } = useListAppConnections(undefined, {
+ const { data: orgAppConnections = [] } = useListAppConnections(undefined, {
enabled: hasMultipleConfigs
});
+ const sourceOptions = useMemo<SourceOption[]>(() => {
+ const configOptions: SourceOption[] = configs.map((c) => {
+ const conn = orgAppConnections.find((a) => a.id === c.connectionId);
+ return { id: c.id, label: conn?.name ?? c.id, kind: "config" };
+ });
+ const connectionOptions: SourceOption[] = appConnections.map((conn) => ({
+ id: conn.id,
+ label: conn.name,
+ kind: "connection"
+ }));
+ return [...connectionOptions, ...configOptions];
+ }, [configs, appConnections, orgAppConnections]);
+
+ const showSourceSelector = sourceOptions.length > 1;
+
useEffect(() => {
if (isOpen) {
+ const onlyOption = sourceOptions.length === 1 ? sourceOptions[0] : null;
reset({
- configId: configs.length === 1 ? configs[0].id : "",
+ sourceId: onlyOption?.id ?? "",
+ sourceKind: onlyOption?.kind ?? "config",
dopplerProject: "",
dopplerEnvironment: ""
});
}
- }, [isOpen, reset, configs]);
+ }, [isOpen, reset, sourceOptions]);
const { data: dopplerProjects = [], isPending: isLoadingProjects } = useGetDopplerProjects(
- selectedConfigId || undefined
+ selectedConfigId,
+ selectedConnectionId
);
const { data: dopplerConfigs = [], isPending: isLoadingConfigs } = useGetDopplerConfigs(
- selectedConfigId || undefined,
- selectedDopplerProject || undefined
+ selectedConfigId,
+ selectedDopplerProject || undefined,
+ selectedConnectionId
);
const sortedDopplerConfigs = useMemo(() => {
@@ -135,22 +191,17 @@ export const DopplerSecretImportModal = ({
});
}, [dopplerConfigs]);
- const configOptions = useMemo(
- () =>
- configs.map((c) => {
- const conn = appConnections.find((a) => a.id === c.connectionId);
- return { id: c.id, label: conn?.name ?? c.id };
- }),
- [configs, appConnections]
- );
-
const handleClose = () => {
reset();
onOpenChange(false);
};
const onFormSubmit = async (data: FormData) => {
- await onImport(data.dopplerProject, data.dopplerEnvironment, data.configId);
+ const selector =
+ data.sourceKind === "connection"
+ ? { connectionId: data.sourceId }
+ : { configId: data.sourceId };
+ await onImport(data.dopplerProject, data.dopplerEnvironment, selector);
handleClose();
};
@@ -183,29 +234,37 @@ export const DopplerSecretImportModal = ({
</div>
<form onSubmit={handleSubmit(onFormSubmit)} className="space-y-4">
- {hasMultipleConfigs && (
+ {showSourceSelector && (
<Controller
control={control}
- name="configId"
+ name="sourceId"
render={({ field }) => {
- const selectedItem = configOptions.find((o) => o.id === field.value);
+ const selectedItem = sourceOptions.find((o) => o.id === field.value);
return (
<Field>
- <FieldLabel>Doppler Configuration</FieldLabel>
+ <FieldLabel>Doppler Source</FieldLabel>
<FieldContent>
<FilterableSelect
value={selectedItem || null}
onChange={(newValue) => {
const single = Array.isArray(newValue) ? newValue[0] : newValue;
- field.onChange(single && "id" in single ? single.id : "");
+ if (single && "id" in single) {
+ field.onChange(single.id);
+ setValue("sourceKind", single.kind);
+ setValue("dopplerProject", "");
+ setValue("dopplerEnvironment", "");
+ } else {
+ field.onChange("");
+ }
}}
- options={configOptions}
- placeholder="Select Doppler configuration..."
+ options={sourceOptions}
+ placeholder="Select Doppler source..."
getOptionLabel={(option) => option.label}
- getOptionValue={(option) => option.id}
+ getOptionValue={(option) => `${option.kind}:${option.id}`}
+ components={{ Option: SourceOptionRow }}
/>
</FieldContent>
- <FieldError>{errors.configId?.message}</FieldError>
+ <FieldError>{errors.sourceId?.message}</FieldError>
</Field>
);
}}
@@ -232,8 +291,8 @@ export const DopplerSecretImportModal = ({
field.onChange("");
}
}}
- isLoading={isLoadingProjects && Boolean(selectedConfigId)}
- isDisabled={!selectedConfigId}
+ isLoading={isLoadingProjects && Boolean(sourceId)}
+ isDisabled={!sourceId}
options={dopplerProjects}
placeholder="Select source project..."
getOptionLabel={(option) => option.name}
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
index 2f52bd73c4..7560926bd3 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
@@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { AppConnectionOption } from "@app/components/app-connections";
import { createNotification } from "@app/components/notifications";
import {
Button,
@@ -11,6 +12,7 @@ import {
ModalClose,
ModalContent
} from "@app/components/v2";
+import { TAvailableAppConnection } from "@app/hooks/api/appConnections/types";
import {
useGetVaultMounts,
useGetVaultNamespaces,
@@ -22,45 +24,59 @@ type Props = {
onOpenChange: (isOpen: boolean) => void;
environment: string;
secretPath: string;
- onImport: (vaultPaths: string[], namespace: string) => void;
+ appConnections: TAvailableAppConnection[];
+ onImport: (vaultPaths: string[], namespace: string, connectionId?: string) => void;
};
type ContentProps = {
onClose: () => void;
environment: string;
secretPath: string;
- onImport: (vaultPaths: string[], namespace: string) => void;
+ appConnections: TAvailableAppConnection[];
+ onImport: (vaultPaths: string[], namespace: string, connectionId?: string) => void;
};
-const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) => {
+const Content = ({ onClose, environment, secretPath, appConnections, onImport }: ContentProps) => {
+ const hasAppConnections = appConnections.length > 0;
+ const [selectedConnectionId, setSelectedConnectionId] = useState<string | null>(null);
const [selectedNamespace, setSelectedNamespace] = useState<string | null>(null);
const [selectedMountPath, setSelectedMountPath] = useState<string | null>(null);
const [selectedPaths, setSelectedPaths] = useState<string[]>([]);
const [shouldFetchPaths, setShouldFetchPaths] = useState(false);
const [shouldFetchMounts, setShouldFetchMounts] = useState(false);
- const { data: namespaces, isLoading: isLoadingNamespaces } = useGetVaultNamespaces();
+ const activeConnectionId = hasAppConnections ? (selectedConnectionId ?? undefined) : undefined;
+
+ const { data: namespaces, isLoading: isLoadingNamespaces } =
+ useGetVaultNamespaces(activeConnectionId);
const { data: secretPaths, isLoading: isLoadingPaths } = useGetVaultSecretPaths(
shouldFetchPaths,
selectedNamespace ?? undefined,
- selectedMountPath ?? undefined
+ selectedMountPath ?? undefined,
+ activeConnectionId
);
const { data: mounts, isLoading: isLoadingMounts } = useGetVaultMounts(
shouldFetchMounts,
- selectedNamespace ?? undefined
+ selectedNamespace ?? undefined,
+ activeConnectionId
);
- // Filter to only show KV mounts
const kvMounts = mounts?.filter((mount) => mount.type === "kv" || mount.type.startsWith("kv"));
- // Enable fetching mounts when namespace is selected
+ useEffect(() => {
+ setSelectedNamespace(null);
+ setSelectedMountPath(null);
+ setSelectedPaths([]);
+ setShouldFetchMounts(false);
+ setShouldFetchPaths(false);
+ }, [selectedConnectionId]);
+
useEffect(() => {
if (selectedNamespace) {
setShouldFetchMounts(true);
}
}, [selectedNamespace]);
- // Enable fetching paths when both namespace and mount path are selected
useEffect(() => {
if (selectedNamespace && selectedMountPath) {
setShouldFetchPaths(true);
@@ -83,6 +99,11 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
return;
}
+ if (hasAppConnections && !selectedConnectionId) {
+ createNotification({ type: "error", text: "Please select an app connection" });
+ return;
+ }
+
if (!mounts || mounts.length === 0) {
createNotification({
type: "error",
@@ -91,7 +112,7 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
return;
}
- onImport(selectedPaths, selectedNamespace);
+ onImport(selectedPaths, selectedNamespace, activeConnectionId);
onClose();
};
@@ -115,6 +136,35 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
</div>
</div>
+ {hasAppConnections && (
+ <FormControl
+ label="App Connection"
+ className="mb-4"
+ tooltipText="Select the HashiCorp Vault app connection to use for this import."
+ >
+ <>
+ <FilterableSelect
+ value={appConnections.find((conn) => conn.id === selectedConnectionId) ?? null}
+ onChange={(value) => {
+ if (value && !Array.isArray(value)) {
+ const conn = value as TAvailableAppConnection;
+ setSelectedConnectionId(conn.id);
+ }
+ }}
+ options={appConnections}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ placeholder="Select app connection..."
+ className="w-full"
+ components={{ Option: AppConnectionOption }}
+ />
+ <p className="mt-1 text-xs text-mineshaft-400">
+ Project-scoped HashiCorp Vault app connections available to you
+ </p>
+ </>
+ </FormControl>
+ )}
+
<FormControl
label="Namespace"
className="mb-4"
@@ -134,8 +184,12 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
options={namespaces || []}
getOptionValue={(option) => option.name}
getOptionLabel={(option) => (option.name === "/" ? "root" : option.name)}
- isDisabled={isLoadingNamespaces}
- placeholder="Select namespace..."
+ isDisabled={isLoadingNamespaces || (hasAppConnections && !selectedConnectionId)}
+ placeholder={
+ hasAppConnections && !selectedConnectionId
+ ? "Select an app connection first..."
+ : "Select namespace..."
+ }
className="w-full"
/>
<p className="mt-1 text-xs text-mineshaft-400">
@@ -224,6 +278,7 @@ export const VaultSecretImportModal = ({
onOpenChange,
environment,
secretPath,
+ appConnections,
onImport
}: Props) => {
return (
@@ -238,6 +293,7 @@ export const VaultSecretImportModal = ({
onClose={() => onOpenChange(false)}
environment={environment}
secretPath={secretPath}
+ appConnections={appConnections}
onImport={onImport}
/>
</ModalContent>