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
feat: change API design of secret validation
adilson6760c9bb6071
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex c3addfcc5b..0c6f3cda67 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -4029,3 +4029,15 @@ export const RELAYS = {token: "The one-time enrollment token previously issued for this relay (token method only)."}} as const;++export const SECRET_VALIDATION_RULES = {+ RULE: {+ type: "The kind of secret the rule applies to. Determines which fields the rule accepts and where the constraints are enforced: `static-secrets` constraints run on write, while `dynamic-secrets` and `secret-rotations` constraints shape the generated password.",+ constraints:+ "The constraints enforced by this rule. Each constraint names what it checks (`type`), what it applies to (`appliesTo`), and its `value` — e.g. the minimum character count for `min-length` or the pattern for `regex-pattern`.",+ dynamicSecretProviders:+ "The dynamic secret providers this rule applies to. A lease is only constrained when its provider is listed here.",+ secretRotationProviders:+ "The secret rotation providers this rule applies to. A rotation is only constrained when its provider is listed here."+ }+} as const;diff --git a/backend/src/server/routes/v1/secret-validation-rule-router.ts b/backend/src/server/routes/v1/secret-validation-rule-router.tsindex ea77a7fb2a..98d5970156 100644--- a/backend/src/server/routes/v1/secret-validation-rule-router.ts+++ b/backend/src/server/routes/v1/secret-validation-rule-router.ts@@ -6,10 +6,9 @@ import { getTelemetryDistinctId } from "@app/server/lib/telemetry";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { AuthMode } from "@app/services/auth/auth-type";import {- SecretValidationRuleInputSchema,- SecretValidationRuleResponseSchema+ SecretValidationRuleResponseSchema,+ SecretValidationRuleSchema} from "@app/services/secret-validation-rule/secret-validation-rule-schemas";-import { SecretValidationRuleType } from "@app/services/secret-validation-rule/secret-validation-rule-types";import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";export const registerSecretValidationRuleRouter = async (server: FastifyZodProvider) => {@@ -57,7 +56,7 @@ export const registerSecretValidationRuleRouter = async (server: FastifyZodProvidescription: z.string().trim().max(500).nullable().optional(),environmentSlug: z.string().trim().min(1).optional(),secretPath: z.string().trim().min(1),- rule: SecretValidationRuleInputSchema+ rule: SecretValidationRuleSchema}),response: {200: z.object({@@ -77,8 +76,7 @@ export const registerSecretValidationRuleRouter = async (server: FastifyZodProvidescription: req.body.description,environmentSlug: req.body.environmentSlug,secretPath: req.body.secretPath,- type: req.body.rule.type,- inputs: req.body.rule.inputs+ rule: req.body.rule});await server.services.auditLog.createAuditLog({@@ -125,13 +123,10 @@ export const registerSecretValidationRuleRouter = async (server: FastifyZodProvidescription: z.string().trim().max(500).nullable().optional(),environmentSlug: z.string().trim().min(1).nullable().optional(),secretPath: z.string().trim().min(1).optional(),- type: z.nativeEnum(SecretValidationRuleType).optional(),- // Inputs are validated strictly in the service against the resolved- // rule type via `parseSecretValidationRuleInputs`. We can't pick the- // right schema here because `type` and `inputs` are sibling fields,- // so a union over the per-type input schemas would silently strip- // fields (e.g. `providers`) whenever a sibling member also matched.- inputs: z.object({}).passthrough().optional(),+ // The rule config is replaced as a whole when supplied — `type` and the+ // per-type fields have to move together for the discriminant to be+ // meaningful. Omit it to leave the stored config untouched.+ rule: SecretValidationRuleSchema.optional(),isActive: z.boolean().optional()}),response: {@@ -160,7 +155,7 @@ export const registerSecretValidationRuleRouter = async (server: FastifyZodProvimetadata: {ruleId: req.params.ruleId,name: req.body.name,- type: req.body.type,+ type: req.body.rule?.type,environmentSlug: req.body.environmentSlug,secretPath: req.body.secretPath,isActive: req.body.isActivediff --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 79411a8246..f3d2c302ed 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,6 +1,7 @@import { z } from "zod";import { SecretValidationRulesSchema } from "@app/db/schemas";+import { SECRET_VALIDATION_RULES } from "@app/lib/api-docs";import {ConstraintTarget,@@ -85,24 +86,50 @@ const buildConstraintSchemaForRuleType = (ruleType: SecretValidationRuleType) =>};export const staticSecretsInputsSchema = z.object({- constraints: z.array(buildConstraintSchemaForRuleType(SecretValidationRuleType.StaticSecrets)).min(1)+ constraints: z+ .array(buildConstraintSchemaForRuleType(SecretValidationRuleType.StaticSecrets))+ .min(1)+ .describe(SECRET_VALIDATION_RULES.RULE.constraints)});export const dynamicSecretsInputsSchema = z.object({- providers: z.array(z.nativeEnum(DynamicSecretRuleProvider)).min(1, "Select at least one provider"),- constraints: z.array(buildConstraintSchemaForRuleType(SecretValidationRuleType.DynamicSecrets)).min(1)+ providers: z+ .array(z.nativeEnum(DynamicSecretRuleProvider))+ .min(1, "Select at least one provider")+ .describe(SECRET_VALIDATION_RULES.RULE.dynamicSecretProviders),+ constraints: z+ .array(buildConstraintSchemaForRuleType(SecretValidationRuleType.DynamicSecrets))+ .min(1)+ .describe(SECRET_VALIDATION_RULES.RULE.constraints)});export const secretRotationsInputsSchema = z.object({- providers: z.array(z.nativeEnum(SecretRotationRuleProvider)).min(1, "Select at least one provider"),- constraints: z.array(buildConstraintSchemaForRuleType(SecretValidationRuleType.SecretRotations)).min(1)+ providers: z+ .array(z.nativeEnum(SecretRotationRuleProvider))+ .min(1, "Select at least one provider")+ .describe(SECRET_VALIDATION_RULES.RULE.secretRotationProviders),+ constraints: z+ .array(buildConstraintSchemaForRuleType(SecretValidationRuleType.SecretRotations))+ .min(1)+ .describe(SECRET_VALIDATION_RULES.RULE.constraints)});-// Discriminated union for create/update request bodies-export const SecretValidationRuleInputSchema = z.discriminatedUnion("type", [- z.object({ type: z.literal(SecretValidationRuleType.StaticSecrets), inputs: staticSecretsInputsSchema }),- z.object({ type: z.literal(SecretValidationRuleType.DynamicSecrets), inputs: dynamicSecretsInputsSchema }),- z.object({ type: z.literal(SecretValidationRuleType.SecretRotations), inputs: secretRotationsInputsSchema })+// Discriminated union for create request bodies / API responses.+// Constraints (and providers for generated-credential rules) sit directly on+// the rule object — there is no nested `inputs` wrapper at the HTTP boundary.+export const SecretValidationRuleSchema = z.discriminatedUnion("type", [+ z.object({+ type: z.literal(SecretValidationRuleType.StaticSecrets).describe(SECRET_VALIDATION_RULES.RULE.type),+ ...staticSecretsInputsSchema.shape+ }),+ z.object({+ type: z.literal(SecretValidationRuleType.DynamicSecrets).describe(SECRET_VALIDATION_RULES.RULE.type),+ ...dynamicSecretsInputsSchema.shape+ }),+ z.object({+ type: z.literal(SecretValidationRuleType.SecretRotations).describe(SECRET_VALIDATION_RULES.RULE.type),+ ...secretRotationsInputsSchema.shape+ })]);// Map of type → inputs schema, used for runtime parsing@@ -123,4 +150,4 @@ export const parseSecretValidationRuleInputs = (type: string, inputs: unknown) =export const SecretValidationRuleResponseSchema = SecretValidationRulesSchema.omit({type: true,encryptedInputs: true-}).and(SecretValidationRuleInputSchema);+}).and(SecretValidationRuleSchema);diff --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 e8668788d3..9c3cddc49e 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@@ -1,7 +1,7 @@import { ForbiddenError } from "@casl/ability";import picomatch from "picomatch";-import { ActionProjectType } from "@app/db/schemas";+import { ActionProjectType, TSecretValidationRules } from "@app/db/schemas";import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";import { NotFoundError } from "@app/lib/errors";@@ -29,10 +29,33 @@ import {TDynamicSecretsInputs,TListSecretValidationRulesDTO,TSecretRotationsInputs,+ TSecretValidationRuleInputs,TSecretValidationRuleRecord,TUpdateSecretValidationRuleDTO} from "./secret-validation-rule-types";+// Builds the API-facing rule record: the selected row fields plus the rule's+// 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 =>+ ({+ id: rule.id,+ name: rule.name,+ description: rule.description,+ projectId: rule.projectId,+ envId: rule.envId,+ secretPath: rule.secretPath,+ isActive: rule.isActive,+ createdAt: rule.createdAt,+ updatedAt: rule.updatedAt,+ type: rule.type as SecretValidationRuleType,+ ...inputs+ }) as TSecretValidationRuleRecord;+type TSecretValidationRuleServiceFactoryDep = {secretValidationRuleDAL: TSecretValidationRuleDALFactory;projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne">;@@ -78,16 +101,14 @@ export const secretValidationRuleServiceFactory = ({projectId});- const finalRules = (rules || []).map(- (rule) =>- ({- ...rule,- type: rule.type as SecretValidationRuleType,- inputs: parseSecretValidationRuleInputs(- rule.type,- JSON.parse(ruleInputsDecryptor({ cipherTextBlob: rule.encryptedInputs }).toString()) as unknown- )- }) as TSecretValidationRuleRecord+ const finalRules = (rules || []).map((rule) =>+ $toRuleRecord(+ rule,+ parseSecretValidationRuleInputs(+ rule.type,+ JSON.parse(ruleInputsDecryptor({ cipherTextBlob: rule.encryptedInputs }).toString()) as unknown+ )+ ));return finalRules;@@ -103,8 +124,7 @@ export const secretValidationRuleServiceFactory = ({description,environmentSlug,secretPath,- type,- inputs+ rule: { type, ...inputs }}: TCreateSecretValidationRuleDTO) => {const { permission } = await permissionService.getProjectPermission({actor,@@ -179,11 +199,7 @@ export const secretValidationRuleServiceFactory = ({encryptedInputs: encryptedRuleInputs});- return {- ...rule,- type: rule.type as SecretValidationRuleType,- inputs: parsedInputs- } as TSecretValidationRuleRecord;+ return $toRuleRecord(rule, parsedInputs);};const updateRule = async ({@@ -194,7 +210,7 @@ export const secretValidationRuleServiceFactory = ({projectId,ruleId,environmentSlug,- inputs,+ rule,...dto}: TUpdateSecretValidationRuleDTO) => {const { permission } = await permissionService.getProjectPermission({@@ -234,8 +250,17 @@ export const secretValidationRuleServiceFactory = ({cipherTextBlob: existingRule.encryptedInputs});- const ruleType = dto.type ?? existingRule.type;- const ruleInputs = inputs ?? (JSON.parse(decryptedExistingRuleInputs.toString()) as unknown);+ // `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`.+ 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);if (ruleType === SecretValidationRuleType.DynamicSecrets || ruleType === SecretValidationRuleType.SecretRotations) {@@ -269,7 +294,7 @@ export const secretValidationRuleServiceFactory = ({let updatedRuleInputs: Buffer | undefined;- if (inputs) {+ if (rule) {const { encryptor: ruleInputsEncryptor } = await kmsService.createCipherPairWithDataKey({type: KmsDataKey.SecretManager,projectId@@ -284,17 +309,17 @@ export const secretValidationRuleServiceFactory = ({const updatedRule = await secretValidationRuleDAL.updateById(ruleId, {...(envId !== undefined && { envId }),...(Boolean(updatedRuleInputs) && { encryptedInputs: updatedRuleInputs }),+ ...(rule && { type: rule.type }),...dto});- return {- ...updatedRule,- type: updatedRule.type as SecretValidationRuleType,- inputs: parseSecretValidationRuleInputs(+ return $toRuleRecord(+ updatedRule,+ parseSecretValidationRuleInputs(updatedRule.type,JSON.parse(ruleInputsDecryptor({ cipherTextBlob: updatedRule.encryptedInputs }).toString()) as unknown)- } as TSecretValidationRuleRecord;+ );};const deleteRule = async ({@@ -326,14 +351,13 @@ export const secretValidationRuleServiceFactory = ({});await secretValidationRuleDAL.deleteById(ruleId);- return {- ...existingRule,- type: existingRule.type as SecretValidationRuleType,- inputs: parseSecretValidationRuleInputs(+ return $toRuleRecord(+ existingRule,+ parseSecretValidationRuleInputs(existingRule.type,JSON.parse(ruleInputsDecryptor({ cipherTextBlob: existingRule.encryptedInputs }).toString()) as unknown)- } as TSecretValidationRuleRecord;+ );};/**diff --git a/backend/src/services/secret-validation-rule/secret-validation-rule-types.ts b/backend/src/services/secret-validation-rule/secret-validation-rule-types.tsindex 7df4cf975c..96a02af3e6 100644--- a/backend/src/services/secret-validation-rule/secret-validation-rule-types.ts+++ b/backend/src/services/secret-validation-rule/secret-validation-rule-types.ts@@ -58,29 +58,29 @@ export type TSecretRotationsInputs = {export type TSecretValidationRuleInputs = TStaticSecretsInputs | TDynamicSecretsInputs | TSecretRotationsInputs;+// A rule's type-specific configuration as it appears on the wire: the per-type+// fields sit alongside `type` rather than under an `inputs` wrapper, so `type`+// discriminates them. The stored blob (`encryptedInputs`) holds the same fields+// minus `type`, which has its own column.+export type TSecretValidationRuleConfig =+ | ({ type: SecretValidationRuleType.StaticSecrets } & TStaticSecretsInputs)+ | ({ type: SecretValidationRuleType.DynamicSecrets } & TDynamicSecretsInputs)+ | ({ type: SecretValidationRuleType.SecretRotations } & TSecretRotationsInputs);+// Discriminated rule shape returned by the service. The `type` field narrows-// the matching `inputs` shape so the response schema (which is a+// the matching per-type fields so the response schema (which is a// discriminated union over `type`) is satisfied without manual casts at// each handler.-type TRuleCommonFields = Omit<TSecretValidationRules, "type">;--export type TSecretValidationRuleRecord =- | (TRuleCommonFields & { type: SecretValidationRuleType.StaticSecrets; inputs: TStaticSecretsInputs })- | (TRuleCommonFields & { type: SecretValidationRuleType.DynamicSecrets; inputs: TDynamicSecretsInputs })- | (TRuleCommonFields & { type: SecretValidationRuleType.SecretRotations; inputs: TSecretRotationsInputs });--// `inputs` is validated server-side by `parseSecretValidationRuleInputs` against-// the resolved rule type, so the DTO accepts `unknown` rather than a structured-// union. The shape can't be known at the route boundary because `type` and-// `inputs` are sibling fields and a per-type Zod union would silently strip-// fields when sibling members happen to also match.+type TRuleCommonFields = Omit<TSecretValidationRules, "type" | "encryptedInputs">;++export type TSecretValidationRuleRecord = TRuleCommonFields & TSecretValidationRuleConfig;+export type TCreateSecretValidationRuleDTO = {name: string;description?: string | null;environmentSlug?: string;secretPath: string;- type: SecretValidationRuleType;- inputs: unknown;+ rule: TSecretValidationRuleConfig;} & TProjectPermission;export type TUpdateSecretValidationRuleDTO = {@@ -89,8 +89,7 @@ export type TUpdateSecretValidationRuleDTO = {description?: string | null;environmentSlug?: string | null;secretPath?: string;- type?: SecretValidationRuleType;- inputs?: unknown;+ rule?: TSecretValidationRuleConfig;isActive?: boolean;} & TProjectPermission;diff --git a/frontend/src/components/v3/platform/PasswordGenerator/PasswordGenerator.tsx b/frontend/src/components/v3/platform/PasswordGenerator/PasswordGenerator.tsxindex 0a605d37a3..68798d6f45 100644--- a/frontend/src/components/v3/platform/PasswordGenerator/PasswordGenerator.tsx+++ b/frontend/src/components/v3/platform/PasswordGenerator/PasswordGenerator.tsx@@ -51,7 +51,7 @@ const NONE_RULE_OPTION: RuleOption = {};const getValueConstraints = (rule: TSecretValidationRule): TConstraint[] =>- rule.inputs.constraints.filter((c) => c.appliesTo === ConstraintTarget.SecretValue);+ rule.constraints.filter((c) => c.appliesTo === ConstraintTarget.SecretValue);const hasValueConstraints = (rule: TSecretValidationRule): boolean =>getValueConstraints(rule).length > 0;diff --git a/frontend/src/hooks/api/secretValidationRules/index.ts b/frontend/src/hooks/api/secretValidationRules/index.tsindex d0cee27f3e..5110de6c1f 100644--- a/frontend/src/hooks/api/secretValidationRules/index.ts+++ b/frontend/src/hooks/api/secretValidationRules/index.ts@@ -9,6 +9,7 @@ export type {TCreateSecretValidationRuleDTO,TDeleteSecretValidationRuleDTO,TSecretValidationRule,+ TSecretValidationRuleConfig,TUpdateSecretValidationRuleDTO} from "./types";export {diff --git a/frontend/src/hooks/api/secretValidationRules/types.ts b/frontend/src/hooks/api/secretValidationRules/types.tsindex 6b86086442..866691c639 100644--- a/frontend/src/hooks/api/secretValidationRules/types.ts+++ b/frontend/src/hooks/api/secretValidationRules/types.ts@@ -52,25 +52,27 @@ export type TSecretRotationsInputs = {constraints: TConstraint[];};-export type TSecretValidationRuleInputs =- | TStaticSecretsInputs- | TDynamicSecretsInputs- | TSecretRotationsInputs;+// A rule's type-specific configuration: the per-type fields sit alongside+// `type`, which discriminates them. Mirror of backend `TSecretValidationRuleConfig`.+export type TSecretValidationRuleConfig =+ | ({ type: SecretValidationRuleType.StaticSecrets } & TStaticSecretsInputs)+ | ({ type: SecretValidationRuleType.DynamicSecrets } & TDynamicSecretsInputs)+ | ({ type: SecretValidationRuleType.SecretRotations } & TSecretRotationsInputs);-export type TSecretValidationRule = {+type TSecretValidationRuleBase = {id: string;name: string;description?: string | null;projectId: string;envId: string | null;secretPath: string;- type: SecretValidationRuleType;- inputs: TSecretValidationRuleInputs;isActive: boolean;createdAt: string;updatedAt: string;};+export type TSecretValidationRule = TSecretValidationRuleBase & TSecretValidationRuleConfig;+export type TListSecretValidationRulesDTO = {projectId: string;};@@ -81,10 +83,7 @@ export type TCreateSecretValidationRuleDTO = {description?: string | null;environmentSlug?: string;secretPath: string;- rule: {- type: SecretValidationRuleType;- inputs: TSecretValidationRuleInputs;- };+ rule: TSecretValidationRuleConfig;};export type TUpdateSecretValidationRuleDTO = {@@ -94,8 +93,8 @@ export type TUpdateSecretValidationRuleDTO = {description?: string | null;environmentSlug?: string | null;secretPath?: string;- type?: SecretValidationRuleType;- inputs?: TSecretValidationRuleInputs;+ // Replaced as a whole when supplied; omit to leave the stored config untouched.+ rule?: TSecretValidationRuleConfig;isActive?: boolean;};diff --git a/frontend/src/hooks/api/secretValidationRules/useMatchingValidationRules.ts b/frontend/src/hooks/api/secretValidationRules/useMatchingValidationRules.tsindex 26ecc2b98d..55c1065549 100644--- a/frontend/src/hooks/api/secretValidationRules/useMatchingValidationRules.ts+++ b/frontend/src/hooks/api/secretValidationRules/useMatchingValidationRules.ts@@ -45,8 +45,10 @@ 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;- const inputs = rule.inputs as TDynamicSecretsInputs | TSecretRotationsInputs;- return inputs.providers?.includes(provider as never);+ // `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);});}, [rules, type, provider, environmentSlug, secretPath, currentProject.environments]);diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/ConstraintCard.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/ConstraintCard.tsxindex d45be477ee..ab18e663a6 100644--- a/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/ConstraintCard.tsx+++ b/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/ConstraintCard.tsx@@ -33,8 +33,8 @@ type Props = {export const ConstraintCard = ({ index, onRemove }: Props) => {const { control, watch } = useFormContext<TRuleForm>();- const constraintType = watch(`enforcement.inputs.constraints.${index}.type`);- const allConstraints = watch("enforcement.inputs.constraints");+ const constraintType = watch(`enforcement.constraints.${index}.type`);+ const allConstraints = watch("enforcement.constraints");const ruleType = watch("enforcement.type");// Generated-credential rules currently only target the generated password.const isGeneratedCredentialRule =@@ -98,7 +98,7 @@ export const ConstraintCard = ({ index, onRemove }: Props) => {<label className="text-xs font-medium text-muted">Applies to</label><Controllercontrol={control}- name={`enforcement.inputs.constraints.${index}.appliesTo`}+ name={`enforcement.constraints.${index}.appliesTo`}render={({ field: { value, onChange } }) => (<Select value={value} onValueChange={onChange}><SelectTrigger>@@ -146,7 +146,7 @@ export const ConstraintCard = ({ index, onRemove }: Props) => {</label><Controllercontrol={control}- name={`enforcement.inputs.constraints.${index}.value`}+ name={`enforcement.constraints.${index}.value`}render={({ field, fieldState: { error } }) => (<div><Inputdiff --git a/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.tsxindex c9479642ef..25766161c6 100644--- a/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.tsx+++ b/frontend/src/pages/secret-manager/SettingsPage/components/SecretValidationRulesSection/SecretValidationRulesSection.tsx@@ -78,7 +78,10 @@ import {useListSecretValidationRules,useUpdateSecretValidationRule} from "@app/hooks/api/secretValidationRules";-import { SecretValidationRuleType } from "@app/hooks/api/secretValidationRules/types";+import {+ SecretValidationRuleType,+ TSecretValidationRuleConfig+} from "@app/hooks/api/secretValidationRules/types";import { ConstraintCard } from "./ConstraintCard";import {@@ -115,7 +118,7 @@ const ProviderMultiSelect = <T extends string>({<label className="text-xs font-medium text-muted">{label}</label><Controllercontrol={control}- name="enforcement.inputs.providers"+ name="enforcement.providers"render={({ field }) => {const selected = options.filter((opt) =>(field.value as T[] | undefined)?.includes(opt.value)@@ -168,9 +171,7 @@ const RuleFormContent = ({folderPath: "/**",enforcement: {type: RuleType.StaticSecrets,- inputs: {- constraints: []- }+ constraints: []}}});@@ -183,10 +184,10 @@ const RuleFormContent = ({const { fields, append, remove, replace } = useFieldArray({control,- name: "enforcement.inputs.constraints"+ name: "enforcement.constraints"});- const watchedConstraints = form.watch("enforcement.inputs.constraints");+ const watchedConstraints = form.watch("enforcement.constraints");const watchedRuleType = form.watch("enforcement.type");const isGeneratedCredentialRule =watchedRuleType === RuleType.DynamicSecrets || watchedRuleType === RuleType.SecretRotations;@@ -277,7 +278,7 @@ const RuleFormContent = ({onChange(next);replace([]);if (next !== RuleType.StaticSecrets) {- form.setValue("enforcement.inputs.providers" as never, [] as never, {+ form.setValue("enforcement.providers" as never, [] as never, {shouldDirty: true,shouldValidate: false});@@ -305,7 +306,7 @@ const RuleFormContent = ({control={control}error={// discriminated form types: providers only exists on this arm- (errors.enforcement?.inputs as { providers?: { message?: string } } | undefined)+ (errors.enforcement as { providers?: { message?: string } } | undefined)?.providers?.message}/>@@ -316,7 +317,7 @@ const RuleFormContent = ({options={SECRET_ROTATION_PROVIDER_OPTIONS}control={control}error={- (errors.enforcement?.inputs as { providers?: { message?: string } } | undefined)+ (errors.enforcement as { providers?: { message?: string } } | undefined)?.providers?.message}/>@@ -453,11 +454,11 @@ const RuleFormContent = ({{fields.length === 0 && (<div className="rounded-md border border-dashed border-border py-8 text-center"><p className="text-sm text-muted">No constraints added yet</p>- {(errors.enforcement?.inputs?.constraints?.root?.message ||- errors.enforcement?.inputs?.constraints?.message) && (+ {(errors.enforcement?.constraints?.root?.message ||+ errors.enforcement?.constraints?.message) && (<p className="mt-1 text-xs text-danger">- {errors.enforcement?.inputs?.constraints?.root?.message ||- errors.enforcement?.inputs?.constraints?.message}+ {errors.enforcement?.constraints?.root?.message ||+ errors.enforcement?.constraints?.message}</p>)}</div>@@ -470,11 +471,11 @@ const RuleFormContent = ({</div>{fields.length > 0 &&- (errors.enforcement?.inputs?.constraints?.root?.message ||- errors.enforcement?.inputs?.constraints?.message) && (+ (errors.enforcement?.constraints?.root?.message ||+ errors.enforcement?.constraints?.message) && (<p className="mt-1 text-xs text-danger">- {errors.enforcement?.inputs?.constraints?.root?.message ||- errors.enforcement?.inputs?.constraints?.message}+ {errors.enforcement?.constraints?.root?.message ||+ errors.enforcement?.constraints?.message}</p>)}</div>@@ -536,6 +537,13 @@ export const SecretValidationRulesSection = () => {const handleClose = () => setSheetState({ open: false });const handleSubmit = async (data: TRuleForm, isActive?: boolean) => {+ // The form mirrors the API rule config field-for-field; only the enum+ // identity differs (local `RuleType` vs `SecretValidationRuleType`).+ const rule = {+ ...data.enforcement,+ type: data.enforcement.type as string as SecretValidationRuleType+ } as TSecretValidationRuleConfig;+if (sheetState.open && sheetState.mode === "edit") {await updateRule.mutateAsync({projectId: currentProject.id,@@ -545,8 +553,7 @@ export const SecretValidationRulesSection = () => {isActive,environmentSlug: data.environment ?? null,secretPath: data.folderPath,- type: data.enforcement.type as string as SecretValidationRuleType,- inputs: data.enforcement.inputs+ rule});createNotification({ text: "Rule updated", type: "success" });} else {@@ -556,10 +563,7 @@ export const SecretValidationRulesSection = () => {description: data.description,environmentSlug: data.environment ?? undefined,secretPath: data.folderPath,- rule: {- type: data.enforcement.type as string as SecretValidationRuleType,- inputs: data.enforcement.inputs- }+ rule});createNotification({ text: "Rule created", type: "success" });}@@ -579,7 +583,8 @@ export const SecretValidationRulesSection = () => {folderPath: editingRule.secretPath,enforcement: {type: editingRule.type as string as RuleType,- inputs: editingRule.inputs+ constraints: editingRule.constraints,+ ...("providers" in editingRule ? { providers: editingRule.providers } : {})}} as Partial<TRuleForm>): undefined;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 eebff8fcb8..1e46d9eb82 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,10 +243,12 @@ 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.enforcement: z.discriminatedUnion("type", [- z.object({ type: z.literal(RuleType.StaticSecrets), inputs: staticSecretsInputsSchema }),- z.object({ type: z.literal(RuleType.DynamicSecrets), inputs: dynamicSecretsInputsSchema }),- z.object({ type: z.literal(RuleType.SecretRotations), inputs: secretRotationsInputsSchema })+ z.object({ type: z.literal(RuleType.StaticSecrets), ...staticSecretsInputsSchema.shape }),+ z.object({ type: z.literal(RuleType.DynamicSecrets), ...dynamicSecretsInputsSchema.shape }),+ z.object({ type: z.literal(RuleType.SecretRotations), ...secretRotationsInputsSchema.shape })])});