Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
cassandra dynamic secret vault migration support
x032205d03f39b4a17b
diff --git a/backend/src/server/routes/v3/external-migration-router.ts b/backend/src/server/routes/v3/external-migration-router.tsindex e8c790d0fe..7fae954ebf 100644--- a/backend/src/server/routes/v3/external-migration-router.ts+++ b/backend/src/server/routes/v3/external-migration-router.ts@@ -468,7 +468,8 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProviderrenew_statements: z.array(z.string()).nullish(),config: z.object({connection_details: z.object({- connection_url: z.string(),+ connection_url: z.string().nullish(),+ hosts: z.string().nullish(),tls_ca: z.string().nullish(),username: z.string().nullish()}),diff --git a/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.ts b/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.tsindex 94c60da202..21fd24653c 100644--- a/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.ts+++ b/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.ts@@ -121,7 +121,8 @@ export type THCVaultKubernetesRole = {export type THCVaultDatabaseConfig = {connection_details: {- connection_url: string;+ connection_url?: string;+ hosts?: string;tls_ca?: string;username?: string;};diff --git a/frontend/src/hooks/api/migration/types.ts b/frontend/src/hooks/api/migration/types.tsindex 235bf2cae6..f9f4336ba2 100644--- a/frontend/src/hooks/api/migration/types.ts+++ b/frontend/src/hooks/api/migration/types.ts@@ -82,7 +82,8 @@ export type VaultDatabaseRole = {renew_statements?: string[];config: {connection_details: {- connection_url: string;+ connection_url?: string;+ hosts?: string;tls_ca?: string;username?: string;};diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CassandraInputForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CassandraInputForm.tsxindex dd0c3e8792..aaf7f6c936 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CassandraInputForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CassandraInputForm.tsx@@ -1,9 +1,11 @@+import { useState } from "react";import { Controller, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import ms from "ms";import { z } from "zod";import { TtlFormLabel } from "@app/components/features";+import { createNotification } from "@app/components/notifications";import {Accordion,AccordionContent,@@ -18,9 +20,13 @@ import {} from "@app/components/v2";import { useCreateDynamicSecret } from "@app/hooks/api";import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types";+import { VaultDatabaseRole } from "@app/hooks/api/migration/types";import { ProjectEnv } from "@app/hooks/api/types";import { slugSchema } from "@app/lib/schemas";+import { LoadFromVaultBanner } from "./components/LoadFromVaultBanner";+import { VaultCassandraImportModal } from "./VaultCassandraImportModal";+const formSchema = z.object({provider: z.object({host: z.string().toLowerCase().min(1),@@ -84,10 +90,13 @@ export const CassandraInputForm = ({projectSlug,isSingleEnvironmentMode}: Props) => {+ const [isVaultImportModalOpen, setIsVaultImportModalOpen] = useState(false);+const {control,formState: { isSubmitting },- handleSubmit+ handleSubmit,+ setValue} = useForm<TForm>({resolver: zodResolver(formSchema),defaultValues: {@@ -99,6 +108,99 @@ export const CassandraInputForm = ({const createDynamicSecret = useCreateDynamicSecret();+ const handleVaultImport = (role: VaultDatabaseRole) => {+ try {+ setValue("name", role.name);++ // Parse hosts field or connection_url+ const hostsField = role.config.connection_details.hosts || "";+ const connectionUrl = role.config.connection_details.connection_url || "";+ const connectionString = hostsField || connectionUrl;++ try {+ const trimmedUrl = connectionString.trim();+ if (trimmedUrl) {+ // Try to extract host and port from various formats+ const parts = trimmedUrl.split(",");+ const hosts: string[] = [];+ let port = 9042; // Default Cassandra port++ parts.forEach((part) => {+ const hostPort = part.trim().split(":");+ hosts.push(hostPort[0]);+ if (hostPort[1]) {+ port = parseInt(hostPort[1], 10);+ }+ });++ if (hosts.length > 0) {+ setValue("provider.host", hosts.join(","));+ }+ if (!Number.isNaN(port)) {+ setValue("provider.port", port);+ }+ }+ } catch {+ // Connection string parsing failed, user will need to fill in manually+ }++ if (role.config.connection_details.username) {+ setValue("provider.username", role.config.connection_details.username);+ }++ if (role.config.connection_details.tls_ca) {+ setValue("provider.ca", role.config.connection_details.tls_ca);+ }++ // Convert {{name}} variable to {{username}}+ const convertVaultVariables = (statement: string) =>+ statement.replace(/\{\{name\}\}/g, "{{username}}");++ // Set statements+ if (role.creation_statements && role.creation_statements.length > 0) {+ setValue(+ "provider.creationStatement",+ role.creation_statements.map(convertVaultVariables).join("\n")+ );+ }++ if (role.revocation_statements && role.revocation_statements.length > 0) {+ setValue(+ "provider.revocationStatement",+ role.revocation_statements.map(convertVaultVariables).join("\n")+ );+ }++ if (role.renew_statements && role.renew_statements.length > 0) {+ setValue(+ "provider.renewStatement",+ role.renew_statements.map(convertVaultVariables).join("\n")+ );+ }++ // Set TTLs+ if (role.default_ttl) {+ const defaultTTL = `${role.default_ttl}s`;+ setValue("defaultTTL", defaultTTL);+ }++ if (role.max_ttl) {+ const maxTTL = `${role.max_ttl}s`;+ setValue("maxTTL", maxTTL);+ }++ createNotification({+ type: "info",+ text: "Configuration loaded successfully from HashiCorp Vault"+ });+ } catch {+ createNotification({+ type: "error",+ text: "Failed to load configuration from HashiCorp Vault"+ });+ }+ };+const handleCreateDynamicSecret = async ({name,maxTTL,@@ -129,6 +231,7 @@ export const CassandraInputForm = ({<div><form onSubmit={handleSubmit(handleCreateDynamicSecret)} autoComplete="off"><div>+ <LoadFromVaultBanner onClick={() => setIsVaultImportModalOpen(true)} /><div className="flex items-center space-x-2"><div className="grow"><Controller@@ -409,6 +512,11 @@ export const CassandraInputForm = ({Cancel</Button></div>+ <VaultCassandraImportModal+ isOpen={isVaultImportModalOpen}+ onOpenChange={setIsVaultImportModalOpen}+ onImport={handleVaultImport}+ /></form></div>);diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/VaultCassandraImportModal.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/VaultCassandraImportModal.tsxnew file mode 100644index 0000000000..ae4ce916ed--- /dev/null+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/VaultCassandraImportModal.tsx@@ -0,0 +1,233 @@+import { useEffect, useState } from "react";+import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";++import { createNotification } from "@app/components/notifications";+import {+ Button,+ FilterableSelect,+ FormControl,+ Modal,+ ModalClose,+ ModalContent+} from "@app/components/v2";+import {+ useGetVaultDatabaseRoles,+ useGetVaultMounts,+ useGetVaultNamespaces+} from "@app/hooks/api/migration/queries";+import { VaultDatabaseRole } from "@app/hooks/api/migration/types";++type Props = {+ isOpen: boolean;+ onOpenChange: (isOpen: boolean) => void;+ onImport: (role: VaultDatabaseRole) => void;+};++type ContentProps = {+ onClose: () => void;+ onImport: (role: VaultDatabaseRole) => void;+};++const Content = ({ onClose, onImport }: ContentProps) => {+ const [selectedNamespace, setSelectedNamespace] = useState<string | null>(null);+ const [selectedMountPath, setSelectedMountPath] = useState<string | null>(null);+ const [selectedRole, setSelectedRole] = useState<VaultDatabaseRole | null>(null);+ const [shouldFetchRoles, setShouldFetchRoles] = useState(false);+ const [shouldFetchMounts, setShouldFetchMounts] = useState(false);++ const { data: namespaces, isLoading: isLoadingNamespaces } = useGetVaultNamespaces();+ const { data: roles, isLoading: isLoadingRoles } = useGetVaultDatabaseRoles(+ shouldFetchRoles,+ selectedNamespace ?? undefined,+ selectedMountPath ?? undefined+ );+ const { data: mounts, isLoading: isLoadingMounts } = useGetVaultMounts(+ shouldFetchMounts,+ selectedNamespace ?? undefined+ );++ // Filter to only show database mounts+ const databaseMounts = mounts?.filter((mount) => mount.type === "database");++ // Filter roles to only show Cassandra roles+ const cassandraRoles = roles?.filter((role) =>+ role.config.plugin_name?.toLowerCase().includes("cassandra")+ );++ // Enable fetching mounts when namespace is selected+ useEffect(() => {+ if (selectedNamespace) {+ setShouldFetchMounts(true);+ }+ }, [selectedNamespace]);++ // Enable fetching roles when both namespace and mount path are selected+ useEffect(() => {+ if (selectedNamespace && selectedMountPath) {+ setShouldFetchRoles(true);+ } else {+ setShouldFetchRoles(false);+ }+ }, [selectedNamespace, selectedMountPath]);++ const handleImport = () => {+ if (!selectedRole) {+ createNotification({+ type: "error",+ text: "Please select a Vault Cassandra role to load"+ });+ return;+ }++ if (!selectedNamespace) {+ createNotification({ type: "error", text: "Please select a namespace" });+ return;+ }++ if (!mounts || mounts.length === 0) {+ createNotification({+ type: "error",+ text: "No Vault mounts found. Please ensure you have database secrets engine configured."+ });+ return;+ }++ onImport(selectedRole);+ onClose();+ };++ return (+ <>+ <div className="mb-4 rounded-md bg-primary/10 p-3 text-sm text-mineshaft-200">+ <div className="flex items-start gap-2">+ <FontAwesomeIcon icon={faInfoCircle} className="mt-0.5 text-primary" />+ <div className="space-y-1.5 text-xs leading-relaxed">+ <p>+ Select a Cassandra database role from Vault to pre-fill the form with its+ configuration including connection details, creation/revocation statements, TTL+ settings, etc.+ </p>+ </div>+ </div>+ </div>++ <FormControl+ label="Namespace"+ className="mb-4"+ tooltipText="Select the Vault namespace containing the database secrets engine."+ >+ <>+ <FilterableSelect+ value={namespaces?.find((ns) => ns.name === selectedNamespace)}+ onChange={(value) => {+ if (value && !Array.isArray(value)) {+ const namespace = value as { id: string; name: string };+ setSelectedNamespace(namespace.name);+ setSelectedMountPath(null);+ setSelectedRole(null);+ }+ }}+ options={namespaces || []}+ getOptionValue={(option) => option.name}+ getOptionLabel={(option) => (option.name === "/" ? "root" : option.name)}+ isDisabled={isLoadingNamespaces}+ placeholder="Select namespace..."+ className="w-full"+ />+ <p className="mt-1 text-xs text-mineshaft-400">+ Select the Vault namespace to fetch available database secrets engines+ </p>+ </>+ </FormControl>++ <FormControl+ label="Database Secrets Engine"+ className="mb-4"+ tooltipText="Select the database secrets engine mount to fetch available Cassandra roles."+ >+ <>+ <FilterableSelect+ value={databaseMounts?.find((mount) => mount.path === selectedMountPath)}+ onChange={(value) => {+ if (value && !Array.isArray(value)) {+ const mount = value as { path: string; type: string; version: string | null };+ setSelectedMountPath(mount.path.replace(/\/$/, "")); // Remove trailing slash+ setSelectedRole(null);+ }+ }}+ options={databaseMounts || []}+ getOptionValue={(option) => option.path}+ getOptionLabel={(option) => option.path.replace(/\/$/, "")}+ isDisabled={isLoadingMounts || !databaseMounts?.length}+ placeholder="Select database secrets engine..."+ className="w-full"+ />+ <p className="mt-1 text-xs text-mineshaft-400">+ Choose a database secrets engine mount to list available Cassandra roles+ </p>+ </>+ </FormControl>++ <FormControl label="Cassandra Role" className="mb-6">+ <>+ <FilterableSelect+ value={selectedRole}+ onChange={(value) => {+ if (value && !Array.isArray(value)) {+ setSelectedRole(value as VaultDatabaseRole);+ } else {+ setSelectedRole(null);+ }+ }}+ options={cassandraRoles || []}+ getOptionValue={(option) => option.name}+ getOptionLabel={(option) => option.name}+ isDisabled={isLoadingRoles || !cassandraRoles?.length || !selectedMountPath}+ placeholder={+ !selectedMountPath+ ? "Select a mount path first..."+ : cassandraRoles?.length === 0+ ? "No Cassandra roles found..."+ : "Select a role to load..."+ }+ isClearable+ className="w-full"+ />+ <p className="mt-1 text-xs text-mineshaft-400">+ Choose a Cassandra role from the selected mount to load its configuration+ </p>+ </>+ </FormControl>++ <div className="mt-8 flex space-x-4">+ <Button+ onClick={handleImport}+ isDisabled={!selectedRole || isLoadingMounts || isLoadingRoles}+ >+ Load Configuration+ </Button>+ <ModalClose asChild>+ <Button colorSchema="secondary" variant="plain">+ Cancel+ </Button>+ </ModalClose>+ </div>+ </>+ );+};++export const VaultCassandraImportModal = ({ isOpen, onOpenChange, onImport }: Props) => {+ return (+ <Modal isOpen={isOpen} onOpenChange={onOpenChange}>+ <ModalContent+ bodyClassName="overflow-visible"+ title="Load from HashiCorp Vault"+ subTitle="Select a Cassandra database role to load its configuration."+ className="max-w-2xl"+ >+ <Content onClose={() => onOpenChange(false)} onImport={onImport} />+ </ModalContent>+ </Modal>+ );+};