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
fix(kmip): enforce the certificate TTL floor at issuance
bernie-g7215f4e1bc0e
diff --git a/backend/src/ee/routes/v1/kmip-router.ts b/backend/src/ee/routes/v1/kmip-router.tsindex e991bfe309..03e3327978 100644--- a/backend/src/ee/routes/v1/kmip-router.ts+++ b/backend/src/ee/routes/v1/kmip-router.ts@@ -3,6 +3,7 @@ import { z } from "zod";import { KmipClientsSchema } from "@app/db/schemas";import { EventType } from "@app/ee/services/audit-log/audit-log-types";import { KmipPermission } from "@app/ee/services/kmip/kmip-enum";+import { MIN_SERVER_CERT_TTL } from "@app/ee/services/kmip/kmip-service";import { KmipClientOrderBy } from "@app/ee/services/kmip/kmip-types";import { ms } from "@app/lib/ms";import { OrderByDirection } from "@app/lib/types";@@ -290,7 +291,13 @@ export const registerKmipRouter = async (server: FastifyZodProvider) => {body: z.object({keyAlgorithm: z.nativeEnum(CertKeyAlgorithm).optional(),- ttl: z.string().refine((val) => ms(val) > 0, "TTL must be a positive number"),+ ttl: z.string().refine((val) => {+ try {+ return ms(val) >= ms(MIN_SERVER_CERT_TTL);+ } catch {+ return false;+ }+ }, "TTL must be a valid duration of at least 1 hour (e.g. 12h, 30d, 1y)"),csr: z.string().trim().min(1, "CSR cannot be empty").max(4096).optional()}).refine((data) => data.csr || data.keyAlgorithm, {diff --git a/backend/src/ee/routes/v1/kmip-server-router.ts b/backend/src/ee/routes/v1/kmip-server-router.tsindex 971f7d47f5..8dc2b5f98a 100644--- a/backend/src/ee/routes/v1/kmip-server-router.ts+++ b/backend/src/ee/routes/v1/kmip-server-router.ts@@ -2,6 +2,7 @@ import z from "zod";import { KmipServersSchema } from "@app/db/schemas";import { EventType, UserAgentType } from "@app/ee/services/audit-log/audit-log-types";+import { MIN_SERVER_CERT_TTL } from "@app/ee/services/kmip/kmip-service";import { validateAccountIds, validatePrincipalArns } from "@app/ee/services/resource-auth-method/aws-auth-validators";import { ResourceAuthMethodType } from "@app/ee/services/resource-auth-method/resource-auth-method-fns";import { ApiDocsTags } from "@app/lib/api-docs";@@ -33,7 +34,7 @@ const SanitizedKmipServerSchema = KmipServersSchema.pick({// ms() throws on unparseable input (including ""), so guard it to return a clean 400.// The 1h floor catches accidents like "1m" (ms reads it as one minute, not one month) that// would otherwise have the server reissuing its certificate every few seconds forever.-const MIN_TTL_MS = ms("1h");+const MIN_TTL_MS = ms(MIN_SERVER_CERT_TTL);const isTtlAtLeastFloor = (val: string) => {try {return ms(val) >= MIN_TTL_MS;@@ -591,14 +592,6 @@ export const registerKmipServerRouter = async (server: FastifyZodProvider) => {// the server CN), so it's derived from the server name rather than being separately configurable.const resolvedCommonName = kmipServer.name;const resolvedTtl = kmipServer.ttl ?? "1y";- // The floor is only enforced on input, so a server configured before it existed can still- // hold a sub-hour TTL. Refuse here rather than hand the daemon a certificate it would spend- // the rest of its life reissuing.- if (!isTtlAtLeastFloor(resolvedTtl)) {- throw new BadRequestError({- message: `KMIP server certificate TTL '${resolvedTtl}' is below the 1 hour minimum. Update the server's TTL before connecting.`- });- }const resolvedKeyAlgorithm = (kmipServer.keyAlgorithm as CertKeyAlgorithm) ?? undefined;const configs = await server.services.kmip.registerServer({diff --git a/backend/src/ee/services/kmip/kmip-service.ts b/backend/src/ee/services/kmip/kmip-service.tsindex 27998ef201..21f6cc1352 100644--- a/backend/src/ee/services/kmip/kmip-service.ts+++ b/backend/src/ee/services/kmip/kmip-service.ts@@ -80,6 +80,29 @@ type TKmipServiceFactoryDep = {export type TKmipServiceFactory = ReturnType<typeof kmipServiceFactory>;+export const MIN_SERVER_CERT_TTL = "1h";++// Throws rather than clamping: a clamp leaves the stored value wrong and the operator never learns+// the certificate they get is not the one they configured.+export const assertTtlAtLeastFloor = (ttl: string) => {+ let parsed: number | undefined;+ try {+ parsed = ms(ttl);+ } catch {+ parsed = undefined;+ }+ // ms() returns undefined for unparseable input rather than throwing, and NaN comparisons are+ // always false, so an explicit finiteness check is what stops garbage reaching certificate issuance.+ if (!Number.isFinite(parsed)) {+ throw new BadRequestError({ message: `KMIP server certificate TTL '${ttl}' is not a valid duration.` });+ }+ if ((parsed as number) < ms(MIN_SERVER_CERT_TTL)) {+ throw new BadRequestError({+ message: `KMIP server certificate TTL '${ttl}' is below the 1 hour minimum. Update the server's TTL before connecting.`+ });+ }+};+export const kmipServiceFactory = ({kmipClientDAL,permissionService,@@ -827,6 +850,11 @@ export const kmipServiceFactory = ({keyAlgorithm,hostnamesOrIps}: TRegisterServerDTO) => {+ // Both callers (the enrollment /connect flow and the legacy registration route) land here, so+ // the floor is enforced at issuance rather than per route. Sub-hour certificates expire faster+ // than the daemon can replace them, which is the "1m" typo for one month.+ assertTtlAtLeastFloor(ttl);+// KMIP servers authenticate via their enrollment-based access token, which is itself the// authorization — no org-level permission needed. The legacy machine-identity path still// requires the (deprecated) KMIP proxy permission.