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
add support to copy rule id on the frontend
adilsona4e46bcdc500
diff --git a/backend/src/services/secret-validation-rule/secret-validation-rule-schemas.ts b/backend/src/services/secret-validation-rule/secret-validation-rule-schemas.tsindex f3d2c302ed..1baccc03c6 100644--- a/backend/src/services/secret-validation-rule/secret-validation-rule-schemas.ts+++ b/backend/src/services/secret-validation-rule/secret-validation-rule-schemas.ts@@ -1,13 +1,15 @@import { z } from "zod";import { SecretValidationRulesSchema } from "@app/db/schemas";+import { DynamicSecretProviders } from "@app/ee/services/dynamic-secret/providers/models";+import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";import { SECRET_VALIDATION_RULES } from "@app/lib/api-docs";import {ConstraintTarget,ConstraintType,- DynamicSecretRuleProvider,- SecretRotationRuleProvider,+ // DynamicSecretRuleProvider,+ // SecretRotationRuleProvider,SecretValidationRuleType,TSecretValidationRuleInputs} from "./secret-validation-rule-types";@@ -46,17 +48,6 @@ const preventValueReuseRangeRefinement = (c: z.infer<typeof baseConstraintSchemareturn Number.isInteger(num) && num >= 1 && num <= MAX_PREVENT_VALUE_REUSE_VERSIONS;};-export const constraintSchema = baseConstraintSchema- .refine(valueRequiredRefinement, { message: "Value is required", path: ["value"] })- .refine(preventValueReuseTargetRefinement, {- message: "No value reuse constraint can only apply to secret values",- path: ["appliesTo"]- })- .refine(preventValueReuseRangeRefinement, {- message: `Prevent value reuse version count must be between 1 and ${MAX_PREVENT_VALUE_REUSE_VERSIONS}`,- path: ["value"]- });-const buildConstraintSchemaForRuleType = (ruleType: SecretValidationRuleType) => {const allowedTargets =ruleType === SecretValidationRuleType.StaticSecrets ? STATIC_RULE_TARGETS : GENERATED_RULE_TARGETS;@@ -94,7 +85,7 @@ export const staticSecretsInputsSchema = z.object({export const dynamicSecretsInputsSchema = z.object({providers: z- .array(z.nativeEnum(DynamicSecretRuleProvider))+ .array(z.nativeEnum(DynamicSecretProviders)).min(1, "Select at least one provider").describe(SECRET_VALIDATION_RULES.RULE.dynamicSecretProviders),constraints: z@@ -105,7 +96,7 @@ export const dynamicSecretsInputsSchema = z.object({export const secretRotationsInputsSchema = z.object({providers: z- .array(z.nativeEnum(SecretRotationRuleProvider))+ .array(z.nativeEnum(SecretRotation)).min(1, "Select at least one provider").describe(SECRET_VALIDATION_RULES.RULE.secretRotationProviders),constraints: zdiff --git a/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts b/backend/src/services/secret-validation-rule/secret-validation-rule-service.tsindex 9c3cddc49e..b5b5857e00 100644--- a/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts+++ b/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts@@ -38,10 +38,7 @@ import {// type-specific fields flattened alongside `type`. Selecting explicitly keeps// `encryptedInputs` (and any column added later) out of responses rather than// relying on the response schema to strip it.-const $toRuleRecord = (- rule: TSecretValidationRules,- inputs: TSecretValidationRuleInputs-): TSecretValidationRuleRecord =>+const $toRuleRecord = (rule: TSecretValidationRules, inputs: TSecretValidationRuleInputs) =>({id: rule.id,name: rule.name,@@ -52,7 +49,7 @@ const $toRuleRecord = (isActive: rule.isActive,createdAt: rule.createdAt,updatedAt: rule.updatedAt,- type: rule.type as SecretValidationRuleType,+ type: rule.type,...inputs}) as TSecretValidationRuleRecord;@@ -156,10 +153,11 @@ export const secretValidationRuleServiceFactory = ({);}- const { decryptor: ruleInputsDecryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });+ const { encryptor: ruleInputsEncryptor, decryptor: ruleInputsDecryptor } =+ await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId+ });const existingRules = await secretValidationRuleDAL.find({ projectId });checkForOverlappingRules({@@ -180,11 +178,6 @@ export const secretValidationRuleServiceFactory = ({}))});- const { encryptor: ruleInputsEncryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });-const { cipherTextBlob: encryptedRuleInputs } = ruleInputsEncryptor({plainText: Buffer.from(JSON.stringify(parsedInputs))});@@ -241,27 +234,21 @@ export const secretValidationRuleServiceFactory = ({}}- const { decryptor: ruleInputsDecryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });-- const decryptedExistingRuleInputs = ruleInputsDecryptor({- cipherTextBlob: existingRule.encryptedInputs- });+ const { encryptor: ruleInputsEncryptor, decryptor: ruleInputsDecryptor } =+ await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.SecretManager,+ projectId+ });- // `rule` carries `type` alongside the per-type fields, so an update either- // replaces the whole config or leaves the stored one untouched. Only the- // fields other than `type` are stored in `encryptedInputs`.+ // An update either replaces the whole config or leaves the stored one+ // untouched. `type` has its own column and the per-type input schemas strip+ // it, so the incoming config can go straight in — only the per-type input+ // fields reach the blob.const ruleType = rule?.type ?? existingRule.type;- let ruleInputs: unknown;- if (rule) {- const { type, ...inputsFromRule } = rule;- ruleInputs = inputsFromRule;- } else {- ruleInputs = JSON.parse(decryptedExistingRuleInputs.toString()) as unknown;- }- const parsedInputs = parseSecretValidationRuleInputs(ruleType, ruleInputs);+ const parsedInputs = parseSecretValidationRuleInputs(+ ruleType,+ rule ?? (JSON.parse(ruleInputsDecryptor({ cipherTextBlob: existingRule.encryptedInputs }).toString()) as unknown)+ );if (ruleType === SecretValidationRuleType.DynamicSecrets || ruleType === SecretValidationRuleType.SecretRotations) {assertConstraintsProduceSafePasswords(@@ -292,34 +279,19 @@ export const secretValidationRuleServiceFactory = ({excludeRuleId: ruleId});- let updatedRuleInputs: Buffer | undefined;-- if (rule) {- const { encryptor: ruleInputsEncryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });-- const { cipherTextBlob: encryptedRuleInputs } = ruleInputsEncryptor({- plainText: Buffer.from(JSON.stringify(parsedInputs))- });- updatedRuleInputs = encryptedRuleInputs;- }+ // The rule config moves as a unit: `type` and the re-encrypted inputs are+ // written together, or neither is.+ const encryptedInputs = rule+ ? ruleInputsEncryptor({ plainText: Buffer.from(JSON.stringify(parsedInputs)) }).cipherTextBlob+ : undefined;const updatedRule = await secretValidationRuleDAL.updateById(ruleId, {+ ...dto,...(envId !== undefined && { envId }),- ...(Boolean(updatedRuleInputs) && { encryptedInputs: updatedRuleInputs }),- ...(rule && { type: rule.type }),- ...dto+ ...(rule && { type: rule.type, encryptedInputs })});- return $toRuleRecord(- updatedRule,- parseSecretValidationRuleInputs(- updatedRule.type,- JSON.parse(ruleInputsDecryptor({ cipherTextBlob: updatedRule.encryptedInputs }).toString()) as unknown- )- );+ return $toRuleRecord(updatedRule, parsedInputs);};const deleteRule = async ({@@ -387,6 +359,8 @@ export const secretValidationRuleServiceFactory = ({const rules = await secretValidationRuleDAL.find({ projectId, isActive: true });if (!rules.length) return;+ // Secret values and rule inputs share the SecretManager data key, so one+ // cipher pair serves both — this runs on every secret write.const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({type: KmsDataKey.SecretManager,projectId@@ -400,16 +374,11 @@ export const secretValidationRuleServiceFactory = ({canExpandValue: () => true});- const { decryptor: ruleInputsDecryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.SecretManager,- projectId- });-const parsedRules = rules.map((r) => ({...r,inputs: parseSecretValidationRuleInputs(r.type,- JSON.parse(ruleInputsDecryptor({ cipherTextBlob: r.encryptedInputs }).toString()) as unknown+ JSON.parse(secretManagerDecryptor({ cipherTextBlob: r.encryptedInputs }).toString()) as unknown)}));diff --git a/frontend/src/hooks/api/secretValidationRules/useMatchingValidationRules.ts b/frontend/src/hooks/api/secretValidationRules/useMatchingValidationRules.tsindex 55c1065549..ff17bfd812 100644--- a/frontend/src/hooks/api/secretValidationRules/useMatchingValidationRules.ts+++ b/frontend/src/hooks/api/secretValidationRules/useMatchingValidationRules.ts@@ -7,9 +7,7 @@ import { useListSecretValidationRules } from "./queries";import {DynamicSecretRuleProvider,SecretRotationRuleProvider,- SecretValidationRuleType,- TDynamicSecretsInputs,- TSecretRotationsInputs+ SecretValidationRuleType} from "./types";type TParams = {@@ -45,10 +43,7 @@ export const useMatchingValidationRules = ({if (rule.type !== type) return false;if (rule.envId && rule.envId !== envId) return false;if (!picomatch.isMatch(secretPath, rule.secretPath, { strictSlashes: false })) return false;- // `rule.type !== type` compares against a variable, so TS can't narrow the- // union here — only generated-credential arms reach this point.- const generatedRule = rule as TDynamicSecretsInputs | TSecretRotationsInputs;- return generatedRule.providers?.includes(provider as never);+ return "providers" in rule && rule.providers.includes(provider as never);});}, [rules, type, provider, environmentSlug, secretPath, currentProject.environments]);diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.tsxindex 25766161c6..531634dfe3 100644--- a/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.tsx+++ b/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.tsx@@ -3,6 +3,7 @@ import { useState } from "react";import { Controller, FormProvider, useFieldArray, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import {+ CopyIcon,EllipsisVerticalIcon,InfoIcon,PencilIcon,@@ -73,15 +74,13 @@ import {ProjectPermissionSub} from "@app/context/ProjectPermissionContext/types";import {+ SecretValidationRuleType,+ TSecretValidationRuleConfig,useCreateSecretValidationRule,useDeleteSecretValidationRule,useListSecretValidationRules,useUpdateSecretValidationRule} from "@app/hooks/api/secretValidationRules";-import {- SecretValidationRuleType,- TSecretValidationRuleConfig-} from "@app/hooks/api/secretValidationRules/types";import { ConstraintCard } from "./ConstraintCard";import {@@ -584,7 +583,7 @@ export const SecretValidationRulesSection = () => {enforcement: {type: editingRule.type as string as RuleType,constraints: editingRule.constraints,- ...("providers" in editingRule ? { providers: editingRule.providers } : {})+ ...("providers" in editingRule && { providers: editingRule.providers })}} as Partial<TRuleForm>): undefined;@@ -718,6 +717,18 @@ export const SecretValidationRulesSection = () => {</IconButton></DropdownMenuTrigger><DropdownMenuContent align="end">+ <DropdownMenuItem+ onClick={() => {+ navigator.clipboard.writeText(rule.id);+ createNotification({+ text: "Rule ID copied to clipboard",+ type: "success"+ });+ }}+ >+ <CopyIcon className="mr-2 size-4" />+ Copy Rule ID+ </DropdownMenuItem><ProjectPermissionCanI={ProjectPermissionActions.Edit}a={ProjectPermissionSub.Settings}diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.utils.ts b/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.utils.tsindex 1e46d9eb82..0c36069850 100644--- a/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.utils.ts+++ b/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.utils.ts@@ -243,8 +243,7 @@ export const ruleFormSchema = z.object({description: z.string().max(500).optional(),environment: z.string().nullable().default(null),folderPath: z.string().min(1, "Folder path is required").default("/**"),- // Constraints (and providers for generated-credential rules) sit directly on- // the enforcement object, matching the API shape — no nested `inputs` wrapper.+ // Mirrors the API rule config shape (see backend `SecretValidationRuleSchema`).enforcement: z.discriminatedUnion("type", [z.object({ type: z.literal(RuleType.StaticSecrets), ...staticSecretsInputsSchema.shape }),z.object({ type: z.literal(RuleType.DynamicSecrets), ...dynamicSecretsInputsSchema.shape }),