Skip to content

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

feat(secrets-17): add clickhouse dynamic secret provider

Tre Dubrava0e391097a000
diff --git a/backend/src/ee/services/dynamic-secret/providers/clickhouse.ts b/backend/src/ee/services/dynamic-secret/providers/clickhouse.ts
new file mode 100644
index 0000000000..aded11a808
--- /dev/null
+++ b/backend/src/ee/services/dynamic-secret/providers/clickhouse.ts
@@ -0,0 +1,399 @@
+import { createClient } from "@clickhouse/client";
+import handlebars from "handlebars";
+import { z } from "zod";
+
+import { TDynamicSecrets } from "@app/db/schemas";
+import { crypto } from "@app/lib/crypto/cryptography";
+import { BadRequestError } from "@app/lib/errors";
+import { sanitizeString } from "@app/lib/fn";
+import { GatewayProxyProtocol, withGatewayProxy } from "@app/lib/gateway";
+import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
+import { validateHandlebarTemplate } from "@app/lib/template/validate-handlebars";
+
+import { ActorIdentityAttributes } from "../../dynamic-secret-lease/dynamic-secret-lease-types";
+import { TGatewayServiceFactory } from "../../gateway/gateway-service";
+import { TGatewayV2ServiceFactory } from "../../gateway-v2/gateway-v2-service";
+import { verifyHostInputValidity } from "../dynamic-secret-fns";
+import { DynamicSecretClickhouseSchema, PasswordRequirements, TDynamicProviderFns } from "./models";
+import { generateUsername } from "./templateUtils";
+
+const EXTERNAL_REQUEST_TIMEOUT = 10 * 1000;
+
+const DEFAULT_PASSWORD_REQUIREMENTS: PasswordRequirements = {
+ length: 48,
+ required: {
+ lowercase: 1,
+ uppercase: 1,
+ digits: 1,
+ symbols: 0
+ },
+ allowedSymbols: "-_.~!*"
+};
+
+const generatePassword = (requirements?: PasswordRequirements) => {
+ const finalReqs = requirements || DEFAULT_PASSWORD_REQUIREMENTS;
+ const { length, required, allowedSymbols } = finalReqs;
+
+ const chars = {
+ lowercase: "abcdefghijklmnopqrstuvwxyz",
+ uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+ digits: "0123456789",
+ symbols: allowedSymbols || "-_.~!*"
+ };
+
+ const parts: string[] = [];
+
+ if (required.lowercase > 0) {
+ parts.push(
+ ...Array(required.lowercase)
+ .fill(0)
+ .map(() => chars.lowercase[crypto.randomInt(chars.lowercase.length)])
+ );
+ }
+
+ if (required.uppercase > 0) {
+ parts.push(
+ ...Array(required.uppercase)
+ .fill(0)
+ .map(() => chars.uppercase[crypto.randomInt(chars.uppercase.length)])
+ );
+ }
+
+ if (required.digits > 0) {
+ parts.push(
+ ...Array(required.digits)
+ .fill(0)
+ .map(() => chars.digits[crypto.randomInt(chars.digits.length)])
+ );
+ }
+
+ if (required.symbols > 0) {
+ parts.push(
+ ...Array(required.symbols)
+ .fill(0)
+ .map(() => chars.symbols[crypto.randomInt(chars.symbols.length)])
+ );
+ }
+
+ const requiredTotal = Object.values(required).reduce<number>((a, b) => a + b, 0);
+ const remainingLength = Math.max(length - requiredTotal, 0);
+
+ const allowedChars = Object.entries(chars)
+ .filter(([key]) => required[key as keyof typeof required] > 0)
+ .map(([, value]) => value)
+ .join("");
+
+ parts.push(
+ ...Array(remainingLength)
+ .fill(0)
+ .map(() => allowedChars[crypto.randomInt(allowedChars.length)])
+ );
+
+ for (let i = parts.length - 1; i > 0; i -= 1) {
+ const j = crypto.randomInt(i + 1);
+ [parts[i], parts[j]] = [parts[j], parts[i]];
+ }
+
+ return parts.join("");
+};
+
+type TClickhouseProviderDTO = {
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">;
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;
+};
+
+export const ClickhouseProvider = ({
+ gatewayService,
+ gatewayV2Service
+}: TClickhouseProviderDTO): TDynamicProviderFns => {
+ const validateProviderInputs = async (inputs: unknown) => {
+ const providerInputs = await DynamicSecretClickhouseSchema.parseAsync(inputs);
+
+ const [hostIp] = await verifyHostInputValidity({
+ host: providerInputs.host,
+ isGateway: Boolean(providerInputs.gatewayId),
+ isDynamicSecret: true
+ });
+
+ validateHandlebarTemplate("ClickHouse creation", providerInputs.creationStatement, {
+ allowedExpressions: (val) => ["username", "password", "expiration", "database"].includes(val)
+ });
+
+ if (providerInputs.renewStatement) {
+ validateHandlebarTemplate("ClickHouse renew", providerInputs.renewStatement, {
+ allowedExpressions: (val) => ["username", "expiration", "database"].includes(val)
+ });
+ }
+
+ validateHandlebarTemplate("ClickHouse revoke", providerInputs.revocationStatement, {
+ allowedExpressions: (val) => ["username", "database"].includes(val)
+ });
+
+ return { ...providerInputs, hostIp };
+ };
+
+ const $getClient = async (providerInputs: z.infer<typeof DynamicSecretClickhouseSchema> & { hostIp: string }) => {
+ const protocol = (providerInputs.sslEnabled ?? Boolean(providerInputs.ca)) ? "https" : "http";
+ const url = `${protocol}://${providerInputs.host}:${providerInputs.port}`;
+
+ const client = createClient({
+ url,
+ username: providerInputs.username,
+ password: providerInputs.password,
+ database: providerInputs.database,
+ request_timeout: EXTERNAL_REQUEST_TIMEOUT,
+ ...(providerInputs.ca && {
+ tls: { ca_cert: Buffer.from(providerInputs.ca) }
+ })
+ });
+
+ return client;
+ };
+
+ const executeStatements = async (statement: string, client: ReturnType<typeof createClient>) => {
+ const queries = statement
+ .split(";")
+ .map((query) => query.trim())
+ .filter(Boolean);
+
+ for (const query of queries) {
+ // eslint-disable-next-line no-await-in-loop -- statements must run sequentially (e.g. CREATE USER before GRANT)
+ await client.command({ query });
+ }
+ };
+
+ const gatewayProxyWrapper = async (
+ providerInputs: z.infer<typeof DynamicSecretClickhouseSchema>,
+ gatewayCallback: (host: string, port: number) => Promise<void>
+ ) => {
+ const gatewayV2ConnectionDetails = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
+ gatewayId: providerInputs.gatewayId as string,
+ targetHost: providerInputs.host,
+ targetPort: providerInputs.port
+ });
+
+ if (gatewayV2ConnectionDetails) {
+ return withGatewayV2Proxy(
+ async (port) => {
+ await gatewayCallback("localhost", port);
+ },
+ {
+ relayHost: gatewayV2ConnectionDetails.relayHost,
+ gateway: gatewayV2ConnectionDetails.gateway,
+ relay: gatewayV2ConnectionDetails.relay,
+ protocol: GatewayProxyProtocol.Tcp
+ }
+ );
+ }
+
+ const relayDetails = await gatewayService.fnGetGatewayClientTlsByGatewayId(providerInputs.gatewayId as string);
+ await withGatewayProxy(
+ async (port) => {
+ await gatewayCallback("localhost", port);
+ },
+ {
+ relayDetails,
+ protocol: GatewayProxyProtocol.Tcp,
+ targetHost: providerInputs.host,
+ targetPort: providerInputs.port
+ }
+ );
+ };
+
+ const validateConnection = async (inputs: unknown) => {
+ const providerInputs = await validateProviderInputs(inputs);
+ let isConnected = false;
+
+ const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => {
+ const client = await $getClient({
+ ...providerInputs,
+ host,
+ port,
+ hostIp: providerInputs.hostIp
+ });
+
+ try {
+ await client.query({ query: "SELECT 1", format: "JSONEachRow" });
+ isConnected = true;
+ } catch (err) {
+ const sanitizedErrorMessage = sanitizeString({
+ unsanitizedString: (err as Error)?.message,
+ tokens: [providerInputs.username]
+ });
+
+ throw new BadRequestError({
+ message: `Failed to connect with provider: ${sanitizedErrorMessage}`
+ });
+ } finally {
+ await client.close();
+ }
+ };
+
+ if (providerInputs.gatewayId) {
+ await gatewayProxyWrapper(providerInputs, gatewayCallback);
+ } else {
+ await gatewayCallback();
+ }
+
+ return isConnected;
+ };
+
+ const create = async (data: {
+ inputs: unknown;
+ expireAt: number;
+ usernameTemplate?: string | null;
+ identity: ActorIdentityAttributes;
+ dynamicSecret: TDynamicSecrets;
+ }) => {
+ const { inputs, expireAt, usernameTemplate, identity, dynamicSecret } = data;
+
+ const providerInputs = await validateProviderInputs(inputs);
+ const { database } = providerInputs;
+
+ const username = await generateUsername(usernameTemplate, {
+ decryptedDynamicSecretInputs: inputs,
+ dynamicSecret,
+ identity
+ });
+
+ const password = generatePassword(providerInputs.passwordRequirements);
+
+ const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => {
+ const client = await $getClient({
+ ...providerInputs,
+ host,
+ port,
+ hostIp: providerInputs.hostIp
+ });
+
+ try {
+ const expiration = new Date(expireAt).toISOString();
+
+ const creationStatement = handlebars.compile(providerInputs.creationStatement, { noEscape: true })({
+ username,
+ password,
+ expiration,
+ database
+ });
+
+ await executeStatements(creationStatement.toString(), client);
+ } catch (err) {
+ const sanitizedErrorMessage = sanitizeString({
+ unsanitizedString: (err as Error)?.message,
+ tokens: [username, password, database]
+ });
+
+ throw new BadRequestError({
+ message: `Failed to create lease from provider: ${sanitizedErrorMessage}`
+ });
+ } finally {
+ await client.close();
+ }
+ };
+
+ if (providerInputs.gatewayId) {
+ await gatewayProxyWrapper(providerInputs, gatewayCallback);
+ } else {
+ await gatewayCallback();
+ }
+
+ return { entityId: username, data: { DB_USERNAME: username, DB_PASSWORD: password } };
+ };
+
+ const revoke = async (inputs: unknown, entityId: string) => {
+ const providerInputs = await validateProviderInputs(inputs);
+ const username = entityId;
+ const { database } = providerInputs;
+
+ const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => {
+ const client = await $getClient({
+ ...providerInputs,
+ host,
+ port,
+ hostIp: providerInputs.hostIp
+ });
+
+ try {
+ const revokeStatement = handlebars.compile(providerInputs.revocationStatement, { noEscape: true })({
+ username,
+ database
+ });
+
+ await executeStatements(revokeStatement.toString(), client);
+ } catch (err) {
+ const sanitizedErrorMessage = sanitizeString({
+ unsanitizedString: (err as Error)?.message,
+ tokens: [username, database]
+ });
+
+ throw new BadRequestError({
+ message: `Failed to revoke lease from provider: ${sanitizedErrorMessage}`
+ });
+ } finally {
+ await client.close();
+ }
+ };
+
+ if (providerInputs.gatewayId) {
+ await gatewayProxyWrapper(providerInputs, gatewayCallback);
+ } else {
+ await gatewayCallback();
+ }
+
+ return { entityId: username };
+ };
+
+ const renew = async (inputs: unknown, entityId: string, expireAt: number) => {
+ const providerInputs = await validateProviderInputs(inputs);
+ if (!providerInputs.renewStatement) return { entityId };
+
+ const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => {
+ const client = await $getClient({
+ ...providerInputs,
+ host,
+ port,
+ hostIp: providerInputs.hostIp
+ });
+
+ const expiration = new Date(expireAt).toISOString();
+ const { database } = providerInputs;
+
+ try {
+ const renewStatement = handlebars.compile(providerInputs.renewStatement as string, { noEscape: true })({
+ username: entityId,
+ expiration,
+ database
+ });
+
+ await executeStatements(renewStatement.toString(), client);
+ } catch (err) {
+ const sanitizedErrorMessage = sanitizeString({
+ unsanitizedString: (err as Error)?.message,
+ tokens: [database]
+ });
+
+ throw new BadRequestError({
+ message: `Failed to renew lease from provider: ${sanitizedErrorMessage}`
+ });
+ } finally {
+ await client.close();
+ }
+ };
+
+ if (providerInputs.gatewayId) {
+ await gatewayProxyWrapper(providerInputs, gatewayCallback);
+ } else {
+ await gatewayCallback();
+ }
+
+ return { entityId };
+ };
+
+ return {
+ validateProviderInputs,
+ validateConnection,
+ create,
+ revoke,
+ renew
+ };
+};
diff --git a/backend/src/ee/services/dynamic-secret/providers/index.ts b/backend/src/ee/services/dynamic-secret/providers/index.ts
index 0259f2d2d9..b2c329a6f2 100644
--- a/backend/src/ee/services/dynamic-secret/providers/index.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/index.ts
@@ -7,6 +7,7 @@ import { AwsIamProvider } from "./aws-iam";
import { AzureEntraIDProvider } from "./azure-entra-id";
import { AzureSqlDatabaseProvider } from "./azure-sql-database";
import { CassandraProvider } from "./cassandra";
+import { ClickhouseProvider } from "./clickhouse";
import { CouchbaseProvider } from "./couchbase";
import { ElasticSearchProvider } from "./elastic-search";
import { GcpIamProvider } from "./gcp-iam";
@@ -34,6 +35,7 @@ export const buildDynamicSecretProviders = ({
gatewayV2Service
}: TBuildDynamicSecretProviderDTO): Record<DynamicSecretProviders, TDynamicProviderFns> => ({
[DynamicSecretProviders.SqlDatabase]: SqlDatabaseProvider({ gatewayService, gatewayV2Service }),
+ [DynamicSecretProviders.Clickhouse]: ClickhouseProvider({ gatewayService, gatewayV2Service }),
[DynamicSecretProviders.Cassandra]: CassandraProvider(),
[DynamicSecretProviders.AwsIam]: AwsIamProvider(),
[DynamicSecretProviders.Redis]: RedisDatabaseProvider(),
diff --git a/backend/src/ee/services/dynamic-secret/providers/models.ts b/backend/src/ee/services/dynamic-secret/providers/models.ts
index 8370e31de2..8c108e76ce 100644
--- a/backend/src/ee/services/dynamic-secret/providers/models.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/models.ts
@@ -178,6 +178,42 @@ export const DynamicSecretSqlDBSchema = z.object({
gatewayId: z.string().nullable().optional()
});
+export const DynamicSecretClickhouseSchema = z.object({
+ host: z.string().trim().toLowerCase(),
+ port: z.number(),
+ database: z.string().trim(),
+ username: z.string().trim(),
+ password: z.string().trim(),
+ passwordRequirements: z
+ .object({
+ length: z.number().min(1).max(250),
+ required: z
+ .object({
+ lowercase: z.number().min(0),
+ uppercase: z.number().min(0),
+ digits: z.number().min(0),
+ symbols: z.number().min(0)
+ })
+ .refine((data) => {
+ const total = Object.values(data).reduce((sum, count) => sum + count, 0);
+ return total <= 250;
+ }, "Sum of required characters cannot exceed 250"),
+ allowedSymbols: z.string().optional()
+ })
+ .refine((data) => {
+ const total = Object.values(data.required).reduce((sum, count) => sum + count, 0);
+ return total <= data.length;
+ }, "Sum of required characters cannot exceed the total length")
+ .optional()
+ .describe("Password generation requirements"),
+ creationStatement: z.string().trim(),
+ revocationStatement: z.string().trim(),
+ renewStatement: z.string().trim().optional(),
+ ca: z.string().optional(),
+ sslEnabled: z.boolean().optional(),
+ gatewayId: z.string().nullable().optional()
+});
+
export const DynamicSecretCassandraSchema = z.object({
host: z.string().trim().toLowerCase(),
port: z.number(),
@@ -643,6 +679,7 @@ export const DynamicSecretCouchbaseSchema = z.object({
export enum DynamicSecretProviders {
SqlDatabase = "sql-database",
+ Clickhouse = "clickhouse",
Cassandra = "cassandra",
AwsIam = "aws-iam",
Redis = "redis",
@@ -667,6 +704,7 @@ export enum DynamicSecretProviders {
export const DynamicSecretProviderSchema = z.discriminatedUnion("type", [
z.object({ type: z.literal(DynamicSecretProviders.SqlDatabase), inputs: DynamicSecretSqlDBSchema }),
+ z.object({ type: z.literal(DynamicSecretProviders.Clickhouse), inputs: DynamicSecretClickhouseSchema }),
z.object({ type: z.literal(DynamicSecretProviders.Cassandra), inputs: DynamicSecretCassandraSchema }),
z.object({ type: z.literal(DynamicSecretProviders.SapAse), inputs: DynamicSecretSapAseSchema }),
z.object({ type: z.literal(DynamicSecretProviders.AwsIam), inputs: DynamicSecretAwsIamSchema }),
diff --git a/frontend/src/hooks/api/dynamicSecret/types.ts b/frontend/src/hooks/api/dynamicSecret/types.ts
index 8584d6947e..94dedaf6ca 100644
--- a/frontend/src/hooks/api/dynamicSecret/types.ts
+++ b/frontend/src/hooks/api/dynamicSecret/types.ts
@@ -39,7 +39,8 @@ export enum DynamicSecretProviders {
Vertica = "vertica",
GcpIam = "gcp-iam",
Github = "github",
- Couchbase = "couchbase"
+ Couchbase = "couchbase",
+ Clickhouse = "clickhouse"
}
export enum KubernetesDynamicSecretCredentialType {
@@ -423,6 +424,32 @@ export type TDynamicSecretProvider =
apiKey: string;
};
};
+ }
+ | {
+ type: DynamicSecretProviders.Clickhouse;
+ inputs: {
+ host: string;
+ port: number;
+ database: string;
+ username: string;
+ password: string;
+ creationStatement: string;
+ revocationStatement: string;
+ renewStatement?: string;
+ ca?: string;
+ sslEnabled?: boolean;
+ gatewayId?: string;
+ passwordRequirements?: {
+ length: number;
+ required: {
+ lowercase: number;
+ uppercase: number;
+ digits: number;
+ symbols: number;
+ };
+ allowedSymbols?: string;
+ };
+ };
};
export type TCreateDynamicSecretDTO = {
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/DynamicSecretTableRow/DynamicSecretTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/DynamicSecretTableRow/DynamicSecretTableRow.tsx
index ae37c26707..9efd3ec89f 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/DynamicSecretTableRow/DynamicSecretTableRow.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/DynamicSecretTableRow/DynamicSecretTableRow.tsx
@@ -55,6 +55,7 @@ const DYNAMIC_SECRET_PROVIDER_NAMES: Record<DynamicSecretProviders, string> = {
[DynamicSecretProviders.Vertica]: "Vertica",
[DynamicSecretProviders.GcpIam]: "GCP IAM",
[DynamicSecretProviders.Github]: "GitHub",
+ [DynamicSecretProviders.Clickhouse]: "ClickHouse",
[DynamicSecretProviders.Couchbase]: "Couchbase"
};
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/ClickHouseInputForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/ClickHouseInputForm.tsx
new file mode 100644
index 0000000000..e9e7508073
--- /dev/null
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/ClickHouseInputForm.tsx
@@ -0,0 +1,668 @@
+import { Controller, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useQuery } from "@tanstack/react-query";
+import ms from "ms";
+import { z } from "zod";
+
+import { TtlFormLabel } from "@app/components/features";
+import { OrgPermissionCan } from "@app/components/permissions";
+import {
+ Accordion,
+ AccordionContent,
+ AccordionItem,
+ AccordionTrigger,
+ Button,
+ FilterableSelect,
+ FormControl,
+ Input,
+ SecretInput,
+ Select,
+ SelectItem,
+ TextArea,
+ Tooltip
+} from "@app/components/v2";
+import {
+ OrgGatewayPermissionActions,
+ OrgPermissionSubjects
+} from "@app/context/OrgPermissionContext/types";
+import { gatewaysQueryKeys, useCreateDynamicSecret } from "@app/hooks/api";
+import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types";
+import { ProjectEnv } from "@app/hooks/api/types";
+import { slugSchema } from "@app/lib/schemas";
+
+import { MetadataForm } from "../../DynamicSecretListView/MetadataForm";
+
+const passwordRequirementsSchema = z
+ .object({
+ length: z.number().min(1).max(250),
+ required: z
+ .object({
+ lowercase: z.number().min(0),
+ uppercase: z.number().min(0),
+ digits: z.number().min(0),
+ symbols: z.number().min(0)
+ })
+ .refine((data) => {
+ const total = Object.values(data).reduce((sum, count) => sum + count, 0);
+ return total <= 250;
+ }, "Sum of required characters cannot exceed 250"),
+ allowedSymbols: z.string().optional()
+ })
+ .refine((data) => {
+ const total = Object.values(data.required).reduce((sum, count) => sum + count, 0);
+ return total <= data.length;
+ }, "Sum of required characters cannot exceed the total length");
+
+const formSchema = z.object({
+ provider: z.object({
+ host: z.string().toLowerCase().min(1),
+ port: z.coerce.number(),
+ database: z.string().min(1),
+ username: z.string().min(1),
+ password: z.string().min(1),
+ passwordRequirements: passwordRequirementsSchema.optional(),
+ creationStatement: z.string().min(1),
+ revocationStatement: z.string().min(1),
+ renewStatement: z.string().optional(),
+ sslEnabled: z.boolean().optional(),
+ ca: z.string().optional(),
+ gatewayId: z.string().optional()
+ }),
+ defaultTTL: z.string().superRefine((val, ctx) => {
+ const valMs = ms(val);
+ if (valMs < 60 * 1000)
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1min" });
+ if (valMs > ms("10y"))
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than 10 years" });
+ }),
+ maxTTL: z
+ .string()
+ .optional()
+ .superRefine((val, ctx) => {
+ if (!val) return;
+ const valMs = ms(val);
+ if (valMs < 60 * 1000)
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1min" });
+ if (valMs > ms("10y"))
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than 10 years" });
+ }),
+ name: slugSchema(),
+ environment: z.object({ name: z.string(), slug: z.string() }),
+ metadata: z
+ .object({
+ key: z.string().trim().min(1),
+ value: z.string().trim().default("")
+ })
+ .array()
+ .optional(),
+ usernameTemplate: z.string().nullable().optional()
+});
+
+type TForm = z.infer<typeof formSchema>;
+
+type Props = {
+ onCompleted: () => void;
+ onCancel: () => void;
+ secretPath: string;
+ projectSlug: string;
+ environments: ProjectEnv[];
+ isSingleEnvironmentMode?: boolean;
+};
+
+export const ClickHouseInputForm = ({
+ onCompleted,
+ onCancel,
+ environments,
+ secretPath,
+ projectSlug,
+ isSingleEnvironmentMode
+}: Props) => {
+ const {
+ control,
+ formState: { isSubmitting },
+ handleSubmit,
+ watch
+ } = useForm<TForm>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ provider: {
+ host: "",
+ port: 8123,
+ database: "default",
+ username: "",
+ password: "",
+ creationStatement:
+ "CREATE USER '{{username}}' IDENTIFIED WITH sha256_password BY '{{password}}';\nGRANT SELECT ON {{database}}.* TO '{{username}}';",
+ revocationStatement: "DROP USER IF EXISTS '{{username}}';",
+ renewStatement: "",
+ passwordRequirements: {
+ length: 48,
+ required: {
+ lowercase: 1,
+ uppercase: 1,
+ digits: 1,
+ symbols: 0
+ },
+ allowedSymbols: "-_.~!*"
+ }
+ },
+ environment: isSingleEnvironmentMode ? environments[0] : undefined,
+ usernameTemplate: "{{randomUsername}}"
+ }
+ });
+
+ const createDynamicSecret = useCreateDynamicSecret();
+ const { data: gateways, isPending: isGatewaysLoading } = useQuery(gatewaysQueryKeys.list());
+
+ const handleCreateDynamicSecret = async ({
+ name,
+ maxTTL,
+ provider,
+ defaultTTL,
+ environment,
+ metadata,
+ usernameTemplate
+ }: TForm) => {
+ if (createDynamicSecret.isPending) return;
+
+ const isDefaultUsernameTemplate = usernameTemplate === "{{randomUsername}}";
+ await createDynamicSecret.mutateAsync({
+ provider: { type: DynamicSecretProviders.Clickhouse, inputs: provider },
+ maxTTL,
+ name,
+ path: secretPath,
+ defaultTTL,
+ projectSlug,
+ environmentSlug: environment.slug,
+ metadata,
+ usernameTemplate:
+ !usernameTemplate || isDefaultUsernameTemplate ? undefined : usernameTemplate
+ });
+ onCompleted();
+ };
+
+ return (
+ <div>
+ <form onSubmit={handleSubmit(handleCreateDynamicSecret)} autoComplete="off">
+ <div>
+ <div className="flex items-center space-x-2">
+ <div className="grow">
+ <Controller
+ control={control}
+ defaultValue=""
+ name="name"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Secret Name"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ >
+ <Input {...field} placeholder="dynamic-secret" />
+ </FormControl>
+ )}
+ />
+ </div>
+
+ <div className="w-32">
+ <Controller
+ control={control}
+ name="defaultTTL"
+ defaultValue="1h"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label={<TtlFormLabel label="Default TTL" />}
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} />
+ </FormControl>
+ )}
+ />
+ </div>
+ <div className="w-32">
+ <Controller
+ control={control}
+ name="maxTTL"
+ defaultValue="24h"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label={<TtlFormLabel label="Max TTL" />}
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} />
+ </FormControl>
+ )}
+ />
+ </div>
+ </div>
+ <MetadataForm control={control} />
+ <div>
+ <div className="mt-4 mb-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">
+ Configuration
+ </div>
+ <div>
+ <OrgPermissionCan
+ I={OrgGatewayPermissionActions.AttachGateways}
+ a={OrgPermissionSubjects.Gateway}
+ >
+ {(isAllowed) => (
+ <Controller
+ control={control}
+ name="provider.gatewayId"
+ defaultValue=""
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ label="Gateway"
+ >
+ <Tooltip
+ isDisabled={isAllowed}
+ content="Restricted access. You don't have permission to attach gateways to resources."
+ >
+ <div>
+ <Select
+ isDisabled={!isAllowed}
+ value={value}
+ onValueChange={onChange}
+ className="w-full border border-mineshaft-500"
+ dropdownContainerClassName="max-w-none"
+ isLoading={isGatewaysLoading}
+ placeholder="Default: Internet Gateway"
+ position="popper"
+ >
+ <SelectItem
+ value={null as unknown as string}
+ onClick={() => onChange(undefined)}
+ >
+ Internet Gateway
+ </SelectItem>
+ {gateways?.map((el) => (
+ <SelectItem value={el.id} key={el.id}>
+ {el.name}
+ </SelectItem>
+ ))}
+ </Select>
+ </div>
+ </Tooltip>
+ </FormControl>
+ )}
+ />
+ )}
+ </OrgPermissionCan>
+ </div>
+ <div className="flex flex-col">
+ <div className="flex items-center space-x-2">
+ <Controller
+ control={control}
+ name="provider.host"
+ defaultValue=""
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Host"
+ className="grow"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="provider.port"
+ defaultValue={8123}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Port"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} type="number" />
+ </FormControl>
+ )}
+ />
+ </div>
+ <div className="flex items-center space-x-2">
+ <Controller
+ control={control}
+ name="provider.username"
+ defaultValue=""
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="User"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} autoComplete="off" />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="provider.password"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Password"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} type="password" autoComplete="new-password" />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="provider.database"
+ defaultValue="default"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Database Name"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} />
+ </FormControl>
+ )}
+ />
+ </div>
+ <div>
+ <Controller
+ control={control}
+ name="provider.ca"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ isOptional
+ label="CA (SSL)"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <SecretInput
+ {...field}
+ containerClassName="text-bunker-300 hover:border-primary-400/50 border border-mineshaft-600 bg-mineshaft-900 px-2 py-1.5"
+ />
+ </FormControl>
+ )}
+ />
+ <Accordion type="multiple" className="mb-2 w-full bg-mineshaft-700">
+ <AccordionItem value="advanced">
+ <AccordionTrigger>
+ Creation, Revocation & Renew Statements (optional)
+ </AccordionTrigger>
+ <AccordionContent>
+ <Controller
+ control={control}
+ name="usernameTemplate"
+ defaultValue=""
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Username Template"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input
+ {...field}
+ value={field.value || undefined}
+ className="border-mineshaft-600 bg-mineshaft-900 text-sm"
+ placeholder="{{randomUsername}}"
+ />
+ </FormControl>
+ )}
+ />
+ <div className="mb-4 text-sm text-mineshaft-300">
+ Customize ClickHouse statements for managing database user lifecycle
+ </div>
+ <Controller
+ control={control}
+ name="provider.creationStatement"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Creation Statement"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ helperText="username, password and expiration are dynamically provisioned"
+ >
+ <TextArea
+ {...field}
+ reSize="none"
+ rows={3}
+ className="border-mineshaft-600 bg-mineshaft-900 text-sm"
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="provider.revocationStatement"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Revocation Statement"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ helperText="username is dynamically provisioned"
+ >
+ <TextArea
+ {...field}
+ reSize="none"
+ rows={3}
+ className="border-mineshaft-600 bg-mineshaft-900 text-sm"
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="provider.renewStatement"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Renew Statement"
+ helperText="username and expiration are dynamically provisioned"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <TextArea
+ {...field}
+ reSize="none"
+ rows={3}
+ className="border-mineshaft-600 bg-mineshaft-900 text-sm"
+ />
+ </FormControl>
+ )}
+ />
+ </AccordionContent>
+ </AccordionItem>
+ </Accordion>
+ <Accordion type="multiple" className="mt-4 mb-2 w-full bg-mineshaft-700">
+ <AccordionItem value="password-config">
+ <AccordionTrigger>Password Configuration (optional)</AccordionTrigger>
+ <AccordionContent>
+ <div className="mb-4 text-sm text-mineshaft-300">
+ Set constraints on the generated database password
+ </div>
+ <div className="space-y-4">
+ <div>
+ <Controller
+ control={control}
+ name="provider.passwordRequirements.length"
+ defaultValue={48}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Password Length"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ >
+ <Input
+ type="number"
+ min={1}
+ max={250}
+ {...field}
+ onChange={(e) => field.onChange(Number(e.target.value))}
+ />
+ </FormControl>
+ )}
+ />
+ </div>
+
+ <div className="space-y-2">
+ <h4 className="text-sm font-medium">Minimum Required Character Counts</h4>
+ <div className="text-sm text-gray-500">
+ {(() => {
+ const total = Object.values(
+ watch("provider.passwordRequirements.required") || {}
+ ).reduce((sum, count) => sum + Number(count || 0), 0);
+ const length = watch("provider.passwordRequirements.length") || 0;
+ const isError = total > length;
+ return (
+ <span className={isError ? "text-red-500" : ""}>
+ Total required characters: {total}{" "}
+ {isError ? `(exceeds length of ${length})` : ""}
+ </span>
+ );
+ })()}
+ </div>
+ <div className="grid grid-cols-2 gap-4">
+ <Controller
+ control={control}
+ name="provider.passwordRequirements.required.lowercase"
+ defaultValue={1}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Lowercase Count"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText="Minimum number of lowercase letters"
+ >
+ <Input
+ type="number"
+ min={0}
+ {...field}
+ onChange={(e) => field.onChange(Number(e.target.value))}
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="provider.passwordRequirements.required.uppercase"
+ defaultValue={1}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Uppercase Count"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText="Minimum number of uppercase letters"
+ >
+ <Input
+ type="number"
+ min={0}
+ {...field}
+ onChange={(e) => field.onChange(Number(e.target.value))}
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="provider.passwordRequirements.required.digits"
+ defaultValue={1}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Digit Count"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText="Minimum number of digits"
+ >
+ <Input
+ type="number"
+ min={0}
+ {...field}
+ onChange={(e) => field.onChange(Number(e.target.value))}
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="provider.passwordRequirements.required.symbols"
+ defaultValue={0}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Symbol Count"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText="Minimum number of symbols"
+ >
+ <Input
+ type="number"
+ min={0}
+ {...field}
+ onChange={(e) => field.onChange(Number(e.target.value))}
+ />
+ </FormControl>
+ )}
+ />
+ </div>
+ </div>
+
+ <div className="space-y-2">
+ <h4 className="text-sm font-medium">Allowed Symbols</h4>
+ <Controller
+ control={control}
+ name="provider.passwordRequirements.allowedSymbols"
+ defaultValue="-_.~!*"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Symbols to use in password"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText="Default: -_.~!*"
+ >
+ <Input {...field} placeholder="-_.~!*" />
+ </FormControl>
+ )}
+ />
+ </div>
+ </div>
+ </AccordionContent>
+ </AccordionItem>
+ </Accordion>
+ {!isSingleEnvironmentMode && (
+ <Controller
+ control={control}
+ name="environment"
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ label="Environment"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ >
+ <FilterableSelect
+ options={environments}
+ value={value}
+ onChange={onChange}
+ placeholder="Select the environment to create secret in..."
+ getOptionLabel={(option) => option.name}
+ getOptionValue={(option) => option.slug}
+ menuPlacement="top"
+ />
+ </FormControl>
+ )}
+ />
+ )}
+ </div>
+ </div>
+ </div>
+ </div>
+ <div className="mt-4 flex items-center space-x-4">
+ <Button type="submit" isLoading={isSubmitting}>
+ Submit
+ </Button>
+ <Button variant="outline_bg" onClick={onCancel}>
+ Cancel
+ </Button>
+ </div>
+ </form>
+ </div>
+ );
+};
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsx
index 895b474751..23b0688062 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsx
@@ -2,6 +2,7 @@ import { useState } from "react";
import { DiRedis } from "react-icons/di";
import {
SiApachecassandra,
+ SiClickhouse,
SiCouchbase,
SiElasticsearch,
SiFiles,
@@ -27,6 +28,7 @@ import { AwsIamInputForm } from "./AwsIamInputForm";
import { AzureEntraIdInputForm } from "./AzureEntraIdInputForm";
import { AzureSqlDatabaseInputForm } from "./AzureSqlDatabaseInputForm";
import { CassandraInputForm } from "./CassandraInputForm";
+import { ClickHouseInputForm } from "./ClickHouseInputForm";
import { CouchbaseInputForm } from "./CouchbaseInputForm";
import { ElasticSearchInputForm } from "./ElasticSearchInputForm";
import { GcpIamInputForm } from "./GcpIamInputForm";
@@ -163,6 +165,11 @@ const DYNAMIC_SECRET_LIST = [
icon: <SiCouchbase size="1.5rem" />,
provider: DynamicSecretProviders.Couchbase,
title: "Couchbase"
+ },
+ {
+ icon: <SiClickhouse size="1.5rem" />,
+ provider: DynamicSecretProviders.Clickhouse,
+ title: "ClickHouse"
}
];
@@ -643,6 +650,25 @@ export const CreateDynamicSecretForm = ({
/>
</motion.div>
)}
+ {wizardStep === WizardSteps.ProviderInputs &&
+ selectedProvider === DynamicSecretProviders.Clickhouse && (
+ <motion.div
+ key="dynamic-clickhouse-step"
+ transition={{ duration: 0.1 }}
+ initial={{ opacity: 0, translateX: 30 }}
+ animate={{ opacity: 1, translateX: 0 }}
+ exit={{ opacity: 0, translateX: -30 }}
+ >
+ <ClickHouseInputForm
+ onCompleted={handleFormReset}
+ onCancel={handleFormReset}
+ projectSlug={projectSlug}
+ secretPath={secretPath}
+ environments={environments}
+ isSingleEnvironmentMode={isSingleEnvironmentMode}
+ />
+ </motion.div>
+ )}
</AnimatePresence>
</ModalContent>
</Modal>
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretClickHouseForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretClickHouseForm.tsx
new file mode 100644
index 0000000000..60c5082601
--- /dev/null
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretClickHouseForm.tsx
@@ -0,0 +1,649 @@
+import { Controller, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useQuery } from "@tanstack/react-query";
+import ms from "ms";
+import { z } from "zod";
+
+import { TtlFormLabel } from "@app/components/features";
+import { createNotification } from "@app/components/notifications";
+import { OrgPermissionCan } from "@app/components/permissions";
+import {
+ Accordion,
+ AccordionContent,
+ AccordionItem,
+ AccordionTrigger,
+ Button,
+ FormControl,
+ Input,
+ SecretInput,
+ Select,
+ SelectItem,
+ TextArea,
+ Tooltip
+} from "@app/components/v2";
+import { OrgPermissionSubjects } from "@app/context";
+import { OrgGatewayPermissionActions } from "@app/context/OrgPermissionContext/types";
+import { gatewaysQueryKeys, useUpdateDynamicSecret } from "@app/hooks/api";
+import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";
+import { slugSchema } from "@app/lib/schemas";
+
+import { MetadataForm } from "../MetadataForm";
+
+const passwordRequirementsSchema = z
+ .object({
+ length: z.number().min(1).max(250),
+ required: z
+ .object({
+ lowercase: z.number().min(0),
+ uppercase: z.number().min(0),
+ digits: z.number().min(0),
+ symbols: z.number().min(0)
+ })
+ .refine((data) => {
+ const total = Object.values(data).reduce((sum, count) => sum + count, 0);
+ return total <= 250;
+ }, "Sum of required characters cannot exceed 250"),
+ allowedSymbols: z.string().optional()
+ })
+ .refine((data) => {
+ const total = Object.values(data.required).reduce((sum, count) => sum + count, 0);
+ return total <= data.length;
+ }, "Sum of required characters cannot exceed the total length");
+
+const formSchema = z.object({
+ inputs: z
+ .object({
+ host: z.string().toLowerCase().min(1),
+ port: z.number(),
+ database: z.string().min(1),
+ username: z.string().min(1),
+ password: z.string().min(1),
+ passwordRequirements: passwordRequirementsSchema.optional(),
+ creationStatement: z.string().min(1),
+ revocationStatement: z.string().min(1),
+ renewStatement: z.string().optional(),
+ ca: z.string().optional(),
+ gatewayId: z.string().optional().nullable()
+ })
+ .partial(),
+ defaultTTL: z.string().superRefine((val, ctx) => {
+ const valMs = ms(val);
+ if (valMs < 60 * 1000)
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1min" });
+ if (valMs > ms("10y"))
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than 10 years" });
+ }),
+ maxTTL: z
+ .string()
+ .optional()
+ .superRefine((val, ctx) => {
+ if (!val) return;
+ const valMs = ms(val);
+ if (valMs < 60 * 1000)
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1min" });
+ if (valMs > ms("10y"))
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than 10 years" });
+ })
+ .nullable(),
+ newName: slugSchema().optional(),
+ metadata: z
+ .object({
+ key: z.string().trim().min(1),
+ value: z.string().trim().default("")
+ })
+ .array()
+ .optional(),
+ usernameTemplate: z.string().trim().nullable().optional()
+});
+
+type TForm = z.infer<typeof formSchema>;
+
+type Props = {
+ onClose: () => void;
+ dynamicSecret: TDynamicSecret & { inputs: unknown };
+ secretPath: string;
+ environment: string;
+ projectSlug: string;
+};
+
+const DEFAULT_PASSWORD_REQUIREMENTS = {
+ length: 48,
+ required: {
+ lowercase: 1,
+ uppercase: 1,
+ digits: 1,
+ symbols: 0
+ },
+ allowedSymbols: "-_.~!*"
+};
+
+export const EditDynamicSecretClickHouseForm = ({
+ onClose,
+ dynamicSecret,
+ environment,
+ secretPath,
+ projectSlug
+}: Props) => {
+ const {
+ control,
+ watch,
+ formState: { isSubmitting },
+ handleSubmit
+ } = useForm<TForm>({
+ resolver: zodResolver(formSchema),
+ values: {
+ defaultTTL: dynamicSecret.defaultTTL,
+ maxTTL: dynamicSecret.maxTTL,
+ newName: dynamicSecret.name,
+ metadata: dynamicSecret.metadata,
+ usernameTemplate: dynamicSecret?.usernameTemplate || "{{randomUsername}}",
+ inputs: {
+ ...(dynamicSecret.inputs as TForm["inputs"]),
+ passwordRequirements:
+ (dynamicSecret.inputs as TForm["inputs"])?.passwordRequirements ||
+ DEFAULT_PASSWORD_REQUIREMENTS
+ }
+ }
+ });
+
+ const { data: gateways, isPending: isGatewaysLoading } = useQuery(gatewaysQueryKeys.list());
+ const updateDynamicSecret = useUpdateDynamicSecret();
+ const selectedGatewayId = watch("inputs.gatewayId");
+ const isGatewayInActive = gateways?.findIndex((el) => el.id === selectedGatewayId) === -1;
+
+ const handleUpdateDynamicSecret = async ({
+ inputs,
+ maxTTL,
+ defaultTTL,
+ newName,
+ metadata,
+ usernameTemplate
+ }: TForm) => {
+ if (updateDynamicSecret.isPending) return;
+ const isDefaultUsernameTemplate = usernameTemplate === "{{randomUsername}}";
+ await updateDynamicSecret.mutateAsync({
+ name: dynamicSecret.name,
+ path: secretPath,
+ projectSlug,
+ environmentSlug: environment,
+ data: {
+ maxTTL: maxTTL || undefined,
+ defaultTTL,
+ inputs: {
+ ...inputs,
+ gatewayId: isGatewayInActive ? null : inputs.gatewayId
+ },
+ newName: newName === dynamicSecret.name ? undefined : newName,
+ metadata,
+ usernameTemplate: !usernameTemplate || isDefaultUsernameTemplate ? null : usernameTemplate
+ }
+ });
+ onClose();
+ createNotification({
+ type: "success",
+ text: "Successfully updated dynamic secret"
+ });
+ };
+
+ return (
+ <div>
+ <form onSubmit={handleSubmit(handleUpdateDynamicSecret)} autoComplete="off">
+ <div className="flex items-center space-x-2">
+ <div className="grow">
+ <Controller
+ control={control}
+ name="newName"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Secret Name"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ >
+ <Input {...field} placeholder="DYN-1" />
+ </FormControl>
+ )}
+ />
+ </div>
+ <div className="w-32">
+ <Controller
+ control={control}
+ name="defaultTTL"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label={<TtlFormLabel label="Default TTL" />}
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} />
+ </FormControl>
+ )}
+ />
+ </div>
+ <div className="w-32">
+ <Controller
+ control={control}
+ name="maxTTL"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label={<TtlFormLabel label="Max TTL" />}
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} value={field.value || ""} />
+ </FormControl>
+ )}
+ />
+ </div>
+ </div>
+ <MetadataForm control={control} />
+ <div>
+ <div className="mb-4 border-b border-b-mineshaft-600 pb-2">Configuration</div>
+ <div>
+ <OrgPermissionCan
+ I={OrgGatewayPermissionActions.AttachGateways}
+ a={OrgPermissionSubjects.Gateway}
+ >
+ {(isAllowed) => (
+ <Controller
+ control={control}
+ name="inputs.gatewayId"
+ defaultValue=""
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error?.message) || isGatewayInActive}
+ errorText={
+ isGatewayInActive && selectedGatewayId
+ ? `Project Gateway ${selectedGatewayId} is removed`
+ : error?.message
+ }
+ label="Gateway"
+ helperText=""
+ >
+ <Tooltip
+ isDisabled={isAllowed}
+ content="Restricted access. You don't have permission to attach gateways to resources."
+ >
+ <div>
+ <Select
+ isDisabled={!isAllowed}
+ value={value || undefined}
+ onValueChange={onChange}
+ className="w-full border border-mineshaft-500"
+ dropdownContainerClassName="max-w-none"
+ isLoading={isGatewaysLoading}
+ placeholder="Default: Internet Gateway"
+ position="popper"
+ >
+ <SelectItem
+ value={null as unknown as string}
+ onClick={() => onChange(undefined)}
+ >
+ Internet Gateway
+ </SelectItem>
+ {gateways?.map((el) => (
+ <SelectItem value={el.id} key={el.id}>
+ {el.name}
+ </SelectItem>
+ ))}
+ </Select>
+ </div>
+ </Tooltip>
+ </FormControl>
+ )}
+ />
+ )}
+ </OrgPermissionCan>
+ </div>
+ <div className="flex flex-col">
+ <div className="flex items-center space-x-2">
+ <Controller
+ control={control}
+ name="inputs.host"
+ defaultValue=""
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Host"
+ className="grow"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="inputs.port"
+ defaultValue={8123}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Port"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input
+ {...field}
+ type="number"
+ onChange={(el) => field.onChange(parseInt(el.target.value, 10))}
+ />
+ </FormControl>
+ )}
+ />
+ </div>
+ <div className="flex items-center space-x-2">
+ <Controller
+ control={control}
+ name="inputs.username"
+ defaultValue=""
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="User"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} autoComplete="off" />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="inputs.password"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Password"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} type="password" autoComplete="new-password" />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="inputs.database"
+ defaultValue="default"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Database Name"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input {...field} />
+ </FormControl>
+ )}
+ />
+ </div>
+ <div>
+ <Controller
+ control={control}
+ name="inputs.ca"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ isOptional
+ label="CA (SSL)"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <SecretInput
+ {...field}
+ containerClassName="text-bunker-300 hover:border-primary-400/50 border border-mineshaft-600 bg-mineshaft-900 px-2 py-1.5"
+ />
+ </FormControl>
+ )}
+ />
+ <Accordion type="multiple" className="mt-4 mb-2 w-full bg-mineshaft-700">
+ <AccordionItem value="advanced">
+ <AccordionTrigger>
+ Creation, Revocation & Renew Statements (optional)
+ </AccordionTrigger>
+ <AccordionContent>
+ <Controller
+ control={control}
+ name="usernameTemplate"
+ defaultValue=""
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Username Template"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <Input
+ {...field}
+ value={field.value || undefined}
+ className="border-mineshaft-600 bg-mineshaft-900 text-sm"
+ />
+ </FormControl>
+ )}
+ />
+ <div className="mb-4 text-sm text-mineshaft-300">
+ Customize ClickHouse statements for managing database user lifecycle
+ </div>
+ <Controller
+ control={control}
+ name="inputs.creationStatement"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Creation Statement"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ helperText="username, password and expiration are dynamically provisioned"
+ >
+ <TextArea
+ {...field}
+ reSize="none"
+ rows={3}
+ className="border-mineshaft-600 bg-mineshaft-900 text-sm"
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="inputs.revocationStatement"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Revocation Statement"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ helperText="username is dynamically provisioned"
+ >
+ <TextArea
+ {...field}
+ reSize="none"
+ rows={3}
+ className="border-mineshaft-600 bg-mineshaft-900 text-sm"
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="inputs.renewStatement"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Renew Statement"
+ helperText="username and expiration are dynamically provisioned"
+ isError={Boolean(error?.message)}
+ errorText={error?.message}
+ >
+ <TextArea
+ {...field}
+ reSize="none"
+ rows={3}
+ className="border-mineshaft-600 bg-mineshaft-900 text-sm"
+ />
+ </FormControl>
+ )}
+ />
+ </AccordionContent>
+ </AccordionItem>
+ </Accordion>
+ <Accordion type="multiple" className="mt-4 mb-2 w-full bg-mineshaft-700">
+ <AccordionItem value="password-config">
+ <AccordionTrigger>Password Configuration (optional)</AccordionTrigger>
+ <AccordionContent>
+ <div className="mb-4 text-sm text-mineshaft-300">
+ Set constraints on the generated database password
+ </div>
+ <div className="space-y-4">
+ <div>
+ <Controller
+ control={control}
+ name="inputs.passwordRequirements.length"
+ defaultValue={48}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Password Length"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ >
+ <Input
+ type="number"
+ min={1}
+ max={250}
+ {...field}
+ onChange={(e) => field.onChange(Number(e.target.value))}
+ />
+ </FormControl>
+ )}
+ />
+ </div>
+
+ <div className="space-y-2">
+ <h4 className="text-sm font-medium">Minimum Required Character Counts</h4>
+ <div className="text-sm text-gray-500">
+ {(() => {
+ const total = Object.values(
+ watch("inputs.passwordRequirements.required") || {}
+ ).reduce((sum, count) => sum + Number(count || 0), 0);
+ const length = watch("inputs.passwordRequirements.length") || 0;
+ const isError = total > length;
+ return (
+ <span className={isError ? "text-red-500" : ""}>
+ Total required characters: {total}{" "}
+ {isError ? `(exceeds length of ${length})` : ""}
+ </span>
+ );
+ })()}
+ </div>
+ <div className="grid grid-cols-2 gap-4">
+ <Controller
+ control={control}
+ name="inputs.passwordRequirements.required.lowercase"
+ defaultValue={1}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Lowercase Count"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText="Minimum number of lowercase letters"
+ >
+ <Input
+ type="number"
+ min={0}
+ {...field}
+ onChange={(e) => field.onChange(Number(e.target.value))}
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="inputs.passwordRequirements.required.uppercase"
+ defaultValue={1}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Uppercase Count"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText="Minimum number of uppercase letters"
+ >
+ <Input
+ type="number"
+ min={0}
+ {...field}
+ onChange={(e) => field.onChange(Number(e.target.value))}
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="inputs.passwordRequirements.required.digits"
+ defaultValue={1}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Digit Count"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText="Minimum number of digits"
+ >
+ <Input
+ type="number"
+ min={0}
+ {...field}
+ onChange={(e) => field.onChange(Number(e.target.value))}
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ control={control}
+ name="inputs.passwordRequirements.required.symbols"
+ defaultValue={0}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Symbol Count"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText="Minimum number of symbols"
+ >
+ <Input
+ type="number"
+ min={0}
+ {...field}
+ onChange={(e) => field.onChange(Number(e.target.value))}
+ />
+ </FormControl>
+ )}
+ />
+ </div>
+ </div>
+
+ <div className="space-y-2">
+ <h4 className="text-sm font-medium">Allowed Symbols</h4>
+ <Controller
+ control={control}
+ name="inputs.passwordRequirements.allowedSymbols"
+ defaultValue="-_.~!*"
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ label="Symbols to use in password"
+ isError={Boolean(error)}
+ errorText={error?.message}
+ helperText="Default: -_.~!*"
+ >
+ <Input {...field} placeholder="-_.~!*" />
+ </FormControl>
+ )}
+ />
+ </div>
+ </div>
+ </AccordionContent>
+ </AccordionItem>
+ </Accordion>
+ </div>
+ </div>
+ </div>
+ <div className="mt-4 flex items-center space-x-4">
+ <Button type="submit" isLoading={isSubmitting}>
+ Save
+ </Button>
+ <Button variant="outline_bg" onClick={onClose}>
+ Cancel
+ </Button>
+ </div>
+ </form>
+ </div>
+ );
+};
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsx
index d75e9ab416..dfaaf68bf0 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsx
@@ -9,6 +9,7 @@ import { EditDynamicSecretAwsIamForm } from "./EditDynamicSecretAwsIamForm";
import { EditDynamicSecretAzureEntraIdForm } from "./EditDynamicSecretAzureEntraIdForm";
import { EditDynamicSecretAzureSqlDatabaseForm } from "./EditDynamicSecretAzureSqlDatabaseForm";
import { EditDynamicSecretCassandraForm } from "./EditDynamicSecretCassandraForm";
+import { EditDynamicSecretClickHouseForm } from "./EditDynamicSecretClickHouseForm";
import { EditDynamicSecretCouchbaseForm } from "./EditDynamicSecretCouchbaseForm";
import { EditDynamicSecretElasticSearchForm } from "./EditDynamicSecretElasticSearchForm";
import { EditDynamicSecretGcpIamForm } from "./EditDynamicSecretGcpIamForm";
@@ -421,6 +422,23 @@ export const EditDynamicSecretForm = ({
/>
</motion.div>
)}
+ {dynamicSecretDetails?.type === DynamicSecretProviders.Clickhouse && (
+ <motion.div
+ key="clickhouse-edit"
+ transition={{ duration: 0.1 }}
+ initial={{ opacity: 0, translateX: 30 }}
+ animate={{ opacity: 1, translateX: 0 }}
+ exit={{ opacity: 0, translateX: -30 }}
+ >
+ <EditDynamicSecretClickHouseForm
+ onClose={onClose}
+ projectSlug={projectSlug}
+ secretPath={secretPath}
+ dynamicSecret={dynamicSecretDetails}
+ environment={environment}
+ />
+ </motion.div>
+ )}
</AnimatePresence>
);
};